我正在尝试使用 API krakenex 为我的研究项目加载 OHLC 数据表单 Kraken。但我无法弄清楚我的错误。
我在 python 中使用https://github.com/veox/python3-krakenex/blob/master/examples/trades-history.py的修改版本来获取历史 OHLC 数据:
import krakenex
import datetime
import calendar
import pandas as pd
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 formated request data
def req(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.txt')
#k.set_connection({'pair':'GNOETH'})
#headers={"headers":'XXBTZUSD'}
#pairs = ['XETHZEUR','XXBTZEUR', 'XZECZEUR', 'XXRPZEUR']
datum_ende=[[31,28,31,30,31,30,31,31,30,31,30,31],[31,29,31,30,31,30,31,31,30,31,30,31]]
data = []
count = 0
jahre =[2015,2016,2017]
for j in jahre:
for i in range(0,11):
start_date = datetime.datetime(j, i+1, 1)
if j==2016:
end_date = datetime.datetime(2016, i+1, datum_ende[1][i])
else:
end_date = datetime.datetime(j, (i+1),datum_ende[0][i])
th = k.query_private('TradesHistory', req(start_date,end_date,1))
time.sleep(.25)
print(th)
th_error = th['error']
if int(th['result']['count'])>0:
count += th['result']['count']
data.append(pd.DataFrame.from_dict(th['result']
所以我的问题是现在我收到了这些行:
{'error': [], 'result': {'trades': {}, 'count': 0}}
我想问题是我还没有定义一个代码对。但我无法弄清楚我应该如何做到这一点。
你能帮我吗?