pybit icon indicating copy to clipboard operation
pybit copied to clipboard

Websocket auth request expired

Open moranelli opened this issue 4 years ago • 2 comments

Hi, I am trying to subscribe to position or order and I don't get data because the auth failed. The problem is that the websocket not raise any exception. I debug the websocket and I can see the error:

msg_json:  {'success': False, 'ret_msg': 'error:request expired', 'conn_id': '31950833-ab7d-4fd2-8b1c-1dc1b7205ae2', 'request': {'op': 'auth', 'args': ['bqZTxSi30b', '1622325037946', '2dab68953beb4d27bc4c1257f1f594dabc9abb631']}}
msg_json:  {'success': False, 'ret_msg': 'error:topic:order needs auth first', 'conn_id': '31950833-ab7d-4f1c-1dc1b7205ae2', 'request': {'op': 'subscribe', 'args': ['order', 'position']}}

If I change the "def _auth(self)" and increase the expires variable the websocket return data correctly. I thing that is a good idea implement the auto increase recv window like HTTP that work fine, because is very difficult to sync the timestamp. What do you think?

if s_json['ret_code'] == 10002:   
   error_msg += '. Added 2.5 seconds to recv_window'     
   recv_window += 2500

moranelli avatar May 29 '21 22:05 moranelli

#67 Started a PR on this issue

ImaRicklePick avatar Dec 02 '21 19:12 ImaRicklePick

@moranelli See https://github.com/verata-veritatis/pybit/pull/67#issuecomment-1000814774 for why I am weary of "auto increase like recv window" for websocket, and I personally don't like the auto increase in HTTP...

Why is it "very difficult to sync the timestamp"? I think you can just sync your computer's clock, which is done differently depending on the OS.

dextertd avatar Dec 24 '21 12:12 dextertd