Error Msg ' Not Connected' in IB Trading Toolbox with Interactive Brokers TWS
4 views (last 30 days)
I am having issues using the Trading Toolbox with Interactive brokers. I have tried this on two separate TWS/Matlab installations on two different machines, connected to two different IB accounts. Both connect to Excel via the TWS api/DDE without difficulty.
I have the latest TWS and api software installed. ActiveX socket clients and DDE are enabled in the TWS api settings. Trusted ip is set to 127.0.0.1. ibtws object seems to be created fine:
ibtws with properties:
Handle: [1x1 COM.TWS_TwsCtrl_1]
However, any attempt to retried data produces a 'not connected' error message in Matlab. For example: ib.Handle.createContract; ibContract.symbol = 'GS'; ibContract.secType = 'STK'; ibContract.exchange = 'NYSE'; ibContract.currency = 'USD'
>> getdata(ib, ibContract)
Ray Ducharme on 4 May 2016
For me, it turned out I was using the wrong port. By going into...
TWS -> File -> Global Configuration -> API -> Settings -> Socket port...
I noticed the port number was not '7496' as seen in most Matlab examples (very close but not the same!). Making the switch fixed the "Not connected" error I was getting.
ib = ibtws('',7496) # <-- Switch the 7496 to your configuration port.
Alexey Yeremenko on 28 Oct 2015
Have you been able to connect? I got the same problem. No idea how to fix it.
Lars Helfenstein on 29 Apr 2016
Hi, did one of you ever find a solution? I got the same and checked and installed everything several times.
Jack Kenney on 22 Jan 2020
Some customers have reported that it helps to specify the client id requirement during connection like this:
ib = ibtws('127.0.0.1', 7496, 0);
(Replacing 7496 with your configuration port)
Documentation for the Client ID argument in the "ibtws" function is available here: