Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/backtest-kit/backtest-kit-docs/llms.txt

Use this file to discover all available pages before exploring further.

Most trading strategies begin their life as a Jupyter notebook or a quick Python script — fast to write, impossible to deploy. Backtest Kit is the bridge between that prototype and a production system you can trust. It is a TypeScript framework for backtesting and live trading strategies on multi-asset, crypto, forex, or DEX markets with crash-safe persistence, signal validation, and AI optimization built in. Write your strategy once and run it identically in backtest mode against years of historical candles, then flip a single flag to go live — no rewrites, no glue code, no framework migrations when the business scales.

Why Backtest Kit?

Backtest Kit is best understood by what it replaces. The table below compares it against the tools most quants reach for first.
FeatureBacktest KitBacktraderVectorBTMetaTrader / MQL5QuantConnectFreqtrade
LanguageTypeScriptPythonPythonC++ / MQL5C#Python
Backtest → Live (same code)✅ (platform-locked)✅ (cloud-only)Partial
Crash-safe persistence✅ AtomicPartial
AI / LLM integration✅ Built-inLimited
Transactional broker commits
Type-safe signal lifecyclePartialPartial
Self-hosted
No platform fees
Multi-asset / DEX support✅ CCXTLimitedLimitedLimited✅ CCXT
Streaming large datasetsLimited
Think of it as open-source QuantConnect / MetaTrader without the vendor lock-in — pure TypeScript, self-hosted, with your code, your data, and your infrastructure.

Key Architectural Guarantees

Backtest Kit is not a data-processing library. It is a time execution engine — an async stream of virtual time where your strategy is evaluated step by step. Four architectural guarantees make that engine reliable in production.

Type-Safe State Machines

Every signal moves through a strict lifecycle enforced at compile time. TypeScript generics propagate signal types through schemas, validations, and commit functions, catching mismatches before the strategy ever runs.

Ambient Temporal Context

Backtest Kit uses Node.js AsyncLocalStorage to inject the current virtual time into every getCandles, getOrderBook, and getAggregatedTrades call automatically. Look-ahead bias is structurally impossible — all time boundaries are enforced without any manual synchronization.

Crash-Safe Persistence

Atomic persistence writes recover positions, schedules, and partial fills after a process crash. The engine resumes from the last consistent state, preventing duplicate fills, ghost positions, and unreported losses.

Transactional Broker Commits

The broker adapter intercepts every trade mutation before the internal position state changes. If the exchange rejects the order, the fill times out, or the network fails, the adapter throws and the mutation is skipped. Backtest Kit retries automatically on the next tick — the internal state never drifts from the exchange.

How It Works

The overall flow is three phases, and the same TypeScript file drives all three:
  1. Register schemas — call addExchangeSchema, addFrameSchema, addStrategySchema, and optionally addRiskSchema at the top level of your entry point. Schemas describe what data to fetch, what time window to replay, and how to generate signals.
  2. Run a backtest — point the CLI at your entry file with --backtest. The engine replays historical candles in virtual time, calls getSignal on each tick, validates signals against your risk schema, and writes a Markdown report with PNL, Sharpe Ratio, win rate, and more.
  3. Deploy live — change --backtest to --live. The same entry file, the same schemas, the same getSignal function — now driven by real-time candles from the exchange. Add a broker adapter module for transactional order placement and you have a production bot.
No rewrite. No language switch. No framework migration.

Supported Order Types

Backtest Kit calculates PnL, Peak Profit, and Max Drawdown for every entry across a comprehensive set of order types:
  • Market / Limit entries — open positions at market price or a specified limit
  • TP / SL / OCO exits — take-profit, stop-loss, and one-cancels-other exit pairs
  • Grid orders — automatically cancelled when conditions are not met
  • Partial profit / partial loss levels — scale out of a position in multiple tranches
  • Trailing take-profit / stop-loss — dynamic exit levels that follow price
  • Breakeven protection — move the stop-loss to entry price once a threshold is reached
  • Stop limit entries — trigger entry before OCO exits are placed
  • Dollar cost averaging (DCA) — add to a position at lower prices, with configurable acceptance rules
  • Time attack / Infinite hold — close positions after a fixed time window or hold indefinitely

Build docs developers (and LLMs) love