-
Notifications
You must be signed in to change notification settings - Fork 4
/
tracker.py
80 lines (69 loc) · 2.75 KB
/
tracker.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
import requests
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter
import datetime
def get_prices(coin):
crypto_data = requests.get(
"https://min-api.cryptocompare.com/data/pricemultifull?fsyms={}&tsyms=USD".format(coin)).json()["DISPLAY"][coin]["USD"]
data = {
"ticker": coin,
"price": crypto_data["PRICE"],
"change_day": crypto_data["CHANGEDAY"],
"change_hour": crypto_data["CHANGEHOUR"],
"market_cap": crypto_data["MKTCAP"],
"volume_day": crypto_data["VOLUMEDAYTO"],
"day_open": crypto_data["OPENDAY"],
"day_high": crypto_data["HIGHDAY"],
"day_low": crypto_data["LOWDAY"]
}
return data
def get_graph_info(rate,coin):
crypto_data = requests.get(
"https://min-api.cryptocompare.com/data/v2/histo{}?fsym={}&tsym=USD&limit=10".format(rate,coin)).json()
data = {}
times = []
price = []
for i in range(1, 11):
t = (crypto_data['Data']['Data'][i]['time'])
timestamp = datetime.datetime.fromtimestamp(t)
times.append(timestamp)
price.append(crypto_data['Data']['Data'][i]['close'])
data['time'] = times
data['price'] = price
fig, ax = plt.subplots(figsize=(8, 8))
plt.xticks(rotation=30)
plt.title('{} Close prices for the last 10 {}s'.format(coin,rate))
plt.xlabel('Time')
if rate == "hour":
label = "Hourly"
elif rate == "day":
label = "Daily"
elif rate == "minute":
label = "Minute"
plt.ylabel('{} Close Prices'.format(label))
plt.plot_date(times, price)
plt.plot(times,price)
ax = plt.gca()
ax.set_facecolor((0.84,0.84,0.84))
date_form = DateFormatter("%d-%m %H:%M")
ax.xaxis.set_major_formatter(date_form)
path = "graphs/{}.png".format(coin)
plt.savefig(path)
return path
def get_top_coins(count):
crypto_coins = requests.get(f"https://min-api.cryptocompare.com/data/top/mktcapfull?limit={count}&tsym=USD").json()["Data"]
coins = [{} for i in range(int(count))]
for i in range(len(crypto_coins)):
data = {
"ticker": crypto_coins[i]["CoinInfo"]["Name"],
"name": crypto_coins[i]["CoinInfo"]["FullName"],
"price": crypto_coins[i]["DISPLAY"]["USD"]["PRICE"],
"market_cap": crypto_coins[i]["DISPLAY"]["USD"]["MKTCAP"],
"volume_day": crypto_coins[i]["DISPLAY"]["USD"]["VOLUMEDAYTO"],
"day_open": crypto_coins[i]["DISPLAY"]["USD"]["OPENDAY"],
"day_high": crypto_coins[i]["DISPLAY"]["USD"]["HIGHDAY"],
"day_low": crypto_coins[i]["DISPLAY"]["USD"]["LOWDAY"]
}
coins[i] = data
return coins