-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbtc_usdc.py
45 lines (33 loc) · 1.18 KB
/
btc_usdc.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
import json
import requests
from tabulate import tabulate
### ------------ BTC - USDC ------------
def info_btc_usdc():
btc_usdc_url = 'https://api.exchange.ripio.com/api/v1/rate/BTC_USDC/'
data = requests.get(btc_usdc_url)
data = data.json()
# Convert possible items to float
for k,v in data.items():
try:
data[k] = float(v)
except (ValueError, TypeError):
pass
#print(data, end = '\n\n')
btc_usdc_title = ' ' + str(data['base_name']) + ' - ' + str(data['quote_name'] + ' ')
btc_usdc = str(data['base']) + ' - ' + str(data['quote'])
btc_usdc_last_price = data['last_price']
btc_usdc_avg = data['avg']
btc_usdc_high24 = data['high']
btc_usdc_low24 = data['low']
btc_usdc_variation24 = data['variation']
info = [('Pair', btc_usdc),
('Last Value: ', btc_usdc_last_price),
('Avg: ', btc_usdc_avg),
('Low 24hs: ', btc_usdc_low24),
('High 24hs: ', btc_usdc_high24),
('Variation: ', btc_usdc_variation24),
]
#print(btc_usdc_title)
#print(tabulate(info))
return tabulate(info)
# ------------------------------------