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

1 Ansicht (letzte 30 Tage)
Robin Szeto
Robin Szeto am 23 Okt. 2018
Bearbeitet: Gilles Desvilles am 27 Mai 2021
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);
  6 Kommentare
Ryan Hendry
Ryan Hendry am 10 Mär. 2020
Bearbeitet: Ryan Hendry am 11 Mär. 2020
Hey friend, I appreicate your post here. I am relatively new to using matlab for these purposes. I have the following:
(TWS has API settings enables, socket etc.)
%% IB TWS Connection
clc
clear
% PORT 7497 IS FOR PAPER-BACKTEST, 7496 IS FOR LIVE
ib = ibtws('', 7497);
The error I recieve is:
Error in actxserver (line 89)
h=feval(['COM.' convertedProgID], 'server', machinename, interface);
Error in ibtws (line 37)
x.Handle = actxserver('TWS.TwsCtrl.1');
Error in test_book (line 9)
ib = ibtws('', 7497);
Not sure where I am going wrong, i've been trying to follow online solutions but they don't seem to work. If you have any suggestions let me know. I am running Trading Toolbox 3.6 and Matlab R2019b.
Annie Leonhart
Annie Leonhart am 14 Mär. 2020
You’re not using the latest api. Uninstall any api you have, delete the folder at C:/TWS API.
Reboot
Then install 9.76+
This is an API problem.
It’s looking for the API jar file for 9.71 and below named TWS.TwsCTRL.1 when it’s named TWS.TwsCtrl in the new APIS

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Yair Altman
Yair Altman am 24 Okt. 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 Kommentare
Robin Szeto
Robin Szeto am 25 Okt. 2018
Thanks! Will give a try. Just a question. Do I need to uninstall Trading Toolbox before using IB-Matlab connector?
Yair Altman
Yair Altman am 25 Okt. 2018
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).

Melden Sie sich an, um zu kommentieren.


Annie Leonhart
Annie Leonhart am 15 Jan. 2020
The guy's contract is not valid.
I'm not subscribed to GLOBEX so I cannot request ES. Also, you cannot use SMART as an exchange for Futures, Futures Options, or Commodities, Bonds, etc... SMART is only for stocks and options.
Here is a proper contract for a futures security. Also, you must set the contract "include Expired" because it's 2019 and you're requesting an expired contract.
ibFutures = ib.Handle.createContract;
ibFutures.symbol = 'CL';
ibFutures.secType = 'FUT';
ibFutures.lastTradeDateOrContractMonth = '201812'; % Dec 2018
ibFutures.includeExpired = true;
ibFutures.exchange = 'NYMEX';
ibFutures.primaryExchange = 'NYMEX';
ibFutures.currency = 'USD';
Now that you have a proper contract, you need to setup the proper request days, you're requesting 20 days of history from today, but again, it's 2019. Either set the current day to Dec 2018 or do as I did -500 days.
currentdate = today;
startDate = daysadd(currentdate,-500,bizDayConvention);
endDate = daysadd(currentdate,-1,bizDayConvention);
Finally run the code
histTradeData = history(ib,ibFutures,startDate,endDate)
This is using the latest stable API 9.72 from IB on R2019a.
  3 Kommentare
Annie Leonhart
Annie Leonhart am 9 Mär. 2020
Bearbeitet: Annie Leonhart am 9 Mär. 2020
Wrong. It works on the latest api.
You have it setup wrong. The problem is on your end, not matlabs.
If you can’t get a connection at all your port is wrong.
Please post whatever error you’re getting. I can make it work on any API. I’m currently running it on 9.76. Also note at the time of posting, 9.72 was the latest. It’ll work on 9.79 as well.
Gilles Desvilles
Gilles Desvilles am 25 Mai 2021
Bearbeitet: Gilles Desvilles am 27 Mai 2021
Dear Annie
You give a new hope to matlab users, in 2019 I had asked tens of times Mathworks to correct their bug, maybe they have done it in 2020 ...
I have been forced to use matlab 32 bits 2015a and api 971.06 and it worked as a temporary solution
Can you tell which version of matlab you use, which port (7496 ?), which operating system (linux, windows etc) ?
Thank you

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Install Products finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by