ibind: Disconnect / Errors from stream
Hey,
I tend to have this problem, where the ´md´ subscription works for a while but then crashes in the background and is not handled properly.
2024-09-05 01:24:40,317|E| IbkrWsClient: Status unauthenticated: {'authenticated': False}
2024-09-05 01:24:40.317 [ERROR] [ws_client_thread] - IbkrWsClient: Status unauthenticated: {'authenticated': False}
2024-09-05 01:24:40,459|I| IbkrWsClient: Unknown status response: {'topic': 'sts', 'args': {'competing': False}}
2024-09-05 01:24:40.459 [INFO] [ws_client_thread] - IbkrWsClient: Unknown status response: {'topic': 'sts', 'args': {'competing': False}}
2024-09-05 01:24:40,460|I| IbkrWsClient: Unknown status response: {'topic': 'sts', 'args': {'message': ''}}
2024-09-05 01:24:40.460 [INFO] [ws_client_thread] - IbkrWsClient: Unknown status response: {'topic': 'sts', 'args': {'message': ''}}
2024-09-05 01:24:40,460|E| IbkrWsClient: Status unauthenticated: {'authenticated': False}
2024-09-05 01:24:40.460 [ERROR] [ws_client_thread] - IbkrWsClient: Status unauthenticated: {'authenticated': False}
Are there any best practices for reconnecting to WS gracefully?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 30 (14 by maintainers)
Fantastic! Many thanks for your patience and help with this issue. I’m glad we’ve managed to catch it 👏👏👏
Music to my ears! Keep me posted, hopefully we got it this time 👍
Heh 😃 It seems solved for now. I will monitor until Friday, and close this issue, if success keeps repeating 👍
Updated to
0.1.8rc3will get results tmrw 💯Okay, I think I’ve got some good news. I found the core issue here.
The IbkrWsClient has a lot of code in place to handle drops in connectivity, but it wasn’t handling authentication drop as gracefully. While IBKR WS API sends a message when authentication is dropped, it doesn’t send a message when authentication is restored, leaving us thinking that authentication continues to be false. I’ve spent a while to add a bunch of code for handling authentication drops.
In short, it will close the WS connection completely, as this will get it into a reauthentication loop, attempting to reopen and resubscribe every few seconds. Once the authentication is restored, this should eventually succeed.
I’ve tested it with Market Data channel and can report that it is restored successfully.
Please try the
ibind-0.1.8rc3and let me know if it helps.On the master branch.
Trying the ibind==0.1.8rc1
Will let know, in few days
Hey @Tsopic thanks for your patience 🙏
I’ve spent a while investigating the reason behind the
'Topic unknown \'{"s\''and I’ve concluded that IBind was not responding correctly toauthenticated=Falseinstatusmessage. Quite frankly, in the old documentation the way the connection guide was laid out was unclear to me. I’ve just reviewed the current docs and updated the code accordingly.In short:
authenticated=False. This indicates that the session is not authenticated, and IBind has no means of resolving it. Previously I was incorrectly lead to believe that sending a{"session"="[SESSION_ID]"}payload would solve this, but it doesn’t. This is where'Topic unknown \'{"s\''was coming from. In reality, it needs to be solved externally, either by IBeam (if used) or by the user.The rest of your log tells me that where you’re calling
hard_reset(True)you should actually call it withhard_reset(False). The restart happens automatically when the WebSocketApp is closed, and doesn’t need to be initiated fromhard_resetseparately.Try the
ibind==0.1.8rc1and let me know if it helps. Thanks for helping me catch this issue, this has been a great contribution 👍I’m sorry @Tsopic I’m travelling at the moment. I should be able to investigate within the next couple of weeks. Thanks for bearing with me in the meantime and for keeping this thread active 👍
hey @Tsopic I’d appreciate if you could share the logs here for consistency and for other users who may run into this issue in the future. If you feel it’s too long you can make it collapsible in the following fashion:
Which will look like this: .
Note the dot
.character before<details>.Thanks!