BitMEX / sample-market-maker

Sample BitMEX Market Making Bot
Apache License 2.0
1.7k stars 757 forks source link

ws modules refer to settings and BitMEX constructor does nothing #29

Closed 0z4ck closed 6 years ago

0z4ck commented 6 years ago

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.

ryanfox commented 6 years ago

If you want to directly use the BitMEX API, try the REST API client or websocket client.

ryanfox commented 6 years ago

The BitMEX API official client is on PyPI now. Use that for direct API access.