Exchange

The Exchange manages order books, matching, and portfolio state for all agents.

Current implementation: L1

The exchange currently implements level-1 (BBO only) mechanics:

  • Tracks only best_bid and best_ask.
  • Infinite liquidity at BBO (no depth depletion).
  • No queue position or FIFO priority.

This is the fastest model and sufficient for:

  • Testing low-frequency strategies.
  • PnL attribution.
  • Spread capture evaluation.

Per-agent portfolio isolation

Each agent has a separate Portfolio:

#![allow(unused)]
fn main() {
pub struct Portfolio {
    pub cash: f64,
    pub position: f64,
    pub realized_pnl: f64,
}
}

The exchange enforces isolation: agent A's orders cannot see or affect agent B's portfolio. CancelAll cancels only the requesting agent's resting orders. Fill history is tracked per agent.

Planned: L2 and L3

Future implementations will add depth-aware matching:

  • L2: aggregated volume per price tick. Market orders walk the book, consuming volume level by level. No queue priority.
  • L3: FIFO queues per tick. Strict price-time priority. Per-order identity and agent attribution. Higher computational cost but necessary for testing HFT strategies where queue position matters.

Transaction costs

Transaction costs are deducted per fill as a fraction of the fill value. The cost rate is configurable per agent.