For more information, see the official site: github.io
Contents
Initialize session with TWS
% initialize session with TWS session = TWS.Session.getInstance(); % create local buffer for account summary events [buf,lh] = TWS.initBufferForEvent(TWS.Events.POSITIONS); % 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:05:20 EST
Request Positions
% request current positions
session.eClientSocket.reqPositions(); pause(0.5)
Process account update events
The message handler aggregates positions until EWrapper:positionsEnd() is called All positions up to that point are returned in a single event (i.e. event.data = HashSet<Positions>)
To check how many events have been returned
buf.get().data.size()
ans = 14
Keep it simple, print out each event in the buffer to the command window.
cellfun(@(e)cellfun(@(p)disp(p),collection2cell(e.data)),collection2cell(buf));
IWM 0 0.0 WLT 0 0.0 CVEO 0 0.0 GRFS 0 0.0 HZNP 0 0.0 GILD 0 0.0 DGAZ 0 0.0 SPY 0 0.0 ARWR 0 0.0 DUST 0 0.0 AAPL 0 0.0 NILSY 0 0.0 ORIG 0 0.0 RUSS 1000 27.143
References
Interactive Brokers API:
TWS@Github: