Voyz / ibind

IBind is a REST and WebSocket client library for Interactive Brokers Client Portal Web API.
Apache License 2.0
116 stars 14 forks source link

Error in websocket connection #7

Closed akshayaradhya closed 6 months ago

akshayaradhya commented 6 months ago

My web socket subscriptions works many times but not always. Since I am developing, I keep spinning it up and down every now and then. Somewhere here, it gets stuck sometimes and gives the following error. Sometimes, to make it work, I run the other examples rest_01_basic.py and rest_06_chains.py to kinda refresh it and when I try restart websocket it works again. I am guessing these are the cases when IB requires a mandatory call to accounts in order to get live_marketdata_snapshot.

However, the other times, no matter how much I try to run, the websocket examples do not work at all. Rest examples work fine though. Same with web. I checked the logs inside the iBeam container, that seems fine too. However there is a log like this: 2024-05-31 20:54:19,613|I| Maintenance

Questions

Reproduction steps:

python examples ws_01_basic.py

Error logs:

IbkrWsClient: on_close error: 1000 | 
IbkrWsClient: on_close error: 1000 | 
IbkrWsClient: on_close error: 1000 | 
IbkrWsClient: on_close error: 1000 | 
IbkrWsClient: on_close error: 1000 |

Traceback:

^CTraceback (most recent call last):
  File "/root/ibind/examples/ws_01_basic.py", line 22, in <module>
    ws_client.subscribe(channel=ibkr_ws_key.channel)
  File "/root/user/lib/python3.12/site-packages/ibind/client/ibkr_ws_client.py", line 567, in subscribe
    return super().subscribe(channel, data, needs_confirmation, subscription_processor)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/user/lib/python3.12/site-packages/ibind/base/subscription_controller.py", line 164, in subscribe
    return self._attempt_subscribing(channel, data, needs_confirmation, subscription_processor)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/user/lib/python3.12/site-packages/ibind/base/subscription_controller.py", line 121, in _attempt_subscribing
    return self._attempt_subscribing_repeated(channel, payload)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/user/lib/python3.12/site-packages/ibind/base/subscription_controller.py", line 95, in _attempt_subscribing_repeated
    if wait_until(lambda: self.is_subscription_active(channel) == True, timeout=self._subscription_timeout):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/user/lib/python3.12/site-packages/ibind/support/py_utils.py", line 281, in wait_until
    time.sleep(0.1)
KeyboardInterrupt
Voyz commented 6 months ago

I am guessing these are the cases when IB requires a mandatory call to accounts in order to get live_marketdata_snapshot.

That indeed seems to be the case.

However, the other times, no matter how much I try to run, the websocket examples do not work at all It is right now after market hour period. Can IB go to maintenance during this time?

Right, so it is during market closed hours? In my experience that this affects some of their endpoints heavily. I would imagine that this indeed is the case, they run maintenance.

2024-05-31 20:54:19,613|I| Maintenance Does this mean that IB is in maintenance at the moment?

I would interpret it in this way, yes. To get a more thorough confirmation, I'd suggest you direct this question to IBKR support.

I know it happens once in a day, how does it happen at a fixed time or depending on what time I deployed IBeam?

Again, IBKR support should give you more info on this. I would imagine it depends on a fixed time, rather on when you start the Gateway and authenticate (which is all that IBeam does)

I even restarted the IBeam. That did not fix it either. What else do you suggest?

I'd suggest you talk to IBKR support and figure out what Maintenance is, and at what time it runs.

Also ask what error 1000 means. From here I can see:

NormalClosure | 1000 | (1000) The connection has closed after the request was fulfilled.

Hence I'd assume that their maintenance simply closes the connection, and it cannot be reopened for a while during the maintenance.

akshayaradhya commented 6 months ago

That indeed was the case. Closing the issue.

Thank you!

Voyz commented 6 months ago

Great, happy to hear 👏