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

Contents

Initialize session with Trader Workstation

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

However, TWS.Events.ACCOUNTUPDATES is linked only to updateAccountValue().

For events associated with updatePortfolio() see TWSPortfolioUpdateExample.

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

% create local buffer for account summary events
[buf,lh] = TWS.initBufferForEvent(TWS.Events.ACCOUNTUPDATE);

% 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:27:19 EST

Request Account Updates

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

AccountUpdate(s) are published as individual/separate events Here, for accountUpdate subscription, AccountAttributes are published as individual/separate events. This is in contrast to AccountSummary event where AccountAttributes are aggregated into a single event (i.e. event.data = HashSet<AcountAttributes>). Trader Workstation pushes all attributes when subscription is started but individually there after.

buf.size()
ans =

    32

Process account update events

For simplicity, just print out each event in the buffer to the command window. See link to IB API updateAccountValue in Reference section for more information about account attributes

cellfun(@(e)disp(e.data),collection2cell(buf));
DU207406 PostExpirationMargin 0.00 USD
 
DU207406 PostExpirationMargin-C 0.00 USD
 
DU207406 PostExpirationMargin-S 0.00 USD
 
DU207406 PreviousDayEquityWithLoanValue 1003796.95 USD
 
DU207406 PreviousDayEquityWithLoanValue-S 1003796.95 USD
 
DU207406 RealizedPnL -187 BASE
 
DU207406 RealizedPnL -187 USD
 
DU207406 RegTEquity 1003076.78 USD
 
DU207406 RegTEquity-S 1003076.78 USD
 
DU207406 RegTMargin 13305.00 USD
 
DU207406 RegTMargin-S 13305.00 USD
 
DU207406 SMA 990035.78 USD
 
DU207406 SMA-S 990035.78 USD
 
DU207406 SegmentTitle-C US Commodities null
 
DU207406 SegmentTitle-S US Securities null
 
DU207406 StockMarketValue 26610 BASE
 
DU207406 StockMarketValue 26610 USD
 
DU207406 TBillValue 0 BASE
 
DU207406 TBillValue 0 USD
 
DU207406 TBondValue 0 BASE
 
DU207406 TBondValue 0 USD
 
DU207406 TotalCashBalance 976467 BASE
 
DU207406 TotalCashBalance 976467 USD
 
DU207406 TotalCashValue 976466.78 USD
 
DU207406 TotalCashValue-C 0.00 USD
 
DU207406 TotalCashValue-S 976466.78 USD
 
DU207406 TradingType-S STKNOPT null
 
DU207406 UnrealizedPnL -533 BASE
 
DU207406 UnrealizedPnL -533 USD
 
DU207406 WarrantValue 0 BASE
 
DU207406 WarrantValue 0 USD
 
DU207406 WhatIfPMEnabled true null
 

References

Interactive Brokers API:

TWS@Github:

Apache Commons: