Last active
June 16, 2017 05:02
-
-
Save singlerider/fb24425e5dc8b4245d9f5501385a824c to your computer and use it in GitHub Desktop.
GDAX Time Series Data for datetime.now() ~24 hours
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 json | |
import time | |
import urllib | |
import urllib2 | |
from datetime import datetime, timedelta | |
URL = "https://api.gdax.com" | |
def candles(product): | |
return "{url}/products/{product}/candles".format( | |
url=URL, product=product) | |
def get_time_series_data(start, end, product="ETH-USD", granularity=432): | |
response = urllib2.urlopen( | |
candles(product) + "?" + urllib.urlencode( | |
{ | |
"start": str(start), "end": str(end), | |
"granularity": str(granularity) | |
} | |
) | |
) | |
data = response.read() | |
return data | |
def times(date): | |
date = date - timedelta(hours=24) | |
time_periods = [] | |
last_hour = date | |
for n in range(int(24 / 2)): | |
hour = date + timedelta(hours=(n * 2) + 2) | |
time_periods.append((last_hour, hour)) | |
last_hour = hour | |
return time_periods | |
if __name__ == "__main__": | |
time_series_data = [] | |
for time_series in times(datetime.now()): | |
data = get_time_series_data( | |
time_series[0], time_series[1], granularity=60) | |
time_series_data += json.loads(data) | |
time.sleep(0.4) | |
print(time_series_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment