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
| Parameter | Type | Description |
|---|---|---|
| account | &str | Trading 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
| Field | Type | Description |
|---|---|---|
| account | String | Trading account ID |
| currency | String | Currency. USD or HKD |
| segment | String | Category by trading type. S=Stocks, C=Futures, D=Crypto, F=Funds, CONSOLIDATED=Stocks and Funds combined |
| availableFunds | double | Available funds (overnight excess liquidity) |
| excessLiquidity | double | Current excess liquidity |
| netLiquidation | double | Net liquidation value (total assets). Sum of cash balance and gross position value |
| equityWithLoan | double | Equity with loan value. Equals net liquidation minus US stock options |
| buyingPower | double | Buying power. Only meaningful for stocks (segment S) |
| cashBalance | double | Cash balance. Sum of cash across all currencies |
| grossPositionValue | double | Gross position value (total securities value) |
| initMarginReq | double | Initial margin requirement |
| maintMarginReq | double | Maintenance margin requirement |
| timestamp | long | Timestamp 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
| Field | Type | Description |
|---|---|---|
| account | String | Trading account ID |
| symbol | String | Symbol code, e.g. 'AAPL', '00700', 'ES', 'CN' |
| expiry | String | Expiry date. Options, warrants, and CBBC only |
| strike | String | Strike price. Options, warrants, and CBBC only |
| right | String | Right (PUT/CALL). Options, warrants, and CBBC only |
| identifier | String | Identifier. Same as symbol for stocks; includes contract month for futures, e.g. 'CN2201' |
| multiplier | int | Contract multiplier. Futures, options, warrants, and CBBC only |
| market | String | Market. US, HK |
| currency | String | Currency. USD or HKD |
| segment | String | Category by trading type. S=Stocks, C=Futures, D=Crypto, F=Funds |
| secType | String | Security type. STK Stocks, OPT Options, WAR Warrants, IOPT CBBC, CASH Forex, FUT Futures, FOP Future Options |
| positionQty | double | Position quantity |
| salableQty | double | Salable quantity |
| averageCost | double | Average cost |
| latestPrice | double | Latest price |
| marketValue | double | Market value |
| unrealizedPnl | double | Unrealized P&L |
| timestamp | long | Timestamp 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
| Field | Type | Description |
|---|---|---|
| id | long | Order ID |
| account | String | Trading account ID |
| symbol | String | Symbol code, e.g. 'AAPL', '00700', 'ES', 'CN' |
| expiry | String | Expiry date. Options, warrants, and CBBC only |
| strike | String | Strike price. Options, warrants, and CBBC only |
| right | String | Right (PUT/CALL). Options, warrants, and CBBC only |
| identifier | String | Identifier. Same as symbol for stocks; includes contract month for futures, e.g. 'CN2201' |
| multiplier | int | Contract multiplier. Futures, options, warrants, and CBBC only |
| action | String | Order direction. BUY or SELL |
| market | String | Market. US, HK |
| currency | String | Currency. USD or HKD |
| segment | String | Category by trading type. S=Stocks, C=Futures |
| secType | String | Security type. STK Stocks, OPT Options, WAR Warrants, IOPT CBBC, CASH Forex, FUT Futures, FOP Future Options |
| orderType | String | Order type. MKT Market / LMT Limit / STP Stop / STP_LMT Stop Limit / TRAIL Trailing Stop |
| isLong | boolean | Whether this is a long position |
| totalQuantity | long | Order quantity |
| filledQuantity | long | Total filled quantity (cumulative across partial fills) |
| avgFillPrice | double | Average fill price |
| limitPrice | double | Limit price |
| stopPrice | double | Stop price |
| realizedPnl | double | Realized P&L (consolidated accounts only) |
| status | String | Order status. PendingSubmit / Submitted / Cancelled / Inactive / Filled etc. |
| replaceStatus | String | Order replace status |
| cancelStatus | String | Order cancel status |
| outsideRth | boolean | Whether pre/post-market trading is allowed (US stocks only) |
| canModify | boolean | Whether the order can be modified |
| canCancel | boolean | Whether the order can be cancelled |
| liquidation | boolean | Whether this is a liquidation order |
| name | String | Security name |
| source | String | Order source (OpenApi or other) |
| errorMsg | String | Error message |
| commissionAndFee | float | Total commission and fees |
| openTime | long | Order open time |
| timestamp | long | Last order status update time |
| userMark | String | Custom user mark |
| timeInForce | String | Time 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
| Field | Type | Description |
|---|---|---|
| id | long | Transaction ID |
| orderId | long | Order ID |
| account | String | Trading account ID |
| symbol | String | Symbol code, e.g. 'AAPL', '00700', 'ES', 'CN' |
| identifier | String | Identifier. Same as symbol for stocks; includes contract month for futures, e.g. 'CN2201' |
| multiplier | int | Contract multiplier (futures and options only) |
| action | String | Order direction. BUY or SELL |
| market | String | Market. US, HK |
| currency | String | Currency. USD or HKD |
| segment | String | Category by trading type. S=Stocks, C=Futures |
| secType | String | Security type. STK Stocks, FUT Futures |
| filledPrice | double | Fill price |
| filledQuantity | long | Filled quantity |
| createTime | long | Create time |
| updateTime | long | Update time |
| transactTime | long | Transaction time |
| timestamp | long | Timestamp 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);Updated about 13 hours ago
Did this page help you?
