Account and Order Subscriptions

Subscribe Account Changes

Description

Subscribe to real-time push notifications for account assets, positions, orders, and transaction details. Data is received through the following callbacks:

  • on_asset — Asset changes (full snapshot every 5 seconds)
  • on_position — Position changes (full snapshot every 5 seconds)
  • on_order — Order status changes (real-time)
  • on_transaction — Transaction details (real-time)

Parameters

ParameterTypeDescription
account&strTrading account ID. If not specified, subscribes to all accounts including paper trading

Example

// Subscribe to order status changes
push.subscribe(&SubjectType::OrderStatus, None, Some("your_account"), None);
// Subscribe to asset changes
push.subscribe(&SubjectType::Asset, None, Some("your_account"), None);
// Subscribe to position changes
push.subscribe(&SubjectType::Position, None, Some("your_account"), None);
// Subscribe to transaction details
push.subscribe(&SubjectType::OrderTransaction, None, Some("your_account"), None);
⚠️

Subscribing to any one of the four subjects will push data for all four types. Unsubscribing from any one subject cancels all four subscriptions.


Asset Change Callback

Callback: on_asset

Push frequency: Full snapshot every 5 seconds

Callback data fields

FieldTypeDescription
accountStringTrading account ID
currencyStringCurrency. USD or HKD
segmentStringCategory by trading type. S=Stocks, C=Futures, D=Crypto, F=Funds, CONSOLIDATED=Stocks and Funds combined
availableFundsdoubleAvailable funds (overnight excess liquidity)
excessLiquiditydoubleCurrent excess liquidity
netLiquidationdoubleNet liquidation value (total assets). Sum of cash balance and gross position value
equityWithLoandoubleEquity with loan value. Equals net liquidation minus US stock options
buyingPowerdoubleBuying power. Only meaningful for stocks (segment S)
cashBalancedoubleCash balance. Sum of cash across all currencies
grossPositionValuedoubleGross position value (total securities value)
initMarginReqdoubleInitial margin requirement
maintMarginReqdoubleMaintenance margin requirement
timestamplongTimestamp in milliseconds

Callback data example

{
    "account": "13810712",
    "currency": "USD",
    "segment": "S",
    "availableFunds": 2285040.55,
    "excessLiquidity": 2284942.05,
    "netLiquidation": 2285529.37,
    "equityWithLoan": 2285418.28,
    "buyingPower": 9140162.19,
    "cashBalance": 2284275.24,
    "grossPositionValue": 1143.04,
    "initMarginReq": 377.74,
    "maintMarginReq": 476.24,
    "timestamp": "1669888806020"
}

Position Change Callback

Callback: on_position

Push frequency: Full snapshot every 5 seconds

Callback data fields

FieldTypeDescription
accountStringTrading account ID
symbolStringSymbol code, e.g. 'AAPL', '00700', 'ES', 'CN'
expiryStringExpiry date. Options, warrants, and CBBC only
strikeStringStrike price. Options, warrants, and CBBC only
rightStringRight (PUT/CALL). Options, warrants, and CBBC only
identifierStringIdentifier. Same as symbol for stocks; includes contract month for futures, e.g. 'CN2201'
multiplierintContract multiplier. Futures, options, warrants, and CBBC only
marketStringMarket. US, HK
currencyStringCurrency. USD or HKD
segmentStringCategory by trading type. S=Stocks, C=Futures, D=Crypto, F=Funds
secTypeStringSecurity type. STK Stocks, OPT Options, WAR Warrants, IOPT CBBC, CASH Forex, FUT Futures, FOP Future Options
positionQtydoublePosition quantity
salableQtydoubleSalable quantity
averageCostdoubleAverage cost
latestPricedoubleLatest price
marketValuedoubleMarket value
unrealizedPnldoubleUnrealized P&L
timestamplongTimestamp in milliseconds

Callback data example

{
    "account": "13810712",
    "symbol": "AAPL",
    "identifier": "AAPL",
    "multiplier": 1,
    "market": "US",
    "currency": "USD",
    "segment": "S",
    "secType": "STK",
    "positionQty": 4.0,
    "averageCost": 75.0,
    "latestPrice": 147.23,
    "marketValue": 588.92,
    "unrealizedPnl": 288.92,
    "timestamp": "1669888802018"
}

Order Change Callback

Callback: on_order

Push frequency: Real-time on order status changes (Submitted, Cancelled, Inactive, Filled, etc.)

Callback data fields

FieldTypeDescription
idlongOrder ID
accountStringTrading account ID
symbolStringSymbol code, e.g. 'AAPL', '00700', 'ES', 'CN'
expiryStringExpiry date. Options, warrants, and CBBC only
strikeStringStrike price. Options, warrants, and CBBC only
rightStringRight (PUT/CALL). Options, warrants, and CBBC only
identifierStringIdentifier. Same as symbol for stocks; includes contract month for futures, e.g. 'CN2201'
multiplierintContract multiplier. Futures, options, warrants, and CBBC only
actionStringOrder direction. BUY or SELL
marketStringMarket. US, HK
currencyStringCurrency. USD or HKD
segmentStringCategory by trading type. S=Stocks, C=Futures
secTypeStringSecurity type. STK Stocks, OPT Options, WAR Warrants, IOPT CBBC, CASH Forex, FUT Futures, FOP Future Options
orderTypeStringOrder type. MKT Market / LMT Limit / STP Stop / STP_LMT Stop Limit / TRAIL Trailing Stop
isLongbooleanWhether this is a long position
totalQuantitylongOrder quantity
filledQuantitylongTotal filled quantity (cumulative across partial fills)
avgFillPricedoubleAverage fill price
limitPricedoubleLimit price
stopPricedoubleStop price
realizedPnldoubleRealized P&L (consolidated accounts only)
statusStringOrder status. PendingSubmit / Submitted / Cancelled / Inactive / Filled etc.
replaceStatusStringOrder replace status
cancelStatusStringOrder cancel status
outsideRthbooleanWhether pre/post-market trading is allowed (US stocks only)
canModifybooleanWhether the order can be modified
canCancelbooleanWhether the order can be cancelled
liquidationbooleanWhether this is a liquidation order
nameStringSecurity name
sourceStringOrder source (OpenApi or other)
errorMsgStringError message
commissionAndFeefloatTotal commission and fees
openTimelongOrder open time
timestamplongLast order status update time
userMarkStringCustom user mark
timeInForceStringTime in force. DAY=Day order, GTC=Good till cancelled, GTD=Good till date

Callback data example

{
    "id": "28875370355884032",
    "account": "736845",
    "symbol": "CL",
    "identifier": "CL2609",
    "multiplier": 1000,
    "action": "BUY",
    "market": "US",
    "currency": "USD",
    "segment": "C",
    "secType": "FUT",
    "orderType": "LMT",
    "isLong": true,
    "totalQuantity": "1",
    "filledQuantity": "1",
    "avgFillPrice": 77.76,
    "limitPrice": 77.76,
    "status": "Filled",
    "outsideRth": true,
    "name": "WTI Crude Oil Dec 2023",
    "source": "android",
    "commissionAndFee": 4.0,
    "openTime": "1669200792000",
    "timestamp": "1669200782221"
}

Transaction Detail Callback

Callback: on_transaction

Push frequency: Real-time on order execution

Callback data fields

FieldTypeDescription
idlongTransaction ID
orderIdlongOrder ID
accountStringTrading account ID
symbolStringSymbol code, e.g. 'AAPL', '00700', 'ES', 'CN'
identifierStringIdentifier. Same as symbol for stocks; includes contract month for futures, e.g. 'CN2201'
multiplierintContract multiplier (futures and options only)
actionStringOrder direction. BUY or SELL
marketStringMarket. US, HK
currencyStringCurrency. USD or HKD
segmentStringCategory by trading type. S=Stocks, C=Futures
secTypeStringSecurity type. STK Stocks, FUT Futures
filledPricedoubleFill price
filledQuantitylongFilled quantity
createTimelongCreate time
updateTimelongUpdate time
transactTimelongTransaction time
timestamplongTimestamp in milliseconds

Callback data example

{
    "id": "28875370482237440",
    "orderId": "28875370355884032",
    "account": "736845",
    "symbol": "CL",
    "identifier": "CL2609",
    "multiplier": 1000,
    "action": "BUY",
    "market": "US",
    "currency": "USD",
    "segment": "C",
    "secType": "FUT",
    "filledPrice": 77.76,
    "filledQuantity": "1",
    "createTime": "1669200793664",
    "updateTime": "1669200793664",
    "transactTime": "1669200793593",
    "timestamp": "1669200782233"
}

Unsubscribe

Description

Cancel account change subscriptions.

⚠️

Unsubscribing from any one subject cancels all four subscriptions (OrderStatus, Asset, Position, OrderTransaction).

Example

// Unsubscribe
push.unsubscribe(&SubjectType::OrderStatus, None, Some("your_account"), None);
push.unsubscribe(&SubjectType::Asset, None, Some("your_account"), None);
push.unsubscribe(&SubjectType::Position, None, Some("your_account"), None);
push.unsubscribe(&SubjectType::OrderTransaction, None, Some("your_account"), None);

Did this page help you?