bitFlyerでアービトラージ自動売買に挑戦②

1月 1, 2020

前回はこちら→bitFlyerでアービトラージ自動売買に挑戦①
引き続きこちらのサイトを参考に勉強しているのですが、
https://ryota-trade.com/
CCXTライブラリを使うところでつまづいてしまいました。

import ccxt
from pprint import pprint
bitflyer = ccxt.bitflyer()
bitflyer.apiKey = '**********'
bitflyer.secret = '**********'
collateral = bitflyer.private_get_getcollateral()
pprint( collateral )

(****の部分は自分のアカウントのAPI keyを入力)
上記コードを実行してみたところエラーになってしまいました。出力結果がこちら。

Traceback (most recent call last):
  File "C:\Users\tsurezure\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 548, in fetch
    response.raise_for_status()
  File "C:\Users\tsurezure\Anaconda3\lib\site-packages\requests\models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.bitflyer.jp/v1/me/getcollateral
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "test.py", line 9, in <module>
    collateral = bitflyer.private_get_getcollateral()
  File "C:\Users\tsurezure\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 435, in inner
    return entry(_self, **inner_kwargs)
  File "C:\Users\tsurezure\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 458, in request
    return self.fetch2(path, api, method, params, headers, body)
  File "C:\Users\tsurezure\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 454, in fetch2
    return self.fetch(request['url'], request['method'], request['headers'], request['body'])
  File "C:\Users\tsurezure\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 561, in fetch
    self.handle_rest_errors(http_status_code, http_status_text, http_response, url, method)
  File "C:\Users\tsurezure\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 588, in handle_rest_errors
    raise error(' '.join([method, url, string_code, http_status_text, body]))
ccxt.base.errors.AuthenticationError: GET https://api.bitflyer.jp/v1/me/getcollateral 401 Unauthorized {"status":-500,"error_message":"Permission denied","data":null}

なんだかさっぱりわからないのでこれから調査します。。原因が判明したら次回記事を投稿します。