erdewit / ib_insync

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

Error log upon connection: ib_insync.ib completed orders request timed out #355

Closed rgeronimi closed 3 years ago

rgeronimi commented 3 years ago

I have refreshed my IB stack with the latest version of every client (but I am not sure my problem comes from that as I have had pretty verbose logs and have only started to clean them up).

I keep getting this log message when opening a connection to the IB Gateway: ib_insync.ib completed orders request timed out

It seems to come from the connection initialization code in ib.py:1640

It doesn't prevent the entire system from working, but being at ERROR level this is spammy. My gateway is not in read-only mode (hence why this code is executed).

My versions: Python 3.7.10 uvloop 0.15.2 ib_insync 0.9.65 IB Gateway 981.2x

I use the ib_insync API in asynchronous mode exclusively.

erdewit commented 3 years ago

The completedOrders request can time out within the default of 4 seconds if there are many thousands of completed orders. If this is not the case then it would be an error situation, although the only consequence is that the completed orders are not available from ib.orders() etc.

The timeout can be increased, or readonly can be set to skip the request.

rgeronimi commented 3 years ago

Thx. There were no completed orders these days so this cannot be the cause (in that case). And the error is systematic. I will try to gather more information about what causes this.

erdewit commented 3 years ago

My gateway is not in read-only mode

Are you sure it's not set to read-only in the gateway/TWS settings?

rgeronimi commented 3 years ago

I can confirm the Gateway settings are not in read-only.

When I (alternatively) set them to read-only while keeping the python client in non-read-only mode, as expected this triggers another gateway error message (the gateway refuses to process the completed orders request) which did not occur in the former case. This proves the setting has an influence somewhat on the Gateway behavior.

I tested extending the connection timeout to very long durations (eg 15 seconds), to no avail.

I tested connecting instead (of the Gateway) to the Trader Workstation, in the "stable" (not latest) version, 978.2q. And there it works ! So the issue seems to come either from:

To test that I installed the (older) "stable" version of the Gateway (978.2q also). And there it works too !

So to conclude, the issue seems to be specific at least to the latest (post-stable) versions of the gateway. And maybe to the latest versions of the Trader Workstation too as they share a lot of Java code (I didn't test that case).

rgeronimi commented 3 years ago

In case this bug reoccurs in the future, I can confirm over the last 6 months this bug has disappeared on my side by rolling back to IB Gateway 978.2q, the "stable" version. However, the bug used to occur only with posterior versions, so it may still be latent there.