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.
addExchangeSchema connects Backtest Kit to a market data source. The exchange adapter is the single point of contact for all price data consumed by strategies: VWAP calculation, candle history, order book snapshots, and aggregated trade streams. Once registered, the exchange is referenced by name in every Backtest.run, Live.run, and Walker.run context. The adapter can wrap any data provider—CCXT, a proprietary REST API, or a local database.
Function Signature
Parameters
A unique string identifier for this exchange. Used as the routing key in execution contexts. Duplicate names throw at registration.
The primary data-fetching function. Backtest Kit calls it with exact parameters derived from the execution context timestamp.Adapter contract:
sinceis always aligned to an interval boundary (e.g.,00:15:00for 15m).- The first returned candle’s
timestampmust equalsince. - The adapter must return exactly
limitcandles. - Sequential timestamps:
since + i * stepMsfori = 0 .. limit-1.
Formats a raw price number to the exchange’s required precision string. Used when formatting signals for display and reports. Defaults to Bitcoin/USDT precision on Binance (2 decimal places).
Formats a raw quantity to the exchange’s lot-size precision. Defaults to Bitcoin precision (8 decimal places).
Optional. Fetches an order book snapshot. In backtest mode the
from/to window (derived from CC_ORDER_BOOK_TIME_OFFSET_MINUTES) allows serving historical snapshots. In live mode the implementation typically ignores from/to and calls the exchange’s current depth endpoint. Throws if called when not implemented.Optional. Fetches aggregated trade data for the given time window. Backtest Kit aligns
to to the nearest 1-minute boundary to prevent look-ahead bias. Throws if called when not implemented.Optional developer note for documentation or introspection.
Optional lifecycle callbacks:
onCandleData(symbol, interval, since, limit, data)— called after every successfulgetCandlesfetch. Useful for logging or caching raw API responses.
ICandleData — Candle Format
Unix timestamp in milliseconds of the candle’s open time (
openTime). This is the candle boundary, not the close time.Opening price at candle start.
Highest price during the candle period.
Lowest price during the candle period.
Closing price at candle end.
Trading volume during the candle period.
Adapter Contract
ThegetCandles implementation must satisfy these invariants for the framework to work correctly:
- Timestamp alignment:
sinceis always aligned down to the interval boundary before being passed to the adapter. The adapter must begin the response at exactly that timestamp. - Exact count: The adapter must return exactly
limitcandles. Fewer candles will cause assertion errors; more will be silently sliced. - No pending candles: The last candle in the response must be fully closed. Backtest Kit never requests the currently open candle.
- Sequential timestamps: Each candle in the result must have
timestamp = since + i * stepMs.
Example — CCXT Binance Adapter
In backtest mode Backtest Kit caches candle data automatically via
PersistCandleAdapter. The adapter’s getCandles is only called on cache miss, so you will not exceed exchange rate limits during large backtests as long as the candle cache is warm (see cacheCandles / warmCandles).