Portfolio

View as MarkdownOpen in Claude

Request portfolio details for the selected account or accounts available to the user.

get_portfolio(

account_code: String. The accountID to pull portfolio information for. If an empty string is passed, all accounts are requested.

timeout: Integer. A default value of 10 seconds is supplied.

)

app.get_portfolio("")

Response Object

{
{Account ID}: List. List of all contracts
[{

contract: [Contract Object](/tws-api/doc/contracts-financial-instruments/the-contract-object). Contract to trade.

position: Decimal. The total number of shares held in the account.

marketPrice: Float. The current market price of the instrument.

marketValue: Float. The current value of the total position.

averageCost: Float. The average price across executions for the position.

unrealizedPNL: Float. The unrealized profit and loss for the instrument.

realizedPNL: Float. The realized profit and loss for the instrument.

accountName: String. The account identifier that holds the given position.

}]

[{'contract': 1957652380880: ConId: 265598, Symbol: AAPL, SecType: STK, LastTradeDateOrContractMonth: , Strike: 0, Right: , Multiplier: , Exchange: ISLAND, PrimaryExchange: , Currency: USD, LocalSymbol: AAPL, TradingClass: NMS, IncludeExpired: False, SecIdType: , SecId: , Description: , IssuerId: Combo:, 'position': Decimal('202635'), 'marketPrice': 258.57998655, 'marketValue': 52397355.58, 'averageCost': 263.3360764, 'unrealizedPNL': -963750.26, 'realizedPNL': 0.0, 'accountName': 'DU5240685'}]