The exchange schema tells backtest-kit how to fetch OHLCV candles, order book data, and aggregated trades, and how to format prices and quantities for a specific exchange. It is the bridge between backtest-kit’s internal tick engine and anyDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-monorepo-parallel/llms.txt
Use this file to discover all available pages before exploring further.
ccxt-compatible exchange. In this monorepo the schema lives in content/apr_2026.strategy/modules/backtest.module.ts alongside the frame schema.
Global Configuration
Before registering the exchange schema,setConfig applies two global backtest-kit parameters:
| Option | Value | Effect |
|---|---|---|
CC_MAX_STOPLOSS_DISTANCE_PERCENT | 100 | Allows stop-loss levels up to 100% away from entry — effectively disables the distance guard |
CC_BREAKEVEN_THRESHOLD | 0 | Disables the automatic breakeven move — the stop-loss stays at the level set by Position.moonbag() |
The singleshot Exchange Factory
Creating accxt.binance instance and loading its market data is expensive. The singleshot utility from functools-kit wraps the factory so it runs exactly once and returns the cached instance on every subsequent call:
The
singleshot() pattern from functools-kit ensures the ccxt exchange is initialized exactly once and reused across all symbols. With 9 symbols running in parallel, this avoids 9 redundant loadMarkets() round-trips on start-up.addExchangeSchema
exchangeName is the string key used to link this adapter to a frame schema and to Backtest.background(). It must match the value passed to cacheCandles() and Backtest.background({ exchangeName }).
Method Reference
getCandles(symbol, interval, since, limit)
getCandles(symbol, interval, since, limit)
Fetches OHLCV candles from the exchange and maps them to the shape backtest-kit expects.
since is a Date — call .getTime() to convert to the Unix millisecond integer that ccxt.fetchOHLCV expects. The return type is an array of { timestamp, open, high, low, close, volume }.getOrderBook(symbol, depth, from, to, backtest)
getOrderBook(symbol, depth, from, to, backtest)
Returns the current order book. The
backtest flag is true during replay; historical order book snapshots are not available from ccxt, so this implementation throws in that mode.getAggregatedTrades(symbol, from, to)
getAggregatedTrades(symbol, from, to)
Fetches Binance aggregated trade data via the
publicGetAggTrades endpoint. Each record represents a batch of trades executed at the same price in the same direction.| Field | Binance key | Description |
|---|---|---|
id | t.a | Aggregate trade ID |
price | t.p | Execution price |
qty | t.q | Quantity |
timestamp | t.T | Trade time (Unix ms) |
isBuyerMaker | t.m | true if the buyer was the market maker |
formatPrice(symbol, price)
formatPrice(symbol, price)
Rounds a raw price to the exchange’s tick size using
roundTicks() from backtest-kit. Falls back to ccxt’s built-in priceToPrecision if the market’s tick size is unavailable.roundTicks(price, tickSize) snaps price to the nearest multiple of tickSize, matching the exchange’s accepted precision.formatQuantity(symbol, quantity)
formatQuantity(symbol, quantity)
Rounds a raw quantity to the exchange’s step size using
roundTicks(). Falls back to ccxt’s amountToPrecision if the step size is absent.Complete Module File
The fullbacktest.module.ts registers both the exchange schema and the frame schema in a single file: