Backtest Kit is a production-ready TypeScript framework for building algorithmic trading systems that work identically in backtesting and live execution. Instead of maintaining separate codebases for research and production, you register your exchange adapter, risk rules, and signal logic once — then replay them against historical candle data or deploy them against a real exchange without changing a single line of strategy code.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-kit/llms.txt
Use this file to discover all available pages before exploring further.
Why Choose Backtest Kit
One Codebase, Two Modes
The same
getSignal function runs unchanged in both backtest and live mode. The engine handles time context, candle alignment, and VWAP pricing automatically using AsyncLocalStorage.Crash-Safe Persistence
Atomic file writes recover signal state after process crashes. Live bots restart and resume monitoring open positions without duplicates or missed exits.
Built-in Validation
Every signal is validated for TP/SL logic, minimum price distance, and risk/reward ratios before it can open a position. Invalid signals are skipped silently.
Streaming Architecture
Both
Backtest.run() and Live.run() return async generators. Results stream one at a time — no array accumulation, no memory pressure on long backtests.AI Integration
The
getSignal function is async and can call any LLM (Ollama, OpenAI, Claude, DeepSeek) for signal generation. Multi-timeframe candle data is available without look-ahead bias.Rich Reports & Metrics
Automatic Markdown reports include PNL, Sharpe Ratio, Sortino Ratio, Calmar Ratio, win rate, max drawdown, and annualized expected returns.
Custom Risk Rules
Define portfolio-level guards — maximum open positions, minimum R/R ratios, time-window restrictions — as plain TypeScript functions in
addRiskSchema.Transactional Broker
The
Broker adapter intercepts every exchange mutation before internal state changes. If the exchange rejects an order, the position state rolls back atomically.Supported Order Types
Backtest Kit tracks PNL, Peak Profit, and Max Drawdown for each of the following entry and exit patterns:- Market / Limit entries — open immediately at VWAP or wait for price to reach a specified level
- TP / SL / OCO exits — standard take-profit and stop-loss with one-cancels-other semantics
- Grid with auto-cancel — grid entries that cancel themselves when the signal closes
- Partial profit / partial loss — close a percentage of the position at a profit or loss level
- Trailing stop-loss — shift the SL distance toward the entry as price moves in your favour
- Breakeven protection — move SL to entry price once transaction costs are covered
- Stop limit entries — place a limit order that only activates after a trigger price is reached
- Dollar-cost averaging (DCA) — add averaging entries at lower prices; each entry is formatted as a fixed unit of cost (default
$100) - Time attack / Infinite hold — expire a signal after
minuteEstimatedTimeminutes or setInfinityfor no timeout
Get Started
Quickstart
Install Backtest Kit, register all four schemas, and run your first backtest in under five minutes.
Core Concepts
Understand the time execution engine, schema registry pattern, signal lifecycle, and VWAP pricing.
Schema Reference
Full reference for
addExchangeSchema, addFrameSchema, addRiskSchema, and addStrategySchema.Live Trading
Switch from backtesting to live execution with
Live.background() — same code, different class.