• C#
  • Java
  • VB
  • C++
  • Python
Contact us
Account Summary

Requesting

The IBApi.EClient.reqAccountSummary method creates a subscription for the account data displayed in the TWS Account Summary window. It is commonly used with multiple-account structures.

Unlike IBApi.EClient.reqAccountUpdates, IBApi.EClient.reqAccountSummary can not only retrieve summarized information for either one or all the managed accounts but also extract only the specified values to be monitored by the client application. The initial invocation of reqAccountSummary will result in a list of all requested values being returned, and then every three minutes those values which have changed will be returned. The update frequency of 3 minutes is the same as the TWS Account Window and cannot be changed.

  • client.reqAccountSummary(9001, "All", AccountSummaryTags.GetAllTags());
  • client.reqAccountSummary(9001, "All", "AccountType,NetLiquidation,TotalCashValue,SettledCash,AccruedCash,BuyingPower,EquityWithLoanValue,PreviousEquityWithLoanValue,GrossPositionValue,ReqTEquity,ReqTMargin,SMA,InitMarginReq,MaintMarginReq,AvailableFunds,ExcessLiquidity,Cushion,FullInitMarginReq,FullMaintMarginReq,FullAvailableFunds,FullExcessLiquidity,LookAheadNextChange,LookAheadInitMarginReq ,LookAheadMaintMarginReq,LookAheadAvailableFunds,LookAheadExcessLiquidity,HighestSeverity,DayTradesRemaining,Leverage");
  • client.reqAccountSummary(9001, "All", AccountSummaryTags.GetAllTags())
  • m_pClient->reqAccountSummary(9001, "All", AccountSummaryTags::getAllTags());
  • 1  self.reqAccountSummary(9001, "All", AccountSummaryTags.AllTags)

Starting from TWS Build 956 and IB Gateway 956, we have added the function to request account summary data (including CashBalance and TotalCashBalance) for every currency separately using LEDGER tags. Please see TWS Beta Release Notes.

When the "$LEDGER" tag is specified, the account summary data will be returned in BASE CURRENCY only.

  • client.reqAccountSummary(9002, "All", "$LEDGER");
  • client.reqAccountSummary(9002, "All", "$LEDGER");
  • client.reqAccountSummary(9002, "All", "$LEDGER")
  • m_pClient->reqAccountSummary(9002, "All", "$LEDGER");
  • 1  self.reqAccountSummary(9002, "All", "$LEDGER")

When the "$LEDGER:CURRENCY" tag is specified, the account summary data will be returned only in the CURRENCY specified. The CashBalance and TotalCashBalance returned are the balance in that specific currency only as you see within the TWS Account Window.

Example: "$LEDGER:USD", "$LEDGER:EUR", "$LEDGER:HKD" etc.

  • client.reqAccountSummary(9003, "All", "$LEDGER:EUR");
  • client.reqAccountSummary(9003, "All", "$LEDGER:EUR");
  • client.reqAccountSummary(9003, "All", "$LEDGER:EUR")
  • m_pClient->reqAccountSummary(9003, "All", "$LEDGER:EUR");
  • 1  self.reqAccountSummary(9003, "All", "$LEDGER:EUR")

When the "$LEDGER:ALL" tag is specified, the account summary data returned will be summed up values for ALL accounts and currencies.

Example:

Account = All, Currency = EUR, CashBalance = 12345.67

Account = All, Currency = JPY, CashBalance = 987.54

  • client.reqAccountSummary(9004, "All", "$LEDGER:ALL");
  • client.reqAccountSummary(9004, "All", "$LEDGER:ALL");
  • client.reqAccountSummary(9004, "All", "$LEDGER:ALL")
  • m_pClient->reqAccountSummary(9004, "All", "$LEDGER:ALL");
  • 1  self.reqAccountSummary(9004, "All", "$LEDGER:ALL")

Important: only two active summary subscriptions are allowed at a time!

Receiving

Summarised information is delivered via IBApi.EWrapper.accountSummary and IBApi.EWrapper.accountSummaryEnd

  • public class EWrapperImpl : EWrapper
    {
    ...
    public virtual void accountSummary(int reqId, string account, string tag, string value, string currency)
    {
    Console.WriteLine("Acct Summary. ReqId: " + reqId + ", Acct: " + account + ", Tag: " + tag + ", Value: " + value + ", Currency: " + currency);
    }
    ...
    public virtual void accountSummaryEnd(int reqId)
    {
    Console.WriteLine("AccountSummaryEnd. Req Id: "+reqId+"\n");
    }
  • public class EWrapperImpl implements EWrapper {
    ...
    @Override
    public void accountSummary(int reqId, String account, String tag,
    String value, String currency) {
    System.out.println("Acct Summary. ReqId: " + reqId + ", Acct: " + account + ", Tag: " + tag + ", Value: " + value + ", Currency: " + currency);
    }
    ...
    @Override
    public void accountSummaryEnd(int reqId) {
    System.out.println("AccountSummaryEnd. Req Id: "+reqId+"\n");
    }
  • Public Class EWrapperImpl
    Implements EWrapper
    ...
    Public Sub accountSummary(reqId As Integer, account As String, tag As String, value As String, currency As String) Implements IBApi.EWrapper.accountSummary
    Console.WriteLine("AccountSummary - ReqId [" & reqId & "] Account [" & account & "] Tag [" & tag & "] Value [" & value &
    "] Currency [" & currency & "]")
    End Sub
    ...
    Public Sub accountSummaryEnd(reqId As Integer) Implements IBApi.EWrapper.accountSummaryEnd
    Console.WriteLine("AccountSummaryEnd - ReqId [" & reqId & "]")
    End Sub
  • class TestCppClient : public EWrapper
    {
    ...
    void TestCppClient::accountSummary( int reqId, const std::string& account, const std::string& tag, const std::string& value, const std::string& currency) {
    printf( "Acct Summary. ReqId: %d, Account: %s, Tag: %s, Value: %s, Currency: %s\n", reqId, account.c_str(), tag.c_str(), value.c_str(), currency.c_str());
    }
    ...
    void TestCppClient::accountSummaryEnd( int reqId) {
    printf( "AccountSummaryEnd. Req Id: %d\n", reqId);
    }
  • 1 class TestWrapper(wrapper.EWrapper):
    ...
    1  def accountSummary(self, reqId: int, account: str, tag: str, value: str,
    2  currency: str):
    3  super().accountSummary(reqId, account, tag, value, currency)
    4  print("Acct Summary. ReqId:", reqId, "Acct:", account,
    5  "Tag: ", tag, "Value:", value, "Currency:", currency)
    6 
    ...
    1  def accountSummaryEnd(self, reqId: int):
    2  super().accountSummaryEnd(reqId)
    3  print("AccountSummaryEnd. Req Id: ", reqId)
    4 

Cancelling

Once the subscription to account summary is no longer needed, it can be cancelled via the IBApi::EClient::cancelAccountSummary method:

  • client.cancelAccountSummary(9001);
    client.cancelAccountSummary(9002);
    client.cancelAccountSummary(9003);
    client.cancelAccountSummary(9004);
  • client.cancelAccountSummary(9001);
    client.cancelAccountSummary(9002);
    client.cancelAccountSummary(9003);
    client.cancelAccountSummary(9004);
  • client.cancelAccountSummary(9001)
    client.cancelAccountSummary(9002)
    client.cancelAccountSummary(9003)
    client.cancelAccountSummary(9004)
  • m_pClient->cancelAccountSummary(9001);
    m_pClient->cancelAccountSummary(9002);
    m_pClient->cancelAccountSummary(9003);
    m_pClient->cancelAccountSummary(9004);
  • 1  self.cancelAccountSummary(9001)
    2  self.cancelAccountSummary(9002)
    3  self.cancelAccountSummary(9003)
    4  self.cancelAccountSummary(9004)