Skip to main content

Overview

The Autonome simulator provides a complete trading environment that mirrors live exchange behavior without risking real capital. It simulates order execution, position management, margin calculations, and portfolio tracking using real-time market data.

Environment Configuration

Configure the simulator through environment variables in your .env file:
.env

Configuration Options

enum
required
Controls whether the application uses simulated or live trading.
  • simulated - Uses ExchangeSimulator (default, recommended for development)
  • live - Connects to actual exchange via Lighter API
number
default:"10000"
Starting portfolio value in quote currency. This capital is available for margin allocation across positions.
string
default:"USDT"
Quote currency used for all valuations and P&L calculations.
number
default:"10000"
Interval in milliseconds for refreshing market data and checking exit plan triggers. Lower values increase price accuracy but consume more API resources.

Initialization

Bootstrap Process

The simulator is initialized automatically during server startup through the scheduler bootstrap:
src/server/schedulers/bootstrap.ts
The bootstrap method ensures singleton behavior - subsequent calls return the existing instance:
src/server/features/simulator/exchangeSimulator.ts

Initialization Steps

During initialization, the simulator:
  1. Loads market metadata - Initializes MarketState for each symbol in MARKETS configuration
  2. Refreshes order books - Fetches initial prices from Lighter API /api/v1/orderBooks endpoint
  3. Rehydrates positions - Restores open positions from the Orders database table
  4. Starts polling - Begins periodic market data refresh and exit plan monitoring
src/server/features/simulator/exchangeSimulator.ts

Position Rehydration

The simulator restores open positions from the database on startup to maintain state across server restarts:
src/server/features/simulator/exchangeSimulator.ts
The Orders table serves as the single source of truth for positions. The simulator state is derived from this table on startup.

Switching Between Modes

Simulated Mode (Default)

Recommended for development, testing, and AI agent training:
.env
Characteristics:
  • Zero risk to real capital
  • Instant execution with simulated slippage
  • Order book depth from real exchange data
  • Exit plans (stop-loss/take-profit) automatically executed
  • Full position and margin tracking

Live Mode

Connects to actual Lighter exchange:
.env
Live mode executes real trades with real capital. Ensure proper risk management and thoroughly test strategies in simulated mode first.

Runtime Detection

The trading layer automatically detects the mode:
src/env.ts
src/server/features/trading/createPosition.ts

Resetting the Simulator

Reset an account to initial capital and clear all positions:

Reset Implementation

src/server/features/simulator/exchangeSimulator.ts
Resetting an account only affects in-memory simulator state. To fully reset, also clear open orders from the database.

Market Data Refresh

The simulator polls market data at the configured interval:
src/server/features/simulator/exchangeSimulator.ts

Price Data Sources

Market data is fetched from Lighter API in priority order:
  1. Order books endpoint - /api/v1/orderBooks (primary)
  2. Candles endpoint - /api/v1/candles with 1-minute resolution (fallback)
src/server/features/simulator/market.ts

Next Steps

Simulator Features

Learn about order execution, portfolio tracking, and position management

Simulator API

API reference for simulator operations