-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapi.py
52 lines (43 loc) · 1.14 KB
/
api.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
#!/usr/bin/env python
import argparse
import requests
import pandas as pd
from datetime import datetime
import matplotlib.pyplot as plt
__version__ = '0.1'
__author__ = 'Norbert Bota'
__author_email__ = '[email protected]'
parser = argparse.ArgumentParser(
description='Plotting a specific coin from coinmarketcap'
)
parser.add_argument(
'-c', '--coin',
action="store",
help='specify coin name',
required=True
)
coin_name = parser.parse_args()
COIN = coin_name.coin
BASE_URL = "https://graphs2.coinmarketcap.com/currencies/"
def historical_data(coin):
r = requests.get("".join((BASE_URL, coin, "/")))
coin_data = r.json()['price_usd']
real_time = lambda x: datetime.fromtimestamp(x / 1e3)
coin = {real_time(key): value for key, value in coin_data}
return coin
def main():
d = historical_data(COIN)
df = pd.DataFrame(
{
"Time":list(d.keys()),
"Price":list(d.values())
},
index=d.keys()
)
df['Price'].plot(figsize=(20,10), color="green")
plt.title(COIN)
plt.xlabel('Date')
plt.ylabel('Price')
plt.show()
if __name__=='__main__':
main()