Skip to main content

What is TradingSpec?

TradingSpec is the single configuration object that completely defines a trading system — what data to use, what strategy to run, and how to execute orders. In notebook development, mode is always "backtest". Paper and live trading run on the platform after you submit your strategy — the same graph runs identically in all modes.

Hierarchy Overview

TradingDataSpec

Defines what data the system consumes.

SymbolSourceMap

Maps exchanges to symbols, creating the axis keys used throughout the system:
Key properties: Key methods:

OHLCVSpec

Currently the primary data source:
exchange and market_type can be lists — the driver expands them into concrete specs:

TradingStrategySpec

Wraps the StatefulGraph with metadata:

TradingExecutionSpec

Defines how trades are executed:
mode is a top-level field on TradingSpec, not on TradingExecutionSpec. In notebook development, always set mode="backtest" directly on TradingSpec.

AccountSpec

Each exchange account is defined separately:
key property: Returns "{exchange}:{market_type}" (e.g., "binance:futures")

CostModelSpec

Override trading fees per account:
If not specified, fees are auto-fetched from the exchange via CCXT. Zero-cost backtest:

Execution Modes

Backtest

  • Uses historical data from start to end
  • Simulated execution with CostModelSpec fees
  • initial_cash required per account
  • No API credentials needed
  • The only mode used in notebook cells

Paper

  • Uses live/current data from the exchange
  • Simulated execution (no real orders placed)
  • initial_cash optional (defaults to 10000.0)
  • No API credentials needed
Paper trading is managed through the dashboard after strategy submission. It cannot be run from notebook cells.

Live

  • Uses live data from exchange APIs
  • Real order execution
  • Requires API credentials
  • initial_cash is optional — if set, it acts as a capital cap (actual balance must be >= initial_cash)
Live trading is managed through the dashboard after strategy submission. It cannot be run from notebook cells.

Supported Exchanges

Validation

TradingSpec.validate() enforces:
  1. Mode must be explicitly set ("backtest", "paper", or "live")
  2. Strategy.graph must not be None
  3. Observations must not be empty
  4. Live mode: accounts must have credentials, initial_cash is optional (capital cap if set)
  5. Backtest mode: accounts need observation data at system clock resolution
AccountSpec.__post_init__() validates:
  • base_currency is uppercase 3-4 letters
  • exchange:market_type is a valid combination
  • base_currency is supported by the exchange/market_type
  • max_leverage doesn’t exceed venue maximum
SymbolSourceMap.validate_base_currencies():
  • Symbol quote currencies must match account base currencies
  • Prevents PnL calculation errors (e.g., USD vs USDT mismatch)

Complete Example

Going to Paper or Live

Paper and live trading are not configured from notebook cells. After backtesting your strategy:
  1. Submit your strategy via the dashboard
  2. The platform validates and re-runs your backtest for independent verification
  3. Start a Paper or Live run from the dashboard — the same StatefulGraph runs without any code changes
See Backtest to Live for the full deployment lifecycle.

Multi-Exchange Example

Each account creates its own STATE namespace (STATE:binance:futures:*, STATE:gateio:futures:*), enabling venue-specific equity tracking and order execution.

Common Mistakes

Mismatched base_currency

Missing observation for account

initial_cash in live mode

Relationship to Other Concepts