Code covered by the BSD License  

Highlights from
Connecting to Interactive Brokers via ActiveX API

4.25

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

Connecting to Interactive Brokers via ActiveX API

by

 

17 Nov 2010 (Updated )

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

| Watch this File

File Information
Description

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

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

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');

19 Aug 2013 Zheng

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

23 Jul 2012 Dian

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

07 Apr 2012 faruto  
11 Aug 2011 Tobias

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?

Best,

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

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 .

18 Nov 2010 Chris

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

18 Nov 2010 Chris

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!

18 Nov 2010 Chris  
Updates
25 Nov 2010

Removed 'IB' namespace reference.

30 Nov 2010

added 32-bit requirement

Contact us