I have multiple IB accounts, both linked and unlinked ones. I want to be able to trade on two different accounts simultaneously from the same script in Jupyter Notebook, which requires opening two difference instances of IBG or TWS. But how do you make the script to recognize and distinguish between the two instances?
I have tried to open one IBG and one TWS window, each logged into a different account, and the configuration is set so that each has its own unique port number and client id. But that doesn’t work. The script can only connect to one of the instances, and gives an error when trying to connect to the second.
# connect to the IBG
ib = IB()
ib.connect('127.0.0.1', 7496, clientId=6)
# connect to the TWS
ib_2 = IB()
ib_2.connect('127.0.0.1', 7497, clientId=7)
but get the following error message: