Skip to main content

Trading Data Channels

Private channels for trading account updates. Access is restricted to trading accounts available to the authenticated user.

Access Control

  • Users can only subscribe to channels for their authorized trading accounts
  • Use query.tradingAccount.list RPC to get available trading accounts
  • Subscription attempts to unauthorized accounts will be rejected

Channel Patterns

Channel PatternDescription
trading:executionReport:{tradingAccountId}Order status updates
trading:portfolio:{tradingAccountId}Portfolio and balance updates

Trading Account Subscriptions

Subscribe to trading account updates for orders, portfolio, and balances.

Channel Formats

trading:executionReport:{tradingAccountId}
trading:portfolio:{tradingAccountId}

Step 1: Get Available Trading Accounts

# RPC call to list available trading accounts
result = await client.rpc("query.tradingAccount.list", {})
trading_accounts = result.data.get("tradingAccounts", [])

Step 2: Subscribe to Channels

account_id = trading_accounts[0]["id"]

# Subscribe to execution reports
exec_channel = f"trading:executionReport:{account_id}"
exec_sub = client.new_subscription(exec_channel, events=exec_handler)
await exec_sub.subscribe()

# Subscribe to portfolio updates
portfolio_channel = f"trading:portfolio:{account_id}"
portfolio_sub = client.new_subscription(portfolio_channel, events=portfolio_handler)
await portfolio_sub.subscribe()

Event Types

Execution Report Channel (trading:executionReport:{tradingAccountId})

Event TypeDescriptionData Field
orderUpdateOrder status changedorder

Portfolio Channel (trading:portfolio:{tradingAccountId})

Event TypeDescriptionData Field
portfolioUpdatePortfolio updatedportfolio
balanceUpdateBalance changedbalance

Example: Handling Events

class ExecutionReportHandler(SubscriptionEventHandler):
async def on_publication(self, sub, event):
data = event.data
event_type = data.get("eventType")

if event_type == "orderUpdate":
order = data.get("order")
print(f"Execution report: {order}")


class PortfolioEventHandler(SubscriptionEventHandler):
async def on_publication(self, sub, event):
data = event.data
event_type = data.get("eventType")

if event_type == "portfolioUpdate":
portfolio = data.get("portfolio")
print(f"Portfolio update: {portfolio}")
elif event_type == "balanceUpdate":
balance = data.get("balance")
print(f"Balance update: {balance}")