Skip to main content

Overview

The execution pipeline converts strategy graph outputs into actual trades. It operates identically in backtest, paper, and live modes — only the fill engine changes.

The Three Stages

Stage 1: Intention

An intention declares where you want to be, not what to buy or sell:
Target-position trading: You declare “I want to be 30% long BTC” — the pipeline figures out the orders to get there. Intention types:

Stage 2: Delta Calculation

The executor computes the delta between current position and target position:
The delta is computed automatically — the strategy only needs to declare target positions.

Stage 3: Order Execution and Fill

The delta is converted to an order and executed by the fill engine:

Order Types

TimeInForce options: GTC (Good Till Cancel), IOC (Immediate or Cancel), FOK (Fill or Kill), POST_ONLY

Execution Modes: INSTANT vs LATENT

INSTANT mode

Orders fill at the current bar’s close price with BPS-based slippage:
Best for: Initial strategy validation, fast iteration.

LATENT mode

Orders fill against a simulated orderbook with depth-dependent slippage:
Best for: Realistic execution modeling, capacity testing.

TradingDriver: The Orchestrator

The TradingDriver manages the complete lifecycle:

What from_spec() does

  1. Expands specs — Resolves SymbolSourceMap, ObservationSpecs, AccountSpecs
  2. Computes warmup — Traces graph backward to find minimum ticks needed
  3. Creates TradingState — Initializes cash, positions, margin for each account
  4. Creates executorBacktestFactory for backtest/paper, LiveFactory for live
  5. Loads data — Parquet for historical, WebSocket for live
  6. Auto-injects funding — Adds FundingRateSpec for futures accounts

What each tick does

TickResult

Each iteration yields a TickResult:

Post-analysis

TradingState

The executor maintains portfolio state as TradingState, exposed to the graph as STATE: inputs: State updates after every fill:

Cost Application

Fee calculation

Fee rates are resolved through a 3-level priority chain:
  1. User override in CostModelSpec
  2. Auto-fetched from exchange via CCXT
  3. Fallback defaults (0.02% maker, 0.05% taker)

Slippage

INSTANT mode: BPS-based
LATENT mode: Orderbook-based (depth-dependent, realistic)

Funding rates

For futures positions, funding is applied at settlement ticks (every 8 hours for most exchanges):
Positive rate + long position → you pay. Negative rate + long position → you receive. See Funding Rate Simulation for details.

Liquidation

After every fill, the executor checks margin ratio:
If triggered, all positions are closed and a liquidation fee is applied. See Liquidation Logic for per-exchange formulas.

Safety Features (Live Mode)

Execution Mode Differences

TP/SL in Backtest

Take-profit and stop-loss orders are simulated with OHLC-aware logic:

Cost Models

Fee resolution, slippage, and VIP overrides

Liquidation Logic

Per-exchange margin and liquidation formulas

TradingSpec

Complete configuration hierarchy

Code Parity

Why the same pipeline runs in all modes