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

ParameterTypeDescription
account&strTrading 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

FieldTypeDescription
accountStringTrading account ID
currencyStringCurrency. USD or HKD
seg_typeStringCategory by trading type. S=Stocks, C=Futures, D=Crypto, F=Funds, CONSOLIDATED=Stocks and Funds combined
available_fundsdoubleAvailable funds (overnight excess liquidity)
excess_liquiditydoubleCurrent excess liquidity
net_liquidationdoubleNet liquidation value (total assets). Sum of cash balance and gross position value
equity_with_loandoubleEquity with loan value. Equals net liquidation minus US stock options
buying_powerdoubleBuying power. Only meaningful for stocks (segment S)
cash_balancedoubleCash balance. Sum of cash across all currencies
gross_position_valuedoubleGross position value (total securities value)
init_margin_reqdoubleInitial margin requirement
maint_margin_reqdoubleMaintenance margin requirement
timestamplongTimestamp 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

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
seg_typeStringCategory by trading type. S=Stocks, C=Futures, D=Crypto, F=Funds
sec_typeStringSecurity type. STK Stocks, OPT Options, WAR Warrants, IOPT CBBC, CASH Forex, FUT Futures, FOP Future Options
position_qtydoublePosition quantity
salable_qtydoubleSalable quantity
average_costdoubleAverage cost
latest_pricedoubleLatest price
market_valuedoubleMarket value
unrealized_pnldoubleUnrealized P&L
timestamplongTimestamp 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

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
seg_typeStringCategory by trading type. S=Stocks, C=Futures
sec_typeStringSecurity type. STK Stocks, OPT Options, WAR Warrants, IOPT CBBC, CASH Forex, FUT Futures, FOP Future Options
order_typeStringOrder type. MKT Market / LMT Limit / STP Stop / STP_LMT Stop Limit / TRAIL Trailing Stop
is_longbooleanWhether this is a long position
total_quantitylongOrder quantity
filled_quantitylongTotal filled quantity (cumulative across partial fills)
avg_fill_pricedoubleAverage fill price
limit_pricedoubleLimit price
stop_pricedoubleStop price
realized_pnldoubleRealized P&L (consolidated accounts only)
statusStringOrder status. PendingSubmit / Submitted / Cancelled / Inactive / Filled etc.
replace_statusStringOrder replace status
cancel_statusStringOrder cancel status
outside_rthbooleanWhether pre/post-market trading is allowed (US stocks only)
can_modifybooleanWhether the order can be modified
can_cancelbooleanWhether the order can be cancelled
liquidationbooleanWhether this is a liquidation order
nameStringSecurity name
sourceStringOrder source (OpenApi or other)
error_msgStringError message
commission_and_feefloatTotal commission and fees
open_timelongOrder open time
timestamplongLast order status update time
user_markStringCustom user mark
time_in_forceStringTime 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

FieldTypeDescription
idlongTransaction ID
order_idlongOrder 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
seg_typeStringCategory by trading type. S=Stocks, C=Futures
sec_typeStringSecurity type. STK Stocks, FUT Futures
filled_pricedoubleFill price
filled_quantitylongFilled quantity
create_timelongCreate time
update_timelongUpdate time
transact_timelongTransaction time
timestamplongTimestamp 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);

Did this page help you?