File Exchange

image thumbnail

Connecting to Interactive Brokers via ActiveX API

version 1.4 (4.72 KB) by

Basic code that should help you get started with Interactive Brokers API.

10 Downloads

Updated

View License

A collection of classes that shows how to wrap IB API inside a class and use event handlers.
For more details see
http://matlab-trading.blogspot.com/2010/11/howto-wrap-interactive-brokers-tws-api.html

Comments and Ratings (11)

Zheng

Zheng (view profile)

this is the error message I've got. How to fix it?

Error using dateformverify (line 18)
DATESTR failed converting date number to date vector. Date number out
of range.

Error in datestr (line 196)
S = dateformverify(dtnumber, dateformstr, islocal);

Error in CTws/show (line 103)
            fprintf('Symbol:%s LastTrade:%2.2f time:%s \n',
            obj.symbolData{idx}.symbol,...

Error in demoScript (line 20)
tws.show('SPY');

Zheng

Zheng (view profile)

Hi Jev, Is it possible to give me an example how to execute the positions via your api? So many thanks.

DN

DN (view profile)

Jev, At a quick glance this seems excellent since I last saw max dama's stuff he started with some years ago. Now with windows 7's 64 bit system is there allot of changes needed? Can i just use your code as is?

thxs again

faruto

faruto (view profile)

Tobias

Tobias (view profile)

Thanks! Really nice! Some modification should be done to make it more flexible. I for example introduced a loop to acquire more data.
Anyhow, great program!

Mate 2u

Hi, I see you are printing the prices and time. If you want to carry on listening but storing in an array at real time how would this be possible?

Best,

I am trying to connect IB API on Matlab. I am able to connect to tws but when I try to get historical data I am getting following error in this command:
obj.tws.reqHistoricalDataEx(RequestID,Contract,EndDate,Duration,BarSize,’BID’,1,1);
Historical Market Data Service error message:Starting time must occur before ending time
EndDate = ’20110412 12:00:00′;
Duration = ’7200 S’;
BarSize = ’15 secs’;
Can you please figure out and let me know about the solution?
regards
prashant

Jev Kuznetsov

I am aware of the namespace problem... will fix it shortly and upload the new code. For now, just remove the 'IB.' prefix .

Chris

Chris (view profile)

Ahh... got it... RTM!

http://matlab-trading.blogspot.com/2010/11/howto-wrap-interactive-brokers-tws-api.html

Just delete all the references to the namespace the "IB." from the CTws.m.

Bingo!
         =D
                 Chris

Chris

Chris (view profile)

Hi Jev,

Just wanted to say thanks for posting the code!
Very helpful!

I'm using the Max Dama version right now but this is a very interesting version. Good job on the genericIBEvent.

Excellent job commenting the code.
The demoScript.m is very great!

There is however one error popping up.
I'm still pretty new to the OOP style of MATLAB so it could just be my setup/environment. (matlab 2010a)

So here's what I'm getting:

Running:
%% subscribe to a symbol and show current events
tws.subscribe('GOOG');

Exception:

>> tws.subscribe('GOOG');
??? Undefined variable "IB" or class "IB.CSymbolData".

Error in ==> CTws>CTws.subscribe at 68
           obj.symbolData{iNewSubs} = IB.CSymbolData(symbol);
 
I'll keep reading though the code. =D
Thanks again!

Chris

Chris (view profile)

Updates

1.4

added 32-bit requirement

1.3

Removed 'IB' namespace reference.

MATLAB Release
MATLAB 7.9 (R2009b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video