1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

coincheckのpythonライブラリに取引履歴全件が取れる機能を追加した

Last updated at Posted at 2017-12-06

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勉強中につき、もっとかっこいい実装できれば教えてください。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?