View License

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

» Watch video

Highlights from
Connecting to Interactive Brokers via ActiveX API

4.2 | 5 ratings Rate this file 8 Downloads (last 30 days) File Size: 4.72 KB File ID: #29434 Version: 1.4

Connecting to Interactive Brokers via ActiveX API



17 Nov 2010 (Updated )

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

| Watch this File

File Information

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

MATLAB release MATLAB 7.9 (R2009b)
Other requirements IB active X isnstalled, TWS running, 32-bit system
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (11)
21 Aug 2013 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',

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

19 Aug 2013 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.

23 Jul 2012 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

Comment only
07 Apr 2012 faruto

faruto (view profile)

11 Aug 2011 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!

28 Jul 2011 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?


Comment only
08 Jun 2011 Prashant bajpayee

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?

Comment only
18 Nov 2010 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 .

Comment only
18 Nov 2010 Chris

Chris (view profile)

Ahh... got it... RTM!

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


Comment only
18 Nov 2010 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:

%% 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!

Comment only
18 Nov 2010 Chris

Chris (view profile)

25 Nov 2010 1.3

Removed 'IB' namespace reference.

30 Nov 2010 1.4

added 32-bit requirement

Contact us