-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCINCO_CRIPTO.PY
More file actions
55 lines (50 loc) · 1.7 KB
/
CINCO_CRIPTO.PY
File metadata and controls
55 lines (50 loc) · 1.7 KB
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
from time import sleep
import requests
class Config:
def __init__(self):
self.url='https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest'
self.headers={
'Accepts': 'application/json',
'X-CMC_PRO_API_KEY': 'fea42815-ebda-4b39-9a22-3e057beda67d'
}
self.parameters={
'limit': '5',
'convert': 'USD',
'sort': 'market_cap'
}
def get_currency(url, headers, parameters):
result=requests.get(url, headers=headers, params=parameters)
cripto_lastast=result.json()['data']
coins={}
if (cripto_lastast):
for cripto in cripto_lastast:
coin={}
coin['nombre'] = cripto['name']
coin['simbolo'] = cripto['symbol']
coin['precio'] = cripto['quote']['USD']['price']
coin['volumen_24h'] = cripto['quote']['USD']['volume_24h']
coins[coin['simbolo']]=coin
return coins
def show(coin, aumento):
if aumento != '':
aumento= '+' if aumento else '-'
print(f"{coin['simbolo']}: {coin['precio']:.4f} [{aumento}]")
else:
print(f"{coin['simbolo']}: {coin['precio']:.4f} []")
coins={}
coin_last={}
config=Config()
while True:
coin_last=coins
coins= get_currency(config.url, config.headers, config.parameters)
for key, coin in coins.items():
if len(coin_last)==0 or coin['precio']== coin_last[key]['precio']:
show(coin, '')
elif coin['precio']> coin_last[key]['precio']:
show(coin, True)
else:
show(coin, False)
for i in range(0, 11):
print(f"Esperando para actualizar... {11-i:02d} seg", end='\r')
sleep(1)
print("\n")