coincheckのpythonライブラリに取引履歴全件を取れる機能がなかったので追加したおはなし
ライブラリ
https://github.com/kmn/coincheck
背景
coincheckのライブラリで取引履歴取ろうとすると件数制限だか期間制限だかで全量取れない。
ページネーションのメソッド使えばとれそうだけど、ライブラリが対応してない。
⇒ライブラリを改造するぞ!
order.py
# 履歴全件返すメソッドを追加
def historyall(self):
''' show payment historyall
'''
url= 'https://coincheck.com/api/exchange/orders/transactions_pagination?limit=25'
headers = make_header(url,access_key=self.access_key,secret_key=self.secret_key)
r = requests.get(url,headers=headers)
res = json.loads(r.text)
ret = []
while True:
if len(res['data']) > 0:
ret.extend(res['data'])
nextid = res['data'][len(res['data'])-1]['id']
while True:
try:
headers = make_header(url + '&starting_after=' + str(nextid),access_key=self.access_key,secret_key=self.secret_key)
r = requests.get(url + '&starting_after=' + str(nextid),headers=headers)
res = json.loads(r.text)
if res['success'] == False:
time.sleep(1)
continue
break
except:
time.sleep(1)
continue
continue
else:
break
return ret
きれいじゃないし恥ずかしいのでコミットはしません。
python勉強中につき、もっとかっこいい実装できれば教えてください。