①前提・実現したいこと
BitmexのテストネットのAPIキーを使用して仮想通貨BOTを作成し実行しようとしております。
APIキーを発行し、いざ実行してみようとしたら、下記のエラーメッセージがでてきました。
何度確認してもAPI等に間違いはなく正しいはずなのですが…
②発生している問題・エラーメッセージ
itmex market price {'bid': 4097.5, 'ask': 4098, 'spread': 0.5}
Traceback (most recent call last):
File "C:\Users\ユーザー名\AppData\Local\Programs\Python\Python37-32\lib\site-packages\ccxt\base\exchange.py", line 436, in fetch
response.raise_for_status()
File "C:\Users\ユーザー名\AppData\Local\Programs\Python\Python37-32\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://www.bitmex.com/api/v1/order?symbol=XBTUSD&side=Buy&orderQty=100&ordType=Market
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 18, in <module>
exchange.create_market_buy_order(symbol='BTC/USD', amount=100)
File "C:\Users\ユーザー名\AppData\Local\Programs\Python\Python37-32\lib\site-packages\ccxt\base\exchange.py", line 1457, in create_market_buy_order
return self.create_order(symbol, 'market', 'buy', amount, None, params)
File "C:\Users\ユーザー名\AppData\Local\Programs\Python\Python37-32\lib\site-packages\ccxt\bitmex.py", line 498, in create_order
response = self.privatePostOrder(self.extend(request, params))
File "C:\Users\ユーザー名\AppData\Local\Programs\Python\Python37-32\lib\site-packages\ccxt\base\exchange.py", line 364, in request
return self.fetch2(path, api, method, params, headers, body)
File "C:\Users\ユーザー名\AppData\Local\Programs\Python\Python37-32\lib\site-packages\ccxt\base\exchange.py", line 361, in fetch2
return self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "C:\Users\ユーザー名\AppData\Local\Programs\Python\Python37-32\lib\site-packages\ccxt\base\exchange.py", line 448, in fetch
self.handle_errors(response.status_code, response.reason, url, method, headers, http_response)
File "C:\Users\genki\AppData\Local\Programs\Python\Python37-32\lib\site-packages\ccxt\bitmex.py", line 568, in handle_errors
raise exactmessage
ccxt.base.errors.AuthenticationError: bitmex {"error":{"message":"Invalid API Key.","name":"HTTPError"}}
③該当のソースコード
※下記の「☆」はBitmexテストネット用APIキー等になります。
from time import sleep
import ccxt
exchanges = {
"bitmex": {
"apiKey": "☆☆☆☆☆",
"secret": "☆☆☆☆☆"
},
}
exchange = ccxt.bitmex()
exchange.apiKey = exchanges["bitmex"]["apiKey"]
exchange.secret = exchanges["bitmex"]["secret"]
orderbook = exchange.fetch_order_book ('BTC/USD')
bid = orderbook['bids'][0][0] if len (orderbook['bids']) > 0 else None
ask = orderbook['asks'][0][0] if len (orderbook['asks']) > 0 else None
spread = (ask - bid) if (bid and ask) else None
print (exchange.id, 'market price', { 'bid': bid, 'ask': ask, 'spread': spread })
exchange.create_market_buy_order(symbol='BTC/USD', amount=100)#成り行き買い #1分待機sleep(60)
exchange.create_market_sell_order(symbol='BTC/USD', amount=100)#成り行き売り
④試したこと
APIキーに間違いがないか何度も確認し、ネット検索し原因を確認しましたが、わからず…
もしかしたら、テストネット用のAPIキー等じゃだめなんでしようか。
申し訳ありませんが、どなたかご教示いただけければ幸いです。
⑤その他
python3.7.1
Windows10です。
あなたの回答
tips
プレビュー