Account and Order Subscriptions
Subscribe Account Changes
Description
Subscribe to account asset, position, order, and transaction notifications. Assets and positions use five-second snapshots; orders and transactions are pushed in real time. 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)
The tables and examples below use the snake_case field names of Rust prost callback values. The JSON illustrates fields and values; it does not imply that these structs implement serde::Serialize.
Live and paper trading accounts use the same asset and position snapshot interval.
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::Order, 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::Transaction, 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; live and paper trading accounts use the same interval
Callback data fields
| Field | Type | Description |
|---|---|---|
| account | String | Trading account ID |
| currency | String | Currency. USD or HKD |
| seg_type | String | Category by trading type. S=Stocks, C=Futures, D=Crypto, F=Funds, CONSOLIDATED=Stocks and Funds combined |
| available_funds | double | Available funds (overnight excess liquidity) |
| excess_liquidity | double | Current excess liquidity |
| net_liquidation | double | Net liquidation value (total assets). Sum of cash balance and gross position value |
| equity_with_loan | double | Equity with loan value. Equals net liquidation minus US stock options |
| buying_power | double | Buying power. Only meaningful for stocks (segment S) |
| cash_balance | double | Cash balance. Sum of cash across all currencies |
| gross_position_value | double | Gross position value (total securities value) |
| init_margin_req | double | Initial margin requirement |
| maint_margin_req | double | Maintenance margin requirement |
| timestamp | long | Timestamp in milliseconds |
Callback data example
{
"account": "13810712",
"currency": "USD",
"seg_type": "S",
"available_funds": 2285040.55,
"excess_liquidity": 2284942.05,
"net_liquidation": 2285529.37,
"equity_with_loan": 2285418.28,
"buying_power": 9140162.19,
"cash_balance": 2284275.24,
"gross_position_value": 1143.04,
"init_margin_req": 377.74,
"maint_margin_req": 476.24,
"timestamp": "1669888806020"
}Position Change Callback
Callback: on_position
Push frequency: Full snapshot every 5 seconds; live and paper trading accounts use the same interval
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 |
| seg_type | String | Category by trading type. S=Stocks, C=Futures, D=Crypto, F=Funds |
| sec_type | String | Security type. STK Stocks, OPT Options, WAR Warrants, IOPT CBBC, CASH Forex, FUT Futures, FOP Future Options |
| position_qty | double | Position quantity |
| salable_qty | double | Salable quantity |
| average_cost | double | Average cost |
| latest_price | double | Latest price |
| market_value | double | Market value |
| unrealized_pnl | double | Unrealized P&L |
| timestamp | long | Timestamp in milliseconds |
Callback data example
{
"account": "13810712",
"symbol": "AAPL",
"identifier": "AAPL",
"multiplier": 1,
"market": "US",
"currency": "USD",
"seg_type": "S",
"sec_type": "STK",
"position_qty": 4.0,
"average_cost": 75.0,
"latest_price": 147.23,
"market_value": 588.92,
"unrealized_pnl": 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 |
| seg_type | String | Category by trading type. S=Stocks, C=Futures |
| sec_type | String | Security type. STK Stocks, OPT Options, WAR Warrants, IOPT CBBC, CASH Forex, FUT Futures, FOP Future Options |
| order_type | String | Order type. MKT Market / LMT Limit / STP Stop / STP_LMT Stop Limit / TRAIL Trailing Stop |
| is_long | boolean | Whether this is a long position |
| total_quantity | long | Order quantity |
| filled_quantity | long | Total filled quantity (cumulative across partial fills) |
| avg_fill_price | double | Average fill price |
| limit_price | double | Limit price |
| stop_price | double | Stop price |
| realized_pnl | double | Realized P&L (consolidated accounts only) |
| status | String | Order status. PendingSubmit / Submitted / Cancelled / Inactive / Filled etc. |
| replace_status | String | Order replace status |
| cancel_status | String | Order cancel status |
| outside_rth | boolean | Whether pre/post-market trading is allowed (US stocks only) |
| can_modify | boolean | Whether the order can be modified |
| can_cancel | 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) |
| error_msg | String | Error message |
| commission_and_fee | float | Total commission and fees |
| open_time | long | Order open time |
| timestamp | long | Last order status update time |
| user_mark | String | Custom user mark |
| time_in_force | 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",
"seg_type": "C",
"sec_type": "FUT",
"order_type": "LMT",
"is_long": true,
"total_quantity": "1",
"filled_quantity": "1",
"avg_fill_price": 77.76,
"limit_price": 77.76,
"status": "Filled",
"outside_rth": true,
"name": "WTI Crude Oil Dec 2023",
"source": "android",
"commission_and_fee": 4.0,
"open_time": "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 |
| order_id | 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 |
| seg_type | String | Category by trading type. S=Stocks, C=Futures |
| sec_type | String | Security type. STK Stocks, FUT Futures |
| filled_price | double | Fill price |
| filled_quantity | long | Filled quantity |
| create_time | long | Create time |
| update_time | long | Update time |
| transact_time | long | Transaction time |
| timestamp | long | Timestamp in milliseconds |
Callback data example
{
"id": "28875370482237440",
"order_id": "28875370355884032",
"account": "736845",
"symbol": "CL",
"identifier": "CL2609",
"multiplier": 1000,
"action": "BUY",
"market": "US",
"currency": "USD",
"seg_type": "C",
"sec_type": "FUT",
"filled_price": 77.76,
"filled_quantity": "1",
"create_time": "1669200793664",
"update_time": "1669200793664",
"transact_time": "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::Order, 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::Transaction, None, Some("your_account"), None);Updated about 1 month ago
