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.



View License

A collection of classes that shows how to wrap IB API inside a class and use event handlers.
For more details see

Comments and Ratings (11)


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',

Error in demoScript (line 20)'SPY');


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 (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 (view profile)


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?


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:
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?

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 (view profile)

Ahh... got it... RTM!

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



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:

%% subscribe to a symbol and show current events


>> 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 (view profile)



added 32-bit requirement


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

Win prizes and improve your MATLAB skills

Play today