verata-veritatis / pybit

Python3 API connector for Bybit's HTTP and Websockets APIs.
MIT License
114 stars 189 forks source link

Websocket auth request expired #37

Open moranelli opened 3 years ago

moranelli commented 3 years ago

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
ImaRicklePick commented 2 years ago

67 Started a PR on this issue

dextertd commented 2 years ago

@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.