Skip to main content

Module cash

Module cash 

Source
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:

  • BUY orders lock quote currency (cost of purchase).
  • SELL orders lock base currency (assets being sold).

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§

CashAccount
Represents a cash account that cannot hold leveraged positions.