Skip to content

Instantly share code, notes, and snippets.

@cryptoscopia
Created July 4, 2018 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cryptoscopia/37ea607cfc0461aadcec8cb1e556b295 to your computer and use it in GitHub Desktop.
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.
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