Expand description
A cash account that cannot hold leveraged positions.
§Balance locking
The account tracks locked balances per (InstrumentId, Currency) to support
instruments that lock different currencies depending on order side.
The portfolio computes locks for open orders as follows:
- BUY orders lock quote currency (cost of purchase), unless marked
reduce_only. - SELL orders lock base currency (assets being sold), unless marked
reduce_only. - Negative-price SELL orders also lock the cash disposal cost, including
reduce_onlyorders.
Instruments that model no base currency (binary options, equities, and the other types whose
base_currency() is None) have no asset to reserve, so a SELL locks only a negative-price
disposal cost, when present. Inventory availability for those instruments is not
tracked or checked locally, including across concurrent SELLs, and is left to the venue,
whose rejections arrive through the normal order lifecycle.
Callers must clear all existing locks via CashAccount::clear_balance_locked
before applying new locks. This prevents stale currency entries when order
compositions change.
§Graceful degradation
When total locked exceeds total balance (e.g., due to venue/client state latency), the account clamps locked to total rather than raising an error. This yields zero free balance, preventing new orders while avoiding crashes in live trading.
Structs§
- Cash
Account - Represents a cash account that cannot hold leveraged positions.