-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpruebass.py
More file actions
62 lines (50 loc) · 1.6 KB
/
pruebass.py
File metadata and controls
62 lines (50 loc) · 1.6 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
56
57
58
59
60
61
62
import requests
from time import sleep
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': '7a138f90-8d38-49cb-84a4-01a98c978996',
}
self.parameters = {
'limit': '5',
'convert': 'USD',
'sort': 'market_cap'
}
def get_currency(url, headers, parameters):
result = requests.get(url, headers=headers, params=parameters)
cripto_lastest = result.json()['data']
coins = {}
if (cripto_lastest):
for cripto in cripto_lastest:
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, 61):
print(f'Esperando para actualizar... {60-i:02d} seg', end='\r')
sleep(1)
print('\n')