Exchange adapters bridge backtest-kit with real market data sources. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/backtest-kit/backtest-kit-redis-mongo-docker/llms.txt
Use this file to discover all available pages before exploring further.
addExchangeSchema function registers an implementation for a named exchange that provides OHLCV candle data, order book snapshots, and price/quantity formatting. All three running modes — backtest, paper, and live — use the same adapter interface; the strategy code never references the exchange directly.
Exchange name enum
src/enum/ExchangeName.ts
"ccxt-exchange" is the identifier used in addExchangeSchema and when launching runs via Backtest.background, Paper.background, or Live.background.
Exchange singleton
All exchange methods share a singleccxt.binance instance created via singleshot (lazy, memoized):
modules/backtest.module.ts
| Option | Value | Effect |
|---|---|---|
defaultType | "spot" | Targets the Binance spot market |
adjustForTimeDifference | true | Auto-corrects clock skew between local and Binance servers |
recvWindow | 60000 | 60-second receive window for request validity |
enableRateLimit | true | Respects Binance API rate limits automatically |
addExchangeSchema registration
The schema is registered once per module file. The backtest, paper, and live modules share the same implementation:
modules/backtest.module.ts
setConfig({ CC_MAX_STOPLOSS_DISTANCE_PERCENT: 100 }) disables the default maximum stop-loss distance check that backtest-kit would otherwise enforce. Remove or adjust this if you want distance-based stop-loss constraints.Method reference
getCandles
Fetches OHLCV candles from Binance via ccxt’s fetchOHLCV.
Market symbol, e.g.
"TRXUSDT".Candle interval string:
"1m", "5m", "15m", "30m", "1h", "2h", "4h", "6h", "8h", "1d".Start timestamp for the candle range.
Number of candles to fetch.
{ timestamp, open, high, low, close, volume }[].
getOrderBook
Fetches the current order book from Binance. Throws in backtest mode.
{ symbol, asks: [{price, quantity}][], bids: [{price, quantity}][] }.
formatPrice
Rounds a price to the market’s tick size.
roundTicks (from backtest-kit) when a numeric tick size is available, falling back to ccxt’s priceToPrecision otherwise. Returns a string.
formatQuantity
Rounds a quantity to the market’s lot size step.
roundTicks when a numeric step size is available, falling back to ccxt’s amountToPrecision. Returns a string.
Module files
Themodules/ directory contains three separate files that each call addExchangeSchema:
| File | Used by mode |
|---|---|
modules/backtest.module.ts | Backtest entry point (src/main/backtest.ts) |
modules/live.module.ts | Live entry point (src/main/live.ts) |
modules/paper.module.ts | Paper entry point (src/main/paper.ts) |
All three module files currently share identical
addExchangeSchema implementations. Separate files exist so you can customize exchange behavior per mode — for example, adding API keys only in the live module.Registering a custom exchange
To connect to a different exchange or data source, replace theaddExchangeSchema call in the appropriate module file:
modules/backtest.module.ts
ExchangeName enum and all references in src/main/*.ts to match the new exchangeName string.