-
Notifications
You must be signed in to change notification settings - Fork 0
/
GDAX.py
59 lines (47 loc) · 1.25 KB
/
GDAX.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from datetime import datetime, timedelta
from time import sleep
import debugging
import time
import json
import requests
class GDAX(object):
"""
Fetch Deh Candles
"""
def __init__(self, coin):
self.coin = coin
self.uri = 'https://api.gdax.com/products/'+ coin+ '/candles'
@staticmethod
def fee(exchange):
return {
'BTC-USD': 0.0025,
'ETH-USD': 0.003,
'LTC-USD': 0.003
}[exchange]
@staticmethod
def __date_to_iso8601(date):
return '{year}-{month:02d}-{day:02d}T{hour:02d}:{minute:02d}:{second:02d}'.format(
year=date.year,
month=date.month,
day=date.day,
hour=date.hour,
minute=date.minute,
second=date.second)
"""
Start - datetime object
End - datetime object
granularity (Should be 60)
"""
def make_request(self, start, end, granularity = 60):
for retry in xrange(0, 3):
response = requests.get(self.uri, params = {
'start': self.__date_to_iso8601(start),
'end': self.__date_to_iso8601(end),
'granularity': granularity # granularity is in seconds.
})
try:
result = sorted(response.json(), key=lambda x: x[0])
return result
except Exception as e:
return []
return []