Created
December 18, 2017 23:29
-
-
Save xoelop/40340c059759dda07ce2270d2611c609 to your computer and use it in GitHub Desktop.
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 datetime | |
import requests | |
import pandas as pd | |
def daily_price_historical(symbol, comparison_symbol, limit=0, aggregate=1, exchange='CCCAGG', print_url=False): | |
"""Returns a pandas.Dataframe containing OHLC daily data for the specified | |
symbol | |
Parameters | |
---------- | |
symbol : string | |
currency we buy | |
comparison_symbol : string | |
currency we sell | |
limit : int | |
0 : returns all data available | |
> 0 : returns last n rows | |
exchange : string, optional | |
exchange which we want to get the data from | |
print_url : bool, default False | |
prints the url that makes the call to the API | |
Returns | |
---------- | |
df : pandas.DataFrame | |
DataFrame containing OHLCV historical data | |
""" | |
url = 'https://min-api.cryptocompare.com/data/histoday?fsym={}&tsym={}&limit={}&aggregate={}&e={}'\ | |
.format(symbol.upper(), comparison_symbol.upper(), limit-1, aggregate, exchange) | |
if not limit: | |
url += '&allData=True' | |
page = requests.get(url) | |
data = page.json()['Data'] | |
df = pd.DataFrame(data) | |
df['timestamp'] = [datetime.datetime.fromtimestamp(d) for d in df.time] | |
df.index = pd.to_datetime(df.timestamp) | |
df = df.drop(['timestamp', 'time'], axis=1) | |
df.columns = ['Close', 'High', 'Low', 'Open', 'VolumeFrom', 'VolumeTo'] | |
if print_url: | |
print(url) | |
return df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment