Account Updates
Introduction
The EClient.reqAccountUpdates function creates a subscription to the TWS through which account and portfolio information is delivered. This information is the exact same as the one displayed within the TWS’ Account Window. Just as with the TWS’ Account Window, unless there is a position change this information is updated at a fixed interval of three minutes.
Unrealized and Realized P&L is sent to the API function EWrapper.updateAccountValue after a subscription request is made with EClient.reqAccountUpdates. This information corresponds to the data in the TWS Account Window, and has a different source of information, a different update frequency, and different reset schedule than PnL data in the TWS Portfolio Window and associated API functions. In particular, the unrealized P&L information shown in the TWS Account Window which is sent to EWrapper.updatePortfolio will update either (1) when a trade for that particular instrument occurs or (2) every 3 minutes. The realized P&L data in the TWS Account Window is reset to 0 once per day.
It is important to keep in mind that the P&L data shown in the Account Window and Portfolio Window will sometimes differ because there is a different source of information and a different reset schedule.
See Profit & Loss for alternative PnL data.
Requesting Account Updates
EClient.reqAccountUpdates(subscribe, acctCode)
Subscribes to a specific account’s information and portfolio. Through this method, a single account’s subscription can be started/stopped. As a result from the subscription, the account’s information, portfolio and last update time will be received at EWrapper.updateAccountValue, EWrapper.updatePortfolio, and EWrapper.updateAccountTime respectively. All account values and positions will be returned initially, and then there will only be updates when there is a change in a position, or to an account value every 3 minutes if it has changed. Only one account can be subscribed at a time. A second subscription request for another account when the previous one is still active will cause the first one to be canceled in favor of the second one.
Set to true to start the subscription and to false to stop it.
The account id (i.e. U123456) for which the information is requested.
Python
Java
C++
C#
VB.NET
Account Value Keys
When requesting reqAccountUpdates, customers will receive values corresponding to various account key/value pairs. Account values delivered via EWrapper.updateAccountValue can be classified in the following way:
- Commodities: suffixed by a
-C - Securities: suffixed by a
-S - Totals: no suffix
Receiving Account Updates
Resulting account and portfolio information will be delivered via EWrapper.updateAccountValue, EWrapper.updatePortfolio, EWrapper.updateAccountTime, and EWrapper.accountDownloadEnd.
EWrapper.updateAccountValue
EWrapper.updateAccountValue(key, value, currency, accountName)
Receives the subscribed account’s information. Only one account can be subscribed at a time. After the initial callback to updateAccountValue, callbacks only occur for values which have changed. This occurs at the time of a position change, or every 3 minutes at most. This frequency cannot be adjusted.
The value being updated.
Up-to-date value.
The currency on which the value is expressed.
The account identifier.
Python
Java
C++
C#
VB.NET
EWrapper.updatePortfolio
EWrapper.updatePortfolio(contract, position, marketPrice, marketValue, averageCost, unrealizedPNL, realizedPNL, accountName)
Receives the subscribed account’s portfolio. This function will receive only the portfolio of the subscribed account. After the initial callback to updatePortfolio, callbacks only occur for positions which have changed.
The Contract for which a position is held.
The number of positions held.
The instrument’s unitary price.
Total market value of the instrument.
Average cost of the overall position.
Daily unrealized profit and loss on the position.
Daily realized profit and loss on the position.
Account ID for the update.
Python
Java
C++
C#
VB.NET
EWrapper.updateAccountTime
EWrapper.updateAccountTime(timestamp)
Receives the last time on which the account was updated.
The last update system time.
Python
Java
C++
C#
VB.NET
EWrapper.accountDownloadEnd
EWrapper.accountDownloadEnd(account)
Notifies when all the account’s information has finished.
The account identifier.
Python
Java
C++
C#
VB.NET
Cancel Account Updates
EClient.reqAccountUpdates(subscribe, acctCode)
Once the subscription to account updates is no longer needed, it can be cancelled by invoking EClient.reqAccountUpdates with subscribe set to false.
reqAccountUpdates(true, "F123456A").Set to false to stop the subscription.
The account id for which the subscription is being cancelled.

