Interactive Brokers via Matlab

3 Min Read

Here’s a video guide to using the Interactive Brokers API with Matlab.

The following are the notes that go along with the video, it follows each step

install trader workstation (i.e. tws)
http://individuals.interactivebrokers.com/en/software/installationInstructions.php?ib_entity=llc

install the api
http://www.interactivebrokers.com/download/InstallAX_951.exe
online api guide fyi
http://www.interactivebrokers.com/php/apiUsersGuide/apiguide.htm

enable the activex api
run tws
configure > API > enable ActiveX and Socket Clients

register the activex server
windows start button > run > regsvr32 “C:\Program Files\Jts\ActiveX\Tws.ocx”
restart the computer
run tws

run matlab
set up preliminary variables with the following commands
>> global eventdata orderid; eventdata = {}; orderid = 1; f = figure; set(f,’Visible’,’off’);
connect Matlab to the api
copy twsevent.m to your current Matlab directory
>> tws = actxcontrol(‘TWS.TwsCtrl.1′,[0 0 0 0],f,’twsevent’);
>> tws.connect(”, 7496, 1);
test it!
use the newcontract.m script- copy it to the current directory
>> newcontract
>> tws.reqMktDataEx(orderid, contract, ”, 1)
>> tws.reqCurrentTime()

S = INVOKE(OBJ) returns structure


Here’s a video guide to using the Interactive Brokers API with Matlab.

The following are the notes that go along with the video, it follows each step

install trader workstation (i.e. tws)
http://individuals.interactivebrokers.com/en/software/installationInstructions.php?ib_entity=llc

install the api
http://www.interactivebrokers.com/download/InstallAX_951.exe
online api guide fyi
http://www.interactivebrokers.com/php/apiUsersGuide/apiguide.htm

enable the activex api
run tws
configure > API > enable ActiveX and Socket Clients

register the activex server
windows start button > run > regsvr32 “C:\Program Files\Jts\ActiveX\Tws.ocx”
restart the computer
run tws

run matlab
set up preliminary variables with the following commands
>> global eventdata orderid; eventdata = {}; orderid = 1; f = figure; set(f,’Visible’,’off’);
connect Matlab to the api
copy twsevent.m to your current Matlab directory
>> tws = actxcontrol(‘TWS.TwsCtrl.1′,[0 0 0 0],f,’twsevent’);
>> tws.connect(”, 7496, 1);
test it!
use the newcontract.m script- copy it to the current directory
>> newcontract
>> tws.reqMktDataEx(orderid, contract, ”, 1)
>> tws.reqCurrentTime()

S = INVOKE(OBJ) returns structure array S containing a list of
all methods supported by the object or interface OBJ along
with the prototypes for these methods.
invoke(ib)
METHODSVIEW(OBJECT) displays the methods of OBJECT’s class along
with the properties of each method.
methodsview(ib)
Webinar:
http://www.interactivebrokers.com/en/general/education/priorWebinars.php?ib_entity=llc

Here are the two extra files needed
newcontract.m
twsevent.m
UPDATED: Here’s a script of the above instructions in case you get an error: testtws.m

Follow along in notes above and it should be clear enough.

Like I mentioned, please suggest how the process might be improved if you have ideas. Anything else is welcome too.

Share This Article
Exit mobile version