erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.86k stars 778 forks source link

Timeout exception when connecting to TWS Gateway due to reqCompletedOrdersAsync #224

Closed danlinenberg closed 4 years ago

danlinenberg commented 4 years ago

Hey, I'm getting a timeout exception when trying to connect to the Gateway. The problem is in ib.py lines 1603-1604 : if not readonly and self.client.serverVersion() >= 150: await self.reqCompletedOrdersAsync(False)

If I comment them out, I'm able to connect.

Here's the connection method:

ib.connect('127.0.0.1', 4002)

In the Gateway logs I get the following message: 2020-03-16 16:11:20.396 [NG] INFO [AWT-EventQueue-0] - Completed orders request cannot be sent for serverId=1 due to timeout. There is another pending request.

How can I fix this?

Thanks.

danlinenberg commented 4 years ago

Looks like another solution is to set the readonly flag to True, which other than not requesting the completed orders has no apparent usage. Not sure why that flag is related to the completed orders request though.

erdewit commented 4 years ago

2020-03-16 16:11:20.396 [NG] INFO [AWT-EventQueue-0] - Completed orders request cannot be sent for serverId=1 due to timeout. There is another pending request.

Thanks for the bug report and that specific log line. I wonder what other request is pending and why that should matter for the completedOrders request. Just another IB thing that has to be worked around... One possible workaround is a timeout for the completedOrders request.

erdewit commented 4 years ago

Setting the readonly flag is a good work-around. For some reason reqCompletedOrders is not allowed when the API is in readonly-mode, is ib_insync will not use it when the readonly flag is set.

In v0.9.60 here's also a timeout added for reqCompletedOrders.