I started coding to help me improve my trading execution process using python and the IBKR software.
I wrote (was helped) a code for a simple connection before attempting to enter the logic behind.
i did go through the posts on stack concerning the same. from ensuring the socket ports are matching to enabling the activex but to no avail. enter image description here
from ib_insync import IB
ib = IB()
try:
ib.connect('127.0.0.1', 7496, clientId=0)
print("Connection successful")
except Exception as e:
print(f"Error connecting to IB: {e}")
i have added screenshots 2 and 3 to show the connection and disconnection. it happens within microseconds. i added a timeout of 60 to see if it holds. it does for a minute and then disconnects.