Skip to content

Instantly share code, notes, and snippets.

@subpath
Created August 9, 2018 15:37
Show Gist options
  • Save subpath/2374a1eb1e5d9431e15997dc1988210f to your computer and use it in GitHub Desktop.
Save subpath/2374a1eb1e5d9431e15997dc1988210f to your computer and use it in GitHub Desktop.
Load data from cryptocompare API
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