Skip to main content

Portfolio

View balances and positions for your connected trading accounts.

Overview

A Portfolio represents the current state of a trading account, including:

  • Balances - Available and locked amounts of each asset
  • Positions - Open positions for derivatives accounts (futures, margin)

Portfolios are synced in real-time from the exchange.

The Portfolio Object

FieldTypeDescription
tradingAccountIdUUIDTrading account identifier
venueVenueExchange venue
balancesBalanceEntry[]List of asset balances
positionsPositionEntry[]List of open positions (derivatives only)
updatedAttimestampLast sync time

Balance Entry

FieldTypeDescription
assetstringAsset symbol (e.g., "BTC", "USDT")
freedecimalAvailable balance for trading
lockeddecimalBalance locked in open orders
totaldecimalTotal balance (free + locked)

Position Entry (Derivatives)

FieldTypeDescription
instrumentIdstringInstrument identifier
sidePositionSidePosition side (LONG, SHORT)
quantitydecimalPosition size
entryPricedecimalAverage entry price
markPricedecimalCurrent mark price
unrealizedPnldecimalUnrealized profit/loss
leverageintegerPosition leverage
marginTypeMarginModeMargin type (CROSS, ISOLATED)

List Portfolios

Retrieve portfolios for one or more trading accounts:

response = portfolio_api.list_trading_account_portfolios(
trading_account_id=trading_account_id
)

for portfolio in response.data:
print(f"Account: {portfolio.trading_account_id}")
print(f"Venue: {portfolio.venue}")

print("Balances:")
for balance in portfolio.balances:
if float(balance.total) > 0:
print(f" {balance.asset}:")
print(f" Free: {balance.free}")
print(f" Locked: {balance.locked}")
print(f" Total: {balance.total}")

Filter by Currency

Get balance for a specific asset:

response = portfolio_api.list_trading_account_portfolios(
trading_account_id=trading_account_id,
currency="USDT"
)

for portfolio in response.data:
for balance in portfolio.balances:
print(f"USDT Balance: {balance.total}")

Filter by Venue

Get portfolios for all accounts on a specific exchange:

response = portfolio_api.list_trading_account_portfolios(
venue=cadenza_client.Venue.BINANCE
)

for portfolio in response.data:
print(f"Account: {portfolio.trading_account_id}")

Positions (Derivatives)

For futures and margin accounts, the portfolio includes position information:

response = portfolio_api.list_trading_account_portfolios(
trading_account_id=futures_account_id
)

for portfolio in response.data:
print("Positions:")
for position in portfolio.positions or []:
print(f" {position.instrument_id}:")
print(f" Side: {position.side}")
print(f" Size: {position.quantity}")
print(f" Entry Price: {position.entry_price}")
print(f" Mark Price: {position.mark_price}")
print(f" Unrealized PnL: {position.unrealized_pnl}")
print(f" Leverage: {position.leverage}x")

Response Example

{
"data": [
{
"tradingAccountId": "660e8400-e29b-41d4-a716-446655440000",
"venue": "BINANCE",
"balances": [
{
"asset": "BTC",
"free": "0.50000000",
"locked": "0.10000000",
"total": "0.60000000"
},
{
"asset": "USDT",
"free": "10000.00000000",
"locked": "500.00000000",
"total": "10500.00000000"
}
],
"positions": [],
"updatedAt": 1704153600000
}
],
"success": true,
"errno": 0,
"error": null
}

Real-time Updates

For real-time portfolio updates, subscribe to the trading account WebSocket channel:

from cadenza_client.ws import Client

client = Client(WS_URL, token=access_token)
await client.connect()

sub = client.new_subscription(f"tradingAccount:{trading_account_id}")

def on_publication(ctx):
data = ctx.data
if data.get("type") == "portfolioUpdatedEvent":
portfolio = data["data"]
print(f"Portfolio updated: {portfolio}")

sub.on_publication(on_publication)
await sub.subscribe()

See the Quick Start for WebSocket setup and real-time subscriptions.