Created
August 9, 2018 15:37
-
-
Save subpath/2374a1eb1e5d9431e15997dc1988210f to your computer and use it in GitHub Desktop.
Load data from cryptocompare API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
import requests | |
"" | |
LOAD DATA | |
""" | |
def get_market_data(ticker): | |
""" | |
Ticker in format quote/base, | |
for example 'BTC/USD' | |
return: pandas dataframe | |
""" | |
b_ticker, q_ticker = ticker.upper().split('/') | |
url = 'https://min-api.cryptocompare.com/data/histoday?fsym={}&tsym={}&limit=1&aggregate=1&allData=true'\ | |
.format(b_ticker, q_ticker) | |
page = requests.get(url) | |
data = page.json()['Data'] | |
df = pd.DataFrame(data) | |
df['date'] = [datetime.datetime.fromtimestamp(d).date() for d in df.time] | |
df['ticker'] = ticker | |
df['time'] = df['time'].apply(lambda x: datetime.datetime.utcfromtimestamp(x).strftime('%Y-%m-%dT%H:%M:%SZ')) | |
return df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment