For more information, see the official site: github.io

Contents

Initialize session with Trader Workstation

% initialize session with TWS
session = TWS.Session.getInstance();

% create local buffer for *protfolio update* events
[buf,lh] = TWS.initBufferForEvent(TWS.Events.PORTFOLIOUPDATE);

% connect to TWS
session.eClientSocket.eConnect('127.0.0.1',7496,0);
added interface method: TWSNotification
notification listener has been added
Server Version:71
TWS Time at connection:20141231 10:31:30 EST

Request Portfolio Updates

Note here that the IB API associates 3 callbacks with reqAccountUpdates()

However, TWS.Events.PORTFOLIOUPDATE is linked only to EWrapper:updatePortfolio() callback.

For events associated with updateAccountValue() see TWSAccountUpdatesExample.

% request account updates [*USE YOUR IB ACCOUNT NUMBER HERE*]
session.eClientSocket.reqAccountUpdates(true,'DU207406');

Process PortfolioUpdate events

Print out updates to the screen

cellfun(@(e)disp(e.data),collection2cell(buf))
DU207406 ARWR 0 7.44000005 0.0 0.0 0.0 -187.17
 
DU207406 RUSS 1000 25.6950016 25695.0 27.143 -1448.0 0.0
 

Note that to cancel portfolio updates call reqAccountUpdates(false,'DU207406')

References

Interactive Brokers API:

TWS@Github: