Overview
NanoARB’s trait-based architecture allows you to implement custom strategies, order books, risk managers, and other trading components. All traits are designed to be thread-safe (Send + Sync) for concurrent execution.
Strategy
Implement custom trading strategies.Definition
Required Methods
Strategy name for logging and metrics
Called on each market data update. Return orders to submit.
Called when an order is filled
Called when an order is acknowledged by the exchange
Called when an order is rejected
Called when an order is cancelled
Get current position (positive = long, negative = short)
Get current profit and loss
Check if strategy is ready to trade
Reset strategy state
When to Implement
Implement theStrategy trait to:
- Create custom algorithmic trading strategies
- Implement market making logic
- Build arbitrage strategies
- Develop ML-based trading systems
OrderBook
Access market depth and order book state.Definition
Required Methods
Get the best bid price and quantity
Get the best ask price and quantity
Get the mid price (average of best bid and ask)
Get the spread in ticks
Get the current quote (BBO)
Get price at a specific bid level (0 = best)
Get ask at a specific level (0 = best)
Get total quantity at bid levels up to depth
Get total quantity at ask levels up to depth
Get the current timestamp
When to Implement
Implement theOrderBook trait to:
- Create custom order book implementations
- Build order book aggregators across exchanges
- Implement synthetic order books for testing
- Create order book replay systems from historical data
FillModel
Simulate order fills for backtesting.Definition
Required Methods
try_fill
fn(&self, order: &Order, book: &dyn OrderBook, current_time: Timestamp) -> Option<(Price, Quantity)>
Simulate a fill attempt for an order. Returns fill price and quantity if filled.
Get probability of being filled at a given queue position
When to Implement
Implement theFillModel trait to:
- Create realistic fill simulations for backtesting
- Model queue position and adverse selection
- Simulate different market conditions
- Test strategies under various fill assumptions
RiskManager
Manage position and risk limits.Definition
Required Methods
Check if an order passes risk checks
Check if position limits are breached
Check if drawdown limits are breached
Check if we should kill all positions (emergency stop)
Get maximum allowed position
Get maximum allowed order size
When to Implement
Implement theRiskManager trait to:
- Enforce position and order size limits
- Implement custom risk rules
- Create dynamic risk management based on market conditions
- Add compliance checks
ExecutionHandler
Handle order submission and management.Definition
When to Implement
Implement theExecutionHandler trait to:
- Connect to exchange APIs
- Create paper trading simulators
- Build order routing systems
- Implement order management systems (OMS)
LatencyModel
Model network latency for backtesting.Definition
When to Implement
Implement theLatencyModel trait to:
- Simulate network latency in backtests
- Test strategy sensitivity to latency
- Model different network conditions
- Create realistic simulation environments
FeeModel
Calculate trading fees.Definition
When to Implement
Implement theFeeModel trait to:
- Model exchange-specific fee structures
- Account for maker/taker fees
- Implement tiered fee schedules
- Calculate fee rebates
ModelInference
Run machine learning model inference.Definition
When to Implement
Implement theModelInference trait to:
- Integrate ML models into strategies
- Run real-time predictions
- Benchmark model latency
- A/B test different models
MetricsCollector
Collect performance and operational metrics.Definition
When to Implement
Implement theMetricsCollector trait to:
- Export metrics to monitoring systems (Prometheus, DataDog)
- Log performance data
- Track strategy metrics
- Monitor system health