Skip to main content

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

name
fn(&self) -> &str
Strategy name for logging and metrics
on_market_data
fn(&mut self, book: &dyn OrderBook) -> Vec<Order>
Called on each market data update. Return orders to submit.
on_fill
fn(&mut self, fill: &Fill)
Called when an order is filled
on_order_ack
fn(&mut self, order_id: OrderId)
Called when an order is acknowledged by the exchange
on_order_reject
fn(&mut self, order_id: OrderId, reason: &str)
Called when an order is rejected
on_order_cancel
fn(&mut self, order_id: OrderId)
Called when an order is cancelled
position
fn(&self) -> i64
Get current position (positive = long, negative = short)
pnl
fn(&self) -> f64
Get current profit and loss
is_ready
fn(&self) -> bool
Check if strategy is ready to trade
reset
fn(&mut self)
Reset strategy state

When to Implement

Implement the Strategy 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

best_bid
fn(&self) -> Option<(Price, Quantity)>
Get the best bid price and quantity
best_ask
fn(&self) -> Option<(Price, Quantity)>
Get the best ask price and quantity
mid_price
fn(&self) -> Option<Price>
Get the mid price (average of best bid and ask)
spread
fn(&self) -> Option<Price>
Get the spread in ticks
quote
fn(&self) -> Option<Quote>
Get the current quote (BBO)
bid_at_level
fn(&self, level: usize) -> Option<(Price, Quantity)>
Get price at a specific bid level (0 = best)
ask_at_level
fn(&self, level: usize) -> Option<(Price, Quantity)>
Get ask at a specific level (0 = best)
bid_depth
fn(&self, levels: usize) -> Quantity
Get total quantity at bid levels up to depth
ask_depth
fn(&self, levels: usize) -> Quantity
Get total quantity at ask levels up to depth
timestamp
fn(&self) -> Timestamp
Get the current timestamp

When to Implement

Implement the OrderBook 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.
fill_probability
fn(&self, queue_position: usize, level_quantity: Quantity) -> f64
Get probability of being filled at a given queue position

When to Implement

Implement the FillModel 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_order
fn(&self, order: &Order, current_position: i64) -> Result<(), Error>
Check if an order passes risk checks
check_position
fn(&self, position: i64) -> Result<(), Error>
Check if position limits are breached
check_drawdown
fn(&self, pnl: f64, peak_pnl: f64) -> Result<(), Error>
Check if drawdown limits are breached
should_kill_switch
fn(&self, pnl: f64, position: i64) -> bool
Check if we should kill all positions (emergency stop)
max_position
fn(&self) -> i64
Get maximum allowed position
max_order_size
fn(&self) -> u32
Get maximum allowed order size

When to Implement

Implement the RiskManager 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 the ExecutionHandler 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 the LatencyModel 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 the FeeModel 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 the ModelInference 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 the MetricsCollector trait to:
  • Export metrics to monitoring systems (Prometheus, DataDog)
  • Log performance data
  • Track strategy metrics
  • Monitor system health