forked from vmeazevedo/myCrypto_MercadoBitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyCripto-Monitor.py
147 lines (128 loc) · 5.49 KB
/
myCripto-Monitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import requests
import json
import time
import locale
from datetime import datetime
from pyfiglet import figlet_format
from colorama import Fore, Back, Style
import colorama
colorama.init(autoreset=True)
locale.setlocale(locale.LC_MONETARY, "pt_BR.UTF-8")
def logo():
print("======================================================================")
print(figlet_format("Mercado Bitcoin ", font="standard"))
print("======================================================================")
def obter_hora():
data_e_hora_atuais = datetime.now()
data_e_hora_em_texto = data_e_hora_atuais.strftime("%d/%m/%Y %H:%M:%S")
return data_e_hora_em_texto
def buscar_dados(coin):
request = requests.get(f"https://www.mercadobitcoin.net/api/{coin}/ticker")
payload = json.loads(request.content)
coin = payload['ticker']['last']
return float(coin)
def calc_porc(anterior,nova):
anterior = anterior
nova = nova
if anterior < nova:
x = (nova*100.00) / anterior
x = 100.00 - x
x = str(x)
x = x.replace('-','')
x = float(x)
x = round(x,2)
x = ("+"+ str(x))
return x
elif anterior > nova:
x = (nova*100.00) / anterior
x = 100.00 - x
x = str(x)
x = float(x)
x = round(x,2)
x = ("-"+ str(x))
return x
else:
x = ("-%")
return x
logo()
list_btc = [1.00]
list_eth = [1.00]
list_xrp = [1.00]
list_paxg = [1.00]
list_usdc = [1.00]
while True:
# Realizando as requisições
btc = float(buscar_dados("BTC"))
eth = float(buscar_dados("ETH"))
xrp = float(buscar_dados("XRP"))
paxg = float(buscar_dados("PAXG"))
usdc = float(buscar_dados("USDC"))
# Armazenando os dados em listas para comparações
list_btc.append(btc)
btc = locale.currency(btc, grouping=True)
list_eth.append(eth)
eth = locale.currency(eth, grouping=True)
list_xrp.append(xrp)
xrp = locale.currency(xrp, grouping=True)
list_paxg.append(paxg)
paxg = locale.currency(paxg, grouping=True)
list_usdc.append(usdc)
usdc = locale.currency(usdc, grouping=True)
# Monitoramento BTC
if list_btc[-1] > list_btc[-2]:
if list_btc[-2] == 1.00:
response = "Calculando.."
else:
response = str(calc_porc(list_btc[-2],list_btc[-1]))
print("BTC: \t" + str(btc) + "\t" + obter_hora() + Fore.GREEN+"\tSubindo!"+Style.RESET_ALL + " " +response)
elif list_btc[-1] < list_btc[-2]:
response = str(calc_porc(list_btc[-2],list_btc[-1]))
print("BTC: \t" + str(btc) + "\t" + obter_hora() + Fore.RED +"\tCaindo!\t"+Style.RESET_ALL + " " +response)
else:
print("BTC: \t" + str(btc) + "\t" + obter_hora() + Fore.LIGHTYELLOW_EX +"\tEstável!"+Style.RESET_ALL + " " +"-%")
# Monitoramento ETH
if list_eth[-1] > list_eth[-2]:
if list_eth[-2] == 1.00:
response = "Calculando.."
else:
response = str(calc_porc(list_eth[-2],list_eth[-1]))
print("ETH: \t" + str(eth) + "\t" + obter_hora() + Fore.GREEN +"\tSubindo!"+Style.RESET_ALL + " " +response)
elif list_eth[-1] < list_eth[-2]:
print("ETH: \t" + str(eth) + "\t" + obter_hora() + Fore.RED +"\tCaindo!"+Style.RESET_ALL + " " +response)
else:
print("ETH: \t" + str(eth) + "\t" + obter_hora() + Fore.LIGHTYELLOW_EX +"\tEstável!"+Style.RESET_ALL + " " +"-%")
# Monitoramento XRP
if list_xrp[-1] > list_xrp[-2]:
if list_xrp[-2] == 1.00:
response = "Calculando.."
else:
response = str(calc_porc(list_xrp[-2],list_xrp[-1]))
print("XRP: \t" + str(xrp) + "\t\t" + obter_hora() + Fore.GREEN +"\tSubindo!"+Style.RESET_ALL + " " +response)
elif list_xrp[-1] < list_xrp[-2]:
print("XRP: \t" + str(xrp) + "\t\t" + obter_hora() + Fore.RED +"\tCaindo!"+Style.RESET_ALL + " " +response)
else:
print("XRP: \t" + str(xrp) + "\t\t" + obter_hora() + Fore.LIGHTYELLOW_EX +"\tEstável!"+Style.RESET_ALL + " " +"-%")
# Monitoramento PAXG
if list_paxg[-1] > list_paxg[-2]:
if list_paxg[-2] == 1.00:
response = "Calculando.."
else:
response = str(calc_porc(list_paxg[-2],list_paxg[-1]))
print("PAXG:\t" + str(paxg) + "\t" + obter_hora() + Fore.GREEN +"\tSubindo!"+Style.RESET_ALL + " " +response)
elif list_paxg[-1] < list_paxg[-2]:
print("PAXG:\t" + str(paxg) + "\t" + obter_hora() + Fore.RED +"\tCaindo!"+Style.RESET_ALL + " " +response)
else:
print("PAXG:\t" + str(paxg) + "\t" + obter_hora() + Fore.LIGHTYELLOW_EX +"\tEstável!"+Style.RESET_ALL + " " +"-%")
# Monitoramento USDC
if list_usdc[-1] > list_usdc[-2]:
if list_usdc[-2] == 1.00:
response = "Calculando.."
else:
response = str(calc_porc(list_usdc[-2],list_usdc[-1]))
print("USDC:\t" + str(usdc) + "\t\t" + obter_hora() + Fore.GREEN +"\tSubindo!"+Style.RESET_ALL + " " +response)
elif list_usdc[-1] < list_usdc[-2]:
print("USDC:\t" + str(usdc) + "\t\t" + obter_hora() + Fore.RED +"\tCaindo!"+Style.RESET_ALL + " " +response)
else:
print("USDC:\t" + str(usdc) + "\t\t" + obter_hora() + Fore.LIGHTYELLOW_EX +"\tEstável!"+Style.RESET_ALL + " " +"-%")
print("======================================================================")
time.sleep(60)