Introduction
NanoARB is a nanosecond-level high-frequency trading framework built in Rust for CME futures markets (ES, NQ). It achieves sub-microsecond inference latency through an event-driven architecture that combines ultra-low-latency systems programming with cutting-edge machine learning models.Core Design Principles
Event-Driven Architecture
NanoARB uses a strict event-driven model where all system operations are triggered by timestamped events processed through a priority queue. This design ensures:- Deterministic execution - Events are processed in chronological order
- Realistic backtesting - Lookahead bias is eliminated by enforcing causality
- Latency modeling - Network and processing delays are explicitly simulated
- Parallel execution - Multiple strategies can run independently
BinaryHeap-based priority queue (see nano-backtest/src/events.rs:186) that guarantees O(log n) insertion and O(1) peek operations.
Zero-Copy Data Processing
To minimize latency, NanoARB employs zero-copy techniques throughout the stack:- CME MDP 3.0 parsing - Direct binary message parsing with
nomcombinator library - Order book updates - In-place modification of
BTreeMapdata structures - Serialization -
rkyvfor zero-copy deserialization of archived data
Type Safety & Performance
All core types are strongly typed with compile-time guarantees:Price- Fixed-point decimal to avoid floating-point errorsQuantity- Unsigned integer with overflow checksTimestamp- Nanosecond-precision u64OrderId- Unique identifier with non-zero guarantee
nano-core/src/types/ for implementations.
System Architecture
Component Interaction
Data Flow (Market Data → Strategy)
-
Market Data Ingestion
- CME MDP 3.0 binary packets arrive via multicast UDP
MdpParser(nano-feed) decodes SBE-encoded messages- Messages are validated and converted to internal types
-
Order Book Update
OrderBook(nano-lob) applies incremental updates- 20-level bid/ask depth maintained in
BTreeMap - Book snapshot added to
SnapshotRingBufferfor ML inference
-
Feature Extraction
LobFeatureExtractorcomputes:- Microprice - Volume-weighted mid price
- OFI - Order Flow Imbalance
- VPIN - Volume-Synchronized Probability of Informed Trading
- Book Imbalance - Bid/ask volume asymmetry
- Features serialized to
ndarraytensor
-
ML Inference
- ONNX model processes feature tensor (batch=1, seq_len=100, features=40)
- Mamba model returns directional predictions (up/flat/down) for multiple horizons
- Inference completes in <800ns (see README.md:228)
-
Strategy Decision
MarketMakerStrategycombines ML signal with inventory skew- Generates
Orderobjects with price/quantity/side - Orders validated by
RiskManager
Execution Flow (Strategy → Market)
-
Order Submission
- Strategy returns
Vec<Order>fromon_market_data() BacktestEngineschedulesOrderSubmitevent with latency- Latency determined by
LatencySimulator(default: 100μs)
- Strategy returns
-
Exchange Matching
SimulatedExchangeattempts to match orders against current book- Fill probability based on queue position model
- Partial fills supported for large orders
-
Fill Notification
OrderFillevent scheduled with notification latency- Strategy receives
on_fill()callback PositionTrackerupdates inventory and realized P&L
-
Risk Monitoring
RiskManagerchecks position limits, drawdown, daily loss- Kill switch triggered if breach detected
- Engine transitions to
EngineState::Stopped
Event Processing Model
TheBacktestEngine (nano-backtest/src/engine.rs:33) processes events in a deterministic loop:
- Timestamp (primary) - Earlier events processed first
- Sequence number (tiebreaker) - Preserves submission order
nano-backtest/src/events.rs:176 for ordering implementation.
Latency Budget
From README.md (lines 221-228), the latency budget for tick-to-trade:| Operation | Median | P95 | P99 |
|---|---|---|---|
| LOB Update | 45ns | 62ns | 78ns |
| Feature Extraction | 120ns | 145ns | 168ns |
| Model Inference | 580ns | 720ns | 890ns |
| Signal Generation | 35ns | - | - |
| Total | 780ns | 950ns | 1.2μs |
- Rust’s zero-cost abstractions
- SIMD-optimized numerical operations
- Lock-free data structures where possible
- ONNX Runtime with CPU-specific optimizations
Concurrency Model
Backtesting (Single-threaded)
Backtests run single-threaded for determinism:- All events processed sequentially
- No race conditions or non-deterministic behavior
- Reproducible results with same seed
Live Trading (Multi-threaded)
In live mode (nano-gateway), concurrency is managed via:- Market data thread - Receives UDP packets, updates order book
- Strategy thread - Processes book snapshots, generates signals
- Execution thread - Submits orders to FIX gateway
- Metrics thread - Exports Prometheus metrics
crossbeam-channel MPSC queues for low-latency message passing.
Configuration & Deployment
The system is configured via TOML files (see README.md:265):- Development - Local machine with synthetic data
- Backtesting - Cloud VM (AWS c6a.8xlarge recommended)
- Paper trading - CME test environment
- Production - Co-located server with kernel bypass networking
Monitoring & Observability
NanoARB exports metrics via:- Prometheus - Latency histograms, fill rates, P&L tracking
- Grafana - Real-time dashboards (see grafana/ directory)
- Tracing - Structured logging via
tracingcrate - SSE Stream - Real-time updates to web UI (http://localhost:9090/api/stream)
Next Steps
- Crates Reference - Detailed documentation of each crate
- Data Flow - Deep dive into data pipeline
- Strategy Development - Building custom strategies