Skip to content

Trading Strategies

All strategies are hosted in engine/strategies/ and run inside a single NautilusTrader TradingNode.

MeanReversionStrategy

File: engine/strategies/strategies_binance.py
Strategy ID: mean_reversion

EMA crossover on 1-minute Binance kline bars.

Logic

  1. Subscribe to BTCUSDT.BINANCE-1-MINUTE-LAST-EXTERNAL bars
  2. Maintain a fast EMA (3 bars) and slow EMA (8 bars)
  3. On each bar: if fast crosses above slow → BUY; crosses below → SELL
  4. Orders are LIMIT IOC at current mid price
  5. Cancel all open orders before placing a new one (cancel-and-replace)
  6. Max 1 open order at a time

Configuration

class MeanReversionConfig(StrategyConfig):
    order_qty: float = 0.002       # BTC per order
    fast_period: int = 3           # fast EMA bars
    slow_period: int = 8           # slow EMA bars
    max_open_orders: int = 1
    strategy_id: str = "mean_reversion"

Emitted Metrics

Metric Type Description
strategy_latency_us gauge Time from signal to submit_order() in microseconds
order_ack_rtt_us gauge Round-trip time to OrderAccepted event
fill_report_lag_us gauge Lag between fill event and report (ts_init - ts_event)
trade_pnl_usdt gauge Per-trade realized PnL in USDT

HourlyBuyStrategy

File: engine/strategies/strategies_binance.py
Strategy ID: hourly_buy

Time-based DCA strategy that buys at each whole UTC hour.

Logic

  1. Subscribe to BTCUSDT.BINANCE quote ticks for mid-price tracking
  2. Fire a recurring timer every check_interval_secs (default: 60s)
  3. At the first minute of hour n, place a MARKET BUY for n BTC
  4. Hour 0 (midnight) triggers a 1 BTC buy; hour 23 triggers a 24 BTC buy

Configuration

class HourlyBuyConfig(StrategyConfig):
    instrument_id: str = "BTCUSDT.BINANCE"
    strategy_id: str = "hourly_buy"
    check_interval_secs: int = 60

Emitted Metrics

Metric Type Description
strategy_latency_us gauge Time from timer callback to order submission
order_ack_rtt_us gauge Round-trip time to OrderAccepted
fill_report_lag_us gauge Fill report delivery lag
trade_pnl_usdt gauge Per-fill incremental PnL vs previous fill price

Latency Strategies

File: engine/strategies/strategies_latency.py

Three additional strategies instrumented specifically for latency benchmarking across different order types and market conditions. They follow the same metric-emission pattern as the strategies above.


Database Integration

All strategies use db/strategy_startup.py:resolve_strategy() on on_start() to find-or-create their Strategy row in PostgreSQL. The DatabaseActor persists fills, orders, signals, and audit events asynchronously.