nautechsystems / nautilus_trader

A high-performance algorithmic trading platform and event-driven backtester
https://nautilustrader.io
GNU Lesser General Public License v3.0
1.71k stars 402 forks source link

Fix IBKR reconnection after gateway/TWS disconnection #1622

Closed benjaminsingleton closed 2 months ago

benjaminsingleton commented 2 months ago

Pull Request

This pull request addresses an issue with the Interactive Brokers (IBKR) reconnection mechanism. Previously, if the connection to the IB gateway or TWS was lost, either due to the nightly restart or a disrupted connection, the system was unable to successfully reestablish the connection. The changes introduced in this PR resolve this bug, ensuring that the connection can be properly restored after such interruptions.

Type of change

How has this change been tested?

Passes all integration tests. Also worked as anticipated while paper trading.

cjdsellers commented 2 months ago

I'm not as familiar with IB and the gateway, but would it be reasonable to bump up that asyncio.wait_for timeout to 30 seconds?

rsmb7z commented 2 months ago

I'm not as familiar with IB and the gateway, but would it be reasonable to bump up that asyncio.wait_for timeout to 30 seconds?

A 15-second interval is acceptable as Docker container downtimes are typically infrequent, and the Gateway restart process itself only takes about 2-3 seconds. Additionally, the nightly reset recovery is generally quicker for live accounts than for paper accounts on the IB side. However, it might be beneficial to make this interval configurable. We could introduce an argument that allows users to adjust the timing based on the specifics of their environment.