-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_testing.py
More file actions
20 lines (17 loc) · 791 Bytes
/
api_testing.py
File metadata and controls
20 lines (17 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from pycoingecko import CoinGeckoAPI
import pandas as pd
from datetime import datetime
def cg_pull(ticker='btc', curr='usd', days='max', intv='daily'):
cg = CoinGeckoAPI()
out = cg.get_coin_market_chart_by_id(id=ticker, vs_currency=curr, days=days, interval=intv)
df = pd.DataFrame(data=out)
df[['date', 'price']] = pd.DataFrame(df.prices.tolist(), index=df.index)
df[['date']] = df[['date']] / 1000
df['datetime'] = [datetime.fromtimestamp(x) for x in df['date']]
df_out = df[['datetime', 'price']]
return df_out
btc = cg_pull('bitcoin', 'usd', 'max', 'daily')
atom = cg_pull('cosmos', 'usd', 'max', 'daily')
kuji = cg_pull('kujira', 'usd', 'max', 'daily')
usdc = cg_pull('usd-coin', 'usd', 'max', 'daily')
eth = cg_pull('ethereum', 'usd', 'max', 'daily')