Problem using 'getdata' function using the Trading Toolbox
Show older comments
I recently bought the Trading Toolbox to be able to receive data from Interactive Brokers (IB) in a simple way. A lot of the functions work fine, though I do experience some problems when using the 'getdata' and 'realtime' functions that are provided by the toolbox. They are somewhat the same functions and I do get the same errors as well when using them. In this topic I would like to focus on the 'getdata' function in this topic. When I use the following function I get the following error:
clear ibBuiltInErrMsg
d= getdata(ib,ibContract)
Error using comeventcallback (line 24)
Error firing event 'tickPrice' to
'@(varargin)ibBuiltInGetDataEventHandler(varargin{:},c)'.
Error using comeventcallback (line 24)
Error firing event 'tickPrice' to
'@(varargin)ibBuiltInGetDataEventHandler(varargin{:},c)'.
d =
struct with fields:
BID_SIZE: 6000000
ASK_SIZE: 1000000
As you can see, I do get the 'tickSize' data returned, but not the 'tickPrice' data. It seems the datarequest itself is fine, but processing the data gives the errors. Also, requesting historical data works great.
I tried requesting livedata using the PythonAPI and that works perfectly fine. Therefore I argue the problem is not in my configuration, but in the MATLAB function.
Anyone familiar with this problem? How can I solve this problem and receive the live price data? Thank you in advance!
I use the latest TWS API, MATLAB 2019b and the most recent Trading Toolbox. I tried other TWS API versions, but that did not resolve the problem.
4 Comments
Annie Leonhart
on 1 Mar 2020
Don't you worry, I'll test this right this very moment.
Annie Leonhart
on 1 Mar 2020
Edited: Annie Leonhart
on 1 Mar 2020
I've been unable to replicate the issue on R2019a
TWS Latest Api: API 9.79
Because I've already done extensive testing through all the APIs and the entire trading toolbox (even created by own trading toolbox) the error is because the eventhandler handles the return buffer with very specific parameters. I'll show you.
case 'tickPrice'
switch varargin{9}.tickType
case 1
% BID PRICE
ibBuiltInCurrentData.BID_PRICE = varargin{9}.price;
case 2
% ASK PRICE
ibBuiltInCurrentData.ASK_PRICE = varargin{9}.price;
case 4
% LAST PRICE
ibBuiltInCurrentData.LAST_PRICE = varargin{9}.price;
end
As you can see, it's doing a case switch on the return buffer. "varargin" is the buffer. it's looking for the 9th object {9} and it'll return a struct, so to get the price, matlab adds ".price"... if .price doesn't exist, which will be the case based on which version of the API you're using, it'll throw an error. I believe on earlier versions of the API, it should be "varargin{7}.price" see the issue? If you're using the 9.79 api then It should be working fine. I made a very long post somewhere aboue changing varargin for older APIs. In short, I know you said you tried all the APIs, but just make sure you're using 9.73+ as it's hard coded into matlabs code. Be sure you've uninstalled other TWS apis including the folder "C:\TWS API" on your C:\.
Here's the link to my post that shows you how to fix this.... https://www.mathworks.com/matlabcentral/answers/449439-unable-to-connect-to-interactive-brokers-after-installed-2018a-in-new-laptop
For those who want to learn how to troublshoot this kind of stuff, you can build your own event handlers :D rather than rely on MATLAB's. I'll respond later today on how to create your own event handlers to return TWS data to you however you want. :D
Gijs van Beek
on 1 Mar 2020
Edited: Gijs van Beek
on 1 Mar 2020
Annie Leonhart
on 24 Mar 2020
Very good!
Answers (0)
Categories
Find more on Financial Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!