Skip to main content

Overview

NanoARB is organized as a Cargo workspace with 7 crates, each responsible for a distinct layer of the trading system. This modular design enables:
  • Independent development - Crates can be tested and benchmarked in isolation
  • Clear dependencies - One-way dependency graph prevents circular references
  • Reusability - Core types and traits shared across all crates
  • Fast compilation - Changes to one crate don’t require rebuilding unrelated code

Dependency Graph

Dependency rule: All crates depend on nano-core, and dependencies only flow downward in the stack.

nano-core

Location: crates/nano-core/ Description: Foundation crate providing domain types, traits, constants, and error handling for the entire system.

Key Types

Price (types/price.rs:1)

Fixed-point decimal representation to avoid floating-point errors:
Usage: Price::from_ticks(50000, 25) represents $5000.00 with 0.25 tick size.

Quantity (types/quantity.rs:1)

Side (types/side.rs:1)

Timestamp (types/timestamp.rs:1)

Nanosecond-precision timestamp:

Order (types/order.rs:1)

Core Traits

Defines interfaces for all major system components (see traits.rs:1):

Strategy (traits.rs:48)

OrderBook (traits.rs:6)

ModelInference (traits.rs:160)

Dependencies

  • rust_decimal - Decimal arithmetic
  • serde / bincode / rkyv - Serialization
  • chrono - Time handling
  • thiserror - Error types
No runtime dependencies on other NanoARB crates.

nano-feed

Location: crates/nano-feed/ Description: CME MDP 3.0 binary protocol parser and synthetic data generator.

Features

  • SBE Decoder - Parses Simple Binary Encoding messages from CME
  • Zero-copy parsing - Uses nom combinator library for allocation-free parsing
  • Message types - Book updates, trades, channel resets, security status
  • Synthetic generator - Creates realistic market data for development and testing

Key Modules

MdpParser (parser.rs:1)

Parses raw CME MDP 3.0 packets:
Supported message types (see messages.rs:1):
  • MDIncrementalRefreshBook (Template 46) - Order book updates
  • MDIncrementalRefreshTrade (Template 42) - Executed trades
  • ChannelReset (Template 4) - Channel state reset
  • SecurityStatus (Template 30) - Trading status changes

Synthetic Data Generator (synthetic.rs:1)

Generates realistic market microstructure:
Generation model:
  • Geometric Brownian Motion for price drift
  • Poisson arrivals for order events
  • Realistic bid/ask spread and depth
  • Correlated buy/sell pressure

Dependencies

  • nano-core - Core types
  • nom - Parser combinators
  • bytes - Byte manipulation
  • rand / rand_distr - Random number generation

nano-lob

Location: crates/nano-lob/ Description: High-performance limit order book with 20-level depth and HFT feature extraction.

Key Modules

OrderBook (orderbook.rs:1)

Performance (see benchmarks in benches/orderbook.rs):
  • Update operation: 45ns median (P95: 62ns)
  • BBO query: 5ns (read-only, no allocation)
  • 20-level iteration: 180ns

LobFeatureExtractor (features.rs:1)

Extracts HFT features for ML models:
Feature definitions:
  1. Microprice - Volume-weighted mid:
  2. Order Flow Imbalance (OFI):
  3. VPIN - Volume-Synchronized Probability of Informed Trading:
  4. Book Imbalance:

SnapshotRingBuffer (snapshot.rs:1)

Fixed-size circular buffer for LOB history:
Usage: Maintain 100-snapshot history for ML model input.

Dependencies

  • nano-core - Core types and traits
  • nano-feed - Market data messages
  • ndarray - Tensor operations
  • smallvec - Stack-allocated vectors
  • parking_lot - Fast mutexes

nano-model

Location: crates/nano-model/ Description: ONNX-based ML model inference for trading signals.

Features

  • ONNX Runtime - Cross-platform inference engine
  • Model types - Mamba, Transformer, Decision Transformer, IQL
  • Batched inference - Process multiple instruments simultaneously
  • Latency tracking - Built-in performance monitoring

Key Types

SignalModel

Model architectures:
  1. Mamba-LOB - State Space Model (see README.md:295)
    • Input: (batch, seq=100, features=40)
    • Hidden: 128 dimensions, 4 Mamba blocks
    • Output: (batch, horizons=3, classes=3)
    • Parameters: ~500K
    • Inference: <800ns
  2. Decision Transformer - Offline RL
    • Predicts optimal actions given past trajectory
    • Context window: 20 timesteps
  3. IQL - Implicit Q-Learning
    • Value-based RL with expectile regression
    • Used for market-making policy

Training

Models are trained in Python (see python/training/) and exported to ONNX:
Trained models stored in models/ directory.

Dependencies

  • nano-core - Core types
  • nano-lob - Feature extraction
  • ndarray - Tensor operations
  • ort (optional) - ONNX Runtime

nano-strategy

Location: crates/nano-strategy/ Description: Trading strategy implementations and RL environment.

Key Modules

MarketMakerStrategy (market_maker.rs:1)

Classic market-making with ML signals:
Configuration (market_maker.rs:15):

RL Environment (rl_env.rs:1)

Gym-style interface for reinforcement learning:
Action space:
  • Bid offset: {-5, -4, …, 0, …, +4, +5} ticks
  • Ask offset: {-5, -4, …, 0, …, +4, +5} ticks
  • Total: 11 × 11 = 121 discrete actions
Reward function:

Signal Strategies (signals.rs:1)

ML-driven directional trading:

Dependencies

  • nano-core - Strategy trait
  • nano-lob - Order book access
  • nano-model - ML inference
  • rand - Action sampling

nano-backtest

Location: crates/nano-backtest/ Description: Event-driven backtesting engine with realistic latency and fill simulation.

Architecture

See detailed explanation in Architecture Overview.

Key Modules

BacktestEngine (engine.rs:33)

Core simulation loop:

EventQueue (events.rs:186)

Priority queue implementation:
Event types (events.rs:10):
  • MarketData - Book update received
  • OrderSubmit - Order sent to exchange
  • OrderAck - Order acknowledged
  • OrderFill - Order executed
  • OrderCancel - Cancellation confirmed

LatencySimulator (latency.rs:1)

Models network and processing delays:

SimulatedExchange (execution.rs:1)

Fill simulation with queue position model:
Fill logic:
  • Limit orders matched only if price crosses
  • Queue position estimated from book depth
  • Fill probability: P = min(1, volume_traded / queue_position)
  • Adverse selection: Market orders get worse average price

PositionTracker (position.rs:1)

Tracks inventory and P&L:

RiskManager (risk.rs:1)

Enforces trading limits:

Dependencies

  • nano-core - Types and traits
  • nano-feed - Market data
  • nano-lob - Order books
  • nano-model - ML models
  • statrs - Statistical functions
  • rand - Random number generation

nano-gateway

Location: crates/nano-gateway/ Description: System entry point with REST API, metrics export, and configuration management.

Features

  • Axum web server - REST API for backtests and state queries
  • Server-Sent Events - Real-time streaming to web UI
  • Prometheus metrics - Time-series monitoring
  • Configuration - TOML-based system config

API Endpoints

Served at http://localhost:9090: See Configuration documentation for API configuration details.

Binary Target

nanoarb (src/main.rs) Main executable:

Dependencies

  • All NanoARB crates
  • axum - Web framework
  • tokio - Async runtime
  • prometheus-client - Metrics
  • clap - CLI argument parsing
  • config / toml - Configuration

Build Configuration

The workspace Cargo.toml defines shared dependencies:

Compilation Profiles

Testing Strategy

Each crate includes:
  • Unit tests - #[cfg(test)] modules in source files
  • Integration tests - tests/ directory
  • Benchmarks - benches/ with Criterion.rs
  • Property tests - proptest for randomized testing

Next Steps