BitMEX / api-connectors

Libraries for connecting to the BitMEX API.
https://www.bitmex.com/app/restAPI
910 stars 795 forks source link

Python 3 urllib.parse error #26

Closed jerreyz closed 6 years ago

jerreyz commented 7 years ago

In python 3 the urlparse has moved to urllib. I tried adding in and changing the names try: from urllib.parse import urlparse except ImportError: from urlparse import urlparse

Im still getting an error with the new urlparse function originating in the actual_kwargs function

STRML commented 7 years ago

What is your other error?

jerreyz commented 7 years ago

The problem I had was occuring in the call to self.__get_url.

It first was giving me an error about the stringmodule so I changed line 162 a bit. in .__get_url

def __get_url(self):
urlParts[2] = os.path.join("/realtime?subscribe=",','.join(map(str, subscriptions))) return urlunparse(urlParts)

my error is now "api-signature: " + generate_signature(self.config['api_secret'], 'GET', '/realtime', nonce, ''), File "/Users/jeroenderyck/Documents/Bitmex/api-connectors/official-ws/python/util/api_key.py", line 32, in generate_signature message = bytes(verb + path + str(nonce) + data).encode('utf-8') TypeError: string argument without an encoding

jerreyz commented 7 years ago

I believe the problem was that the secret was not encoded as a ByteArray in the generate_signature function A quick fix is signature = hmac.new(secret.encode('utf-8'), message, digestmod=hashlib.sha256).hexdigest()

Kind regards

jerreyz commented 7 years ago

It runs fine now in python 3 once you take care of the urlparse and the encoding .

However I still get some failed to connects 2017-10-25 18:53:29,867 - bitmex_websocket - ERROR - Couldn't connect to WS! Exiting. occasionally Maybe because I connect to "wss://testnet.bitmex.com/realtime"?

yazzaoui commented 6 years ago

Hi I'm getting this error trying a port to python 3 but I had to write others small fixes: bitmex_websocket.py : line 209 self.data[table] = self.data[table][int(BitMEXWebsocket.MAX_TABLE_LEN / 2):] and bitmex_websocket.py : line 227: item = findItemByKeys(self.keys[table], self.data[table], deleteData) if item is not None: self.data[table].remove(item)

if someone could confirm it's correct it would be great, thanks !

ryanfox commented 6 years ago

Python 3 is now supported - see the python-dev branch or pip install bitmex-ws.