MATLAB Answers

1

Trading Toolbox (V3.5) NOT working with latest IB API

Asked by Robin Szeto on 23 Oct 2018
Latest activity Commented on by Steven Nilsen on 19 Jul 2019
System setting: Win10, Matlab 2018b, Trading Toolbox 3.5, IB Gateway 973.21 (newest)
1) Latest stable IB API now is V9.72, this version cannot successfully connect IB and Matlab by the following code: ib = ibtws('',7496);
2) Tried IB API V9.71.06 (an older version) instead, the above code can connect IB and Matlab, BUT..... other problem arise. Error message will pops up after execution of the following codes:
ibFutures = ib.Handle.createContract;
ibFutures.symbol = 'ES';
ibFutures.secType = 'FUT';
ibFutures.expiry = '201812'; % Dec 2018
ibFutures.exchange = 'SMART';
ibFutures.currency = 'USD';
bizDayConvention = 13; % i.e. BUS/252
currentdate = today;
startDate = daysadd(currentdate,-20,bizDayConvention);
endDate = daysadd(currentdate,-1,bizDayConvention);
histTradeData = history(ib,ibFutures,startDate,endDate);
Error message as below:
Error using registerevent (line 72)
Error registering events. 'historicalDataEnd' is not a valid event name.
Error in ibtws/history (line 54)
c.Handle.registerevent({eventNames{i},@(varargin)ibBuiltInHistoryEventHandler(varargin{:},c,tickerID)})
Error in IBGateway_0001 (line 15)
histTradeData = history(ib,ibFutures,startDate,endDate);

  1 Comment

I would like to see a solution from Mathworks on this. I experienced the exact same set of challenges with Matlab 2018b and 2019b, using the latest IB API (9.76) and the latest "stable" IB API (9.72). When using the older IB API (9.71.06) it does connect, but then gives a similar error message:
>> bizDayConvention = 13;
currentdate = today;
startDate = daysadd(currentdate,-20,bizDayConvention);
endDate = daysadd(currentdate,-1,bizDayConvention);
>> histTradeData = history(ib,ibContract,startDate,endDate);
Error using registerevent (line 72)
Error registering events. 'historicalDataEnd' is not a valid event name.
Error in ibtws/history (line 54)
c.Handle.registerevent({eventNames{i},@(varargin)ibBuiltInHistoryEventHandler(varargin{:},c,tickerID)})

Sign in to comment.

1 Answer

Answer by Yair Altman on 24 Oct 2018

Check whether you have correctly set the relevant settings on your TWS/Gateway's API configuration panel, specifically "Enable ActiveX clients", socket port 7496 (not the standard 4001/4002), and localhost (127.0.0.1) added as a trusted IP. Without these settings, no Matlab client can connect to IB. The port number that you specify in your ibtws() command has to match the port number that you specified in the TWS/Gateway's API configuration.
Also consider trying the Java-based IB-Matlab connector: https://undocumentedmatlab.com/IB-Matlab

  4 Comments

Show 1 older comment
If you take a look at IB-Matlab's changelog ( https://undocumentedmatlab.com/files/IB-Matlab_User_Guide.pdf#changelog ) you will see that it is continuously updated/improved. Give it a try...
Thanks! Will give a try. Just a question. Do I need to uninstall Trading Toolbox before using IB-Matlab connector?
There is no need to uninstall anything, they work independently of each other (although you probably won't be able to connect both of them at the same time to IB).

Sign in to comment.