Interactive Brokers - IB Gateway API disconnects sporadically

23 views Asked by At

I have been using Interactive Brokers (IB) Gateway API for the past couple of years without any major issues. However, recently I've encountered a peculiar problem where the IB Gateway sporadically disconnects without throwing any errors.

I have an algorithm that I've been developing and testing on a paper account for quite some time. Within the past month, I've noticed this issue occurring where the IB Gateway simply disconnects seemingly at random intervals. Initially, I suspected server issues or problems with the IB Gateway version, but after investigating further, I haven't been able to pinpoint the exact cause.

What's puzzling is that this disconnection behavior is a recent development, despite the fact that the code has been stable for the past two years. Even after terminating the algorithm, attempting to reconnect results in the IB Gateway reporting "no internet connection," which seems implausible.

Here's the relevant code block where I establish the connection:

def websocket_con():
app.run()

# Main thread connects with the current client ID
app = TradingApp()
app.connect(host=op_main_var.ip_address, port=op_main_var.trade_port,
            clientId=op_main_var.Ultron_clientId)

# Separate daemon thread connects with a different client ID
con_thread = threading.Thread(target=websocket_con, daemon=True)
con_thread.start()

I initially suspected a conflict between messages due to the use of two threads, but Interactive Brokers mentioned that they handle this on their end.

I'm at a loss to explain this sudden behavior change and would appreciate any insights or suggestions on how to troubleshoot and resolve this issue. Thank you.

PS I'm not even sure if posting this block makes sense, but im still convinced it could be the issue of threads. I tried giving a daemon thread a separate client id, but it didn't work.

0

There are 0 answers