Skip to content
← Back to documentation

Inventory Model: Balances and Inventory State

The Inventory Manager keeps asset accounting for every currency participating in the module. The inventory state is the basis for Matching Layer decisions (whether to execute from inventory) and Pricing Engine decisions (how to adjust the price).

Balance structure

For each currency, a set of fields is stored:

total_balance        # total currency balance in the system
reserved_balance     # reserved under active orders
available_balance    # available for new trades
inventory_target     # target inventory level
inventory_deviation  # current deviation from the target level
Basic relationship:

available_balance = total_balance – reserved_balance

  • total_balance — all currency funds under the system’s control (accumulated inventory plus working balances).
  • reserved_balance — amounts locked under orders in progress (pending payouts, counter-legs of swaps).
  • available_balance — the free remainder from which new Release-phase trades can be executed.
  • inventory_target — the target position level the system strives to maintain.
  • inventory_deviation — the calculated deviation of the actual balance from the target (formula below).

Inventory state

The key state metric is inventory_delta:

inventory_delta = current_balance – target_balance
Interpretation:

Value State System action
inventory_delta > 0 Asset surplus Need to sell: stimulate clients buying the asset
inventory_delta < 0 Asset deficit Need to buy: stimulate clients selling the asset
inventory_delta ≈ 0 Balanced Position matches the target level

 

Example for BTC inventory:

current_balance = 3.2 BTC
target_balance  = 2.5 BTC
inventory_delta = 3.2 – 2.5 = 0.7 BTC   # surplus: the system wants to sell BTC

How the state is used

  1. Pricing Engine converts inventory_delta into the price multiplier inventory_skew: a surplus lowers the asset price, a deficit raises it (formula: Pricing Engine).
  2. Matching Layer checks available_balance before Release-phase execution: an asset can be sold from inventory only within the available remainder (see Swap Execution Logic).
  3. Risk Engine watches the magnitude of inventory_deviation and signals position skew, limiting its uncontrolled growth.

State changes

Every executed trade changes the balances of both currencies in the pair (buying the asset increases its inventory and decreases the settlement currency stock; selling does the opposite). Step-by-step balance change scenarios: Swap Execution Logic.

See also