Profit & Loss
Introduction
Requests can be made to receive real time updates about the daily P&L and unrealized P&L for an account, or for individual positions. Financial Advisors can also request P&L figures for ‘All’ subaccounts, or for a portfolio model. This is further extended to include realized P&L information at the account or individual position level.
The P&L API functions demonstrated below return the data which is displayed in the TWS Portfolio Window in current versions of TWS. As such, the P&L values are calculated based on the reset schedule specified in TWS Global Configuration (by default an instrument-specific reset schedule) and this setting affects values sent to the associated API functions as well. Also in TWS, P&L data from virtual forex positions will be included in the account P&L if and only if the Virtual Fx section of the Account Window is expanded.
See Account Updates for alternative PnL data.
Request P&L for Accounts
EClient.reqPnL(reqId, account, modelCode)
Creates subscription for real time daily PnL and unrealized PnL updates. Updates are sent to EWrapper.pnl.
- Introducing broker accounts with less than 50 subaccounts can receive aggregate PnL for all subaccounts by specifying ‘All’ as the account code.
- With requests for advisor accounts with many subaccounts and/or positions can take several seconds for aggregated P&L to be computed and returned.
- For account P&L data the TWS setting “Prepare portfolio PnL data when downloading positions” must be checked.
Request ID to track the data.
Account for which to receive PnL updates.
Specify to request PnL updates for a specific model.
Python
Python (Full Example)
C++
C#
VB.NET
Receive P&L for Accounts
EWrapper.pnl(reqId, dailyPnL, unrealizedPnL, realizedPnL)
Request identifier for tracking data.
DailyPnL updates for the account in real time.
Total Unrealized PnL updates for the account in real time.
Total Realized PnL updates for the account in real time.
Python
Java
C++
C#
VB.NET
Cancel P&L for Accounts
EClient.cancelPnL(reqId)
Cancels subscription for real time updated daily PnL.
Request identifier for tracking data.
Python
Java
C++
C#
VB.NET
Request P&L for Individual Positions
EClient.reqPnLSingle(reqId, account, modelCode, conId)
Requests real time updates for daily PnL of individual positions. Updates are returned to EWrapper.pnlSingle approximately once per second.
- If a P&L subscription request is made for an invalid conId or contract not in the account, there will not be a response.
- As elsewhere in the API, a max double value will indicate an ‘unset’ value. This corresponds to an empty cell in TWS.
- Introducing broker accounts without a large number of subaccounts (<50) can receive aggregate data by specifying the account as “All”.
- Cannot be used with IBroker accounts configured for on-demand lookup with
account = 'All'.
Request identifier to track the data.
Account in which position exists.
Model in which position exists.
Contract ID (conId) of contract to receive daily PnL updates for. Note: does not return message if invalid conId is entered.
Python
Python (Full Example)
Java
C++
C#
Receive P&L for Individual Positions
EWrapper.pnlSingle(reqId, pos, dailyPnL, unrealizedPnL, realizedPnL, value)
Receives real time updates for single position daily PnL values.
Request identifier used for tracking.
Current size of the position.
DailyPnL for the position.
Total unrealized PnL for the position (since inception) updating in real time.
Total realized PnL for the position (since inception) updating in real time.
Current market value of the position.
Python
Java
C++
C#
VB.NET
Cancel P&L for Individual Positions
EClient.cancelPnLSingle(reqId)
Cancels real time subscription for a position’s daily PnL information.
Request identifier to cancel the P&L subscription for.

