githubからccxtをインストールし、pythonで下記のコードを実行しました(API keyとsecretは伏せています)。
lang
1import ccxt 2 3exchanges = { 4 "bitflyer": { 5 "apiKey": "", 6 "secret": "" 7 }, 8 "quoinex": { 9 "apiKey": "", 10 "secret": "" 11 }, 12 "zaif": { 13 "apiKey": "", 14 "secret": "" 15 } 16} 17 18amount = 0.001 19ask_exchange = '' 20ask_price = 99999999 21bid_exchange = '' 22bid_price = 0 23 24# 各取引所のaskとbidを取得 25for exchange_id in exchanges: 26 exchange = eval('ccxt.' + exchange_id + '()') 27 28 orderbook = exchange.fetch_order_book('BTC/JPY') 29 bid = orderbook['bids'][0][0] if len(orderbook['bids']) > 0 else None 30 ask = orderbook['asks'][0][0] if len(orderbook['asks']) > 0 else None 31 if ask < ask_price: 32 ask_exchange = exchange_id 33 ask_price = ask 34 if bid > bid_price: 35 bid_exchange = exchange_id 36 bid_price = bid 37 38# 裁定取引を行う 39#買い 40ask_price = int(ask_price/5)*5 41exchange = eval('ccxt.' + ask_exchange + '()') 42exchange.apiKey = exchanges[ask_exchange]["apiKey"] 43exchange.secret = exchanges[ask_exchange]["secret"] 44exchange.create_limit_buy_order ('BTC/JPY', amount, ask_price) 45 46#売り 47bid_price = int(bid_price*5)/5 48exchange = eval('ccxt.' + bid_exchange + '()') 49exchange.apiKey = exchanges[bid_exchange]["apiKey"] 50exchange.secret = exchanges[bid_exchange]["secret"] 51exchange.create_limit_sell_order ('BTC/JPY', amount, bid_price) 52 53print(ask_exchange, 'で', ask_price, '円で', amount, '買って') 54print(bid_exchange, 'で', bid_price, '円で', amount, '売ったので') 55print((bid_price - ask_price)*amount, '円の利益!')
ところが下記のエラーが返って来て実行されませんでした。解決方法を教えて下さい。
Last login: Thu May 24 16:17:24 on ttys000
disconoMacBook-ea:~ disco$ cd python
disconoMacBook-ea:python disco$ python arbitrage.py
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/ccxt/base/exchange.py", line 364, in fetch
response.raise_for_status()
File "/anaconda3/lib/python3.6/site-packages/requests/models.py", line 935, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.quoine.com/orders
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "arbitrage.py", line 44, in <module>
exchange.create_limit_buy_order ('BTC/JPY', amount, ask_price)
File "/anaconda3/lib/python3.6/site-packages/ccxt/base/exchange.py", line 1267, in create_limit_buy_order
return self.create_order(symbol, 'limit', 'buy', *args)
File "/anaconda3/lib/python3.6/site-packages/ccxt/qryptos.py", line 300, in create_order
response = self.privatePostOrders(self.extend(order, params))
File "/anaconda3/lib/python3.6/site-packages/ccxt/base/exchange.py", line 306, in request
return self.fetch2(path, api, method, params, headers, body)
File "/anaconda3/lib/python3.6/site-packages/ccxt/base/exchange.py", line 303, in fetch2
return self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "/anaconda3/lib/python3.6/site-packages/ccxt/base/exchange.py", line 377, in fetch
self.handle_rest_errors(e, response.status_code, self.last_http_response, url, method)
File "/anaconda3/lib/python3.6/site-packages/ccxt/base/exchange.py", line 406, in handle_rest_errors
self.raise_error(error, url, method, exception if exception else http_status_code, response)
File "/anaconda3/lib/python3.6/site-packages/ccxt/base/exchange.py", line 288, in raise_error
raise exception_type(output)
ccxt.base.errors.AuthenticationError: quoinex https://api.quoine.com/orders POST 401 Client Error: Unauthorized for url: https://api.quoine.com/orders
disconoMacBook-ea:python disco$
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/28 09:57