Skip to content

Instantly share code, notes, and snippets.

@subpath
Created August 9, 2018 15:39
Show Gist options
  • Save subpath/95bab7416cf61693cd6e9f102c9eb8ea to your computer and use it in GitHub Desktop.
Save subpath/95bab7416cf61693cd6e9f102c9eb8ea to your computer and use it in GitHub Desktop.
Load data from cryptocompare API
import numpy as np
import pandas as pd
import requests
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