-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkktradehist.py
61 lines (48 loc) · 1.59 KB
/
kktradehist.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
58
59
60
61
#!/usr/bin/env python
# This file is part of krakenex.
# Licensed under the Simplified BSD license. See `examples/LICENSE.txt`.
# Saves trade history to CSV file.
#
# WARNING: submits a lot of queries in rapid succession!
# Maintainer: [email protected] (@AustinDeric on github)
import pandas as pd
import krakenex
import datetime
import calendar
import time
# takes date and returns nix time
def date_nix(str_date):
return calendar.timegm(str_date.timetuple())
# takes nix time and returns date
def date_str(nix_time):
return datetime.datetime.fromtimestamp(nix_time).strftime('%m, %d, %Y')
# return formatted TradesHistory request data
def data(start, end, ofs):
req_data = {'type': 'all',
'trades': 'true',
'start': str(date_nix(start)),
'end': str(date_nix(end)),
'ofs': str(ofs)
}
return req_data
k = krakenex.API()
k.load_key('kraken.key')
datadf = []
count = 0
for i in range(1,3):
start_date = datetime.datetime(2016, i+1, 1)
end_date = datetime.datetime(2016, i+2, 29)
a=data(start_date, end_date, 1)
th = k.query_private('TradesHistory', data(start_date, end_date, 1))
time.sleep(.25)
print(th)
th_error = th['error']
if int(th['result']['count'])>0:
count += th['result']['count']
datadf.append(pd.DataFrame.from_dict(th['result']['trades']).transpose())
trades = pd.DataFrame
trades = pd.concat(data, axis = 0)
trades = trades.sort_values(columns='time', ascending=True)
trades.to_csv('data.csv')
import ccs
response = ccs.kraken.public.getOHLCdata("XBTEUR")