Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Getting Disconnected At Certain Times #655

Open
eljefe6a opened this issue Nov 10, 2023 · 4 comments
Open

Getting Disconnected At Certain Times #655

eljefe6a opened this issue Nov 10, 2023 · 4 comments

Comments

@eljefe6a
Copy link

I'm hitting a weird problem where ib_insync will disconnect immediately. The disconnect seems to happen starting at around 10:00-10:30 AM EST. It disconnects immediately after ib.connect. The connection works just fine up to that point in time.

This only happens with TWS and I'm using build 10.25.1n, Oct 30, 2023 4:01:24 PM on Linux. If I start using the gateway, everything starts working again. This is annoying as I'm still interacting with TWS.

Here is the connection code:

    util.logToConsole('DEBUG')
    util.startLoop()
    ib = IB()
    ib.connect('127.0.0.1', 7496, clientId=13)

Here is the last part of util.logToConsole('DEBUG'):

2023-11-10 16:34:19,087 ib_insync.client DEBUG <<< 73,1,1,*ACCOUNTNUMBER*,,MutualFundValue,0.00,BASE
2023-11-10 16:34:19,087 ib_insync.client DEBUG <<< 73,1,1,*ACCOUNTNUMBER*,,MoneyMarketFundValue,0.00,BASE
2023-11-10 16:34:19,087 ib_insync.client DEBUG <<< 73,1,1,*ACCOUNTNUMBER*,,CorporateBondValue,0.00,BASE
2023-11-10 16:34:19,087 ib_insync.client DEBUG <<< 73,1,1,*ACCOUNTNUMBER*,,TBondValue,0.00,BASE
2023-11-10 16:34:19,087 ib_insync.client DEBUG <<< 73,1,1,*ACCOUNTNUMBER*,,TBillValue,0.00,BASE
2023-11-10 16:34:19,087 ib_insync.client DEBUG <<< 73,1,1,*ACCOUNTNUMBER*,,WarrantValue,0.00,BASE
2023-11-10 16:34:19,087 ib_insync.client DEBUG <<< 73,1,1,*ACCOUNTNUMBER*,,FxCashBalance,0.00,BASE
2023-11-10 16:34:19,087 ib_insync.client DEBUG <<< 73,1,1,*ACCOUNTNUMBER*,,AccountOrGroup,U7327047,BASE
2023-11-10 16:34:19,088 ib_insync.client DEBUG <<< 73,1,1,*ACCOUNTNUMBER*,,RealCurrency,BASE,BASE
2023-11-10 16:34:19,088 ib_insync.client DEBUG <<< 73,1,1,*ACCOUNTNUMBER*,,IssuerOptionValue,0.00,BASE
2023-11-10 16:34:19,088 ib_insync.client DEBUG <<< 73,1,1,*ACCOUNTNUMBER*,,Cryptocurrency,,BASE
2023-11-10 16:34:19,088 ib_insync.client DEBUG <<< 74,1,1
2023-11-10 16:34:19,088 ib_insync.client DEBUG >>> 7,3,2,0,,,,,,
2023-11-10 16:34:23,094 ib_insync.ib INFO Disconnecting from 127.0.0.1:7496, 116 B sent in 8 messages, 16.3 kB received in 311 messages, session time 10.7 s.
2023-11-10 16:34:23,094 ib_insync.client INFO Disconnecting
@eljefe6a
Copy link
Author

I spent some more time debugging this issue. The exception happens in ib.py at:

await asyncio.wait_for(self.reqExecutionsAsync(), timeout)

The exception is:

Unable to display children:Error resolving variables Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/tasks.py", line 490, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/futures.py", line 198, in result
    raise exc
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/jesse/repos/stocks/pytrader/venv/lib/python3.11/site-packages/ib_insync/ib.py", line 1782, in connectAsync
    await asyncio.wait_for(self.reqExecutionsAsync(), timeout)
  File "/usr/lib/python3.11/asyncio/tasks.py", line 492, in wait_for
    raise exceptions.TimeoutError() from exc
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jesse/pycharm-community-2023.2.3/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_resolver.py", line 213, in resolve
    return dict[key]
           ~~~~^^^^^
KeyError: 'BaseException'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jesse/pycharm-community-2023.2.3/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 1245, in do_it
    _typeName, val_dict = pydevd_vars.resolve_compound_variable_fields(self.thread_id, self.frame_id, self.scope, self.attributes, dbg.get_user_type_renderers())
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jesse/pycharm-community-2023.2.3/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_vars.py", line 301, in resolve_compound_variable_fields
    var = getVariable(thread_id, frame_id, scope, attrs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jesse/pycharm-community-2023.2.3/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_vars.py", line 242, in getVariable
    var = resolver.resolve(var, k)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jesse/pycharm-community-2023.2.3/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_resolver.py", line 215, in resolve
    return getattr(dict, key)
           ^^^^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'BaseException'

@cgntiger
Copy link

没有error级别的日志吗?你这看不到问题,只知道断开连接了,如果你想要断开连接不断重连的话,设置disconnectedEvent回调事件函数就可以了

@tbrand
Copy link

tbrand commented Jan 5, 2024

Same here. Does anyone have an idea for us?
Edit: I found a similar issue here #612 but there is no solution.

@lgbongiolo
Copy link

Changing the TWS version to Stable fixed the issue for me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants