Created
July 4, 2018 16:30
-
-
Save cryptoscopia/37ea607cfc0461aadcec8cb1e556b295 to your computer and use it in GitHub Desktop.
A script to fetch hourly historic price data for the last financial year for BTC/AUD, using the CryptoCompare API and save it as CSV.
This file contains hidden or 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
from __future__ import print_function | |
import requests | |
data = [] | |
timestamp = 1530367200 # 2018-07-01 00:00 AEST | |
for t in range(1530367200, 1530367200-365*24*60*60, -2001*60*60): | |
data = requests.get( | |
'https://min-api.cryptocompare.com/data/histohour?fsym=BTC&tsym=AUD&toTs=%s&limit=%s' \ | |
% (t, min(365*24-len(data), 2000)) | |
).json()['Data'] + data | |
with open('output.csv', 'w') as f: | |
print('utctime,open,close,high,low', file=f) | |
for d in data: | |
print( | |
datetime.utcfromtimestamp(d['time']), | |
',%(open)s,%(close)s,%(high)s,%(low)s' % d, | |
sep='', | |
file=f, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment