Since I wanted to access to the api manually, I made the following script.
import bitmex
b = bitmex.BitMEX(base_url="https://testnet.bitmex.com/api/v1/",symbol="XBTUSD",apiKey="myApiKey",apiSecret="MyApiSecret",orderIDPrefix="my_prefix_",postOnly=False)
print(b.funds())
but this script returns the following error
ERROR:root:API Key incorrect, please check and restart.
ERROR:root:Couldn't connect to WS! Exiting.
And I found out that the apiKey on settings.py was used instead of what I set in instance arguments.
We can see in ws/ws_thread.py, it is referencing the "settings".
def __get_auth(self):
'''Return auth headers. Will use API Keys if present in settings.'''
if self.shouldAuth is False:
return []
self.logger.info("Authenticating with API Key.")
# To auth to the WS using an API key, we generate a signature of a nonce and
# the WS API endpoint.
nonce = generate_nonce()
return [
"api-nonce: " + str(nonce),
"api-signature: " + generate_signature(settings.API_SECRET, 'GET', '/realtime', nonce, ''),
"api-key:" + settings.API_KEY
]
Settings should be referred in higher level, not in the ws module because ws module is required by the bitmex api. ws module should refer to bitmex instance.
Since I wanted to access to the api manually, I made the following script.
but this script returns the following error
And I found out that the apiKey on settings.py was used instead of what I set in instance arguments. We can see in ws/ws_thread.py, it is referencing the "settings".
Settings should be referred in higher level, not in the ws module because ws module is required by the bitmex api. ws module should refer to bitmex instance.