Skip to main content

Overview

NanoARB implements a high-performance limit order book (LOB) designed for HFT applications. The order book maintains up to 20 price levels on each side (bid/ask) with efficient O(log n) update complexity using Rust’s BTreeMap data structure.

Core Design

The order book is implemented in nano-lob/src/orderbook.rs:48 and consists of:
  • Bid side: Stored in descending order by price (highest bid = best bid)
  • Ask side: Stored in ascending order by price (lowest ask = best ask)
  • Maximum 20 levels per side (configurable via MAX_BOOK_LEVELS)
  • Fast updates: O(log n) insert/delete operations

Book Levels

Each price level contains detailed market depth information:

Applying Updates

The order book processes market data updates from CME MDP 3.0 and other feeds:

Snapshot Processing

Snapshots rebuild the entire book state:

Incremental Updates

Supports multiple update actions:
  • New/Change/Overlay: Add or update a price level
  • Delete: Remove a specific price level
  • DeleteThru: Remove all levels through a price
  • DeleteFrom: Remove all levels from a price

Accessing Book Data

Best Bid/Ask (BBO)

Level Access

Access specific depth levels (0 = best):

Depth Calculation

Calculate total quantity across multiple levels:

VWAP Calculation

Volume-weighted average price for market impact estimation:
From nano-lob/src/orderbook.rs:300:

Performance Characteristics

Time Complexity

  • Insert/Update: O(log n) via BTreeMap
  • Delete: O(log n)
  • Best bid/ask access: O(1) amortized
  • Level iteration: O(k) for k levels

Memory Efficiency

  • Maximum 20 levels × 2 sides = 40 price levels
  • Each BookLevel is ~32 bytes
  • Total memory per book: ~1.5 KB

Update Rate

The order book can handle:
  • 1M+ updates/second on modern hardware
  • Sub-microsecond update latency
  • Suitable for CME market data (100K+ messages/sec)

Book Validation

Several validation methods ensure book integrity:

Integration Example