BTCMarkets / API

API
120 stars 30 forks source link

websocket authentication using python #190

Open o5mo-lj opened 4 years ago

o5mo-lj commented 4 years ago

Hi, I've been unable to authenticate using websockets (to access account streams). Is there any example of this being done in python? I'm building the signature as below and I'm receiving the error message "authentication failed. authentications failed. invalid signature" Any advice?

nowInMilisecond = str(int(time.time() * 1000)) path = "/users/self/subscribe"
stringToSign = path + "\n" + nowInMilisecond

update_param__str = stringToSign update_param_byteencoded = update_param_str.encode()

new_hmac = hmac.new( secret_byteencoded, msg=update_param__byteencoded, digestmod=hashlib.sha512, ) new_hmac_updated_hexdigested = new_hmac.hexdigest()

return nowInMilisecond, new_hmac_updated_hexdigested

martin-nginio commented 4 years ago

Hi @lukejamesp

Thanks for your feedback.

Please find below Authentication sample in node.js https://github.com/ngin-io/websocket-client-node/blob/master/index.js

and this one is Java: https://github.com/ngin-io/websocket-client-java/blob/master/src/main/java/io/ngin/websocket/sample/client/java/WebSocketClient.java

They might be useful as. you can compare your python generated signature with any above.

After reviewing those if you are still getting errors please let us know and we will add python authentication sample as well

Thanks.

Regards, Martin