Skip to main content

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.

setConfig lets you override any subset of Backtest Kit’s global execution parameters before starting backtests or live sessions. All parameters have validated defaults; calling setConfig with a partial object merges your overrides into the current configuration without resetting unspecified fields.

setConfig

setConfig(config: Partial<GlobalConfig>, _unsafe?: boolean): void
config
Partial<GlobalConfig>
required
Partial configuration object. Only the keys you provide are updated; all other settings remain unchanged.
_unsafe
boolean
Skip configuration validation checks. Intended for internal testing and testbed environments only.
Never use _unsafe = true in production code. Bypassing validation can lead to unprofitable signal configurations that pass TP/SL checks but are guaranteed to lose after fees and slippage.

getConfig

Returns a shallow copy of the current global configuration. Use for inspection without risking accidental mutations.
getConfig(): GlobalConfig

getDefaultConfig

Returns a read-only reference to the original default configuration. Use to reset a specific field or compare current values against defaults.
getDefaultConfig(): Readonly<GlobalConfig>

Configuration Options

CC_PERCENT_SLIPPAGE
number
default:"0.1"
Percentage slippage applied once on entry and once on exit (two transactions total). Simulates market impact and order book depth. 0.1 = 0.1% per transaction.
CC_PERCENT_FEE
number
default:"0.1"
Exchange fee percentage per transaction. Applied twice for entry + exit. 0.1 = 0.1% per transaction (0.2% round-trip).
CC_SCHEDULE_AWAIT_MINUTES
number
default:"120"
Maximum minutes a scheduled signal waits for price to reach priceOpen before being auto-cancelled with reason: "timeout". Set to Infinity to disable timeouts.
CC_AVG_PRICE_CANDLES_COUNT
number
default:"5"
Number of 1-minute candles used to compute VWAP in getAveragePrice. Higher values produce smoother prices but add latency to the price signal.
CC_ORDER_BOOK_TIME_OFFSET_MINUTES
number
default:"10"
Window size in minutes for order book time-range alignment. Controls how from and to are computed for getOrderBook requests.
CC_ORDER_BOOK_MAX_DEPTH_LEVELS
number
default:"20"
Default number of price levels requested from each side (bids and asks) when depth is not explicitly passed to getOrderBook.
CC_AGGREGATED_TRADES_MAX_MINUTES
number
Maximum minutes per aggregated trades window. Dictates the [from, to] span for getAggregatedTrades and each pagination chunk. Required by exchanges like Binance that cap the time range per request.
CC_MIN_TAKEPROFIT_DISTANCE_PERCENT
number
default:"0.5"
Minimum distance between priceOpen and priceTakeProfit as a percentage. Must exceed total round-trip costs (slippage + fees) to ensure profitable trades. The framework rejects signals that fail this check.
CC_MIN_STOPLOSS_DISTANCE_PERCENT
number
default:"0.5"
Minimum distance between priceOpen and priceStopLoss. Prevents signals from being stopped out immediately by normal market noise.
CC_MAX_STOPLOSS_DISTANCE_PERCENT
number
default:"20"
Maximum stop-loss distance. Prevents catastrophically wide SL levels that would expose the full position to excessive loss.
CC_POSITION_ENTRY_COST
number
default:"100"
Default dollar cost for each position entry (ISignalDto.cost default and each DCA entry via commitAverageBuy).
CC_ENABLE_DCA_EVERYWHERE
boolean
default:"false"
When true, commitAverageBuy is accepted even if currentPrice is not a new all-time low entry price — only requires price to be below priceOpen. Allows averaging even after price has rebounded.
CC_BREAKEVEN_THRESHOLD
number
default:"0.2"
Additional profit buffer required beyond round-trip costs before breakeven can be set. Adds a safety margin: threshold = (CC_PERCENT_SLIPPAGE + CC_PERCENT_FEE) * 2 + CC_BREAKEVEN_THRESHOLD.

Example

import { setConfig, setLogger } from 'backtest-kit';

setLogger({
  log: console.log,
  debug: console.debug,
  info: console.info,
  warn: console.warn,
});

setConfig({
  CC_PERCENT_SLIPPAGE: 0.05,         // tighter exchange
  CC_PERCENT_FEE: 0.075,             // maker/taker rebate tier
  CC_SCHEDULE_AWAIT_MINUTES: 60,     // 1-hour pending timeout
  CC_AVG_PRICE_CANDLES_COUNT: 3,     // faster VWAP response
  CC_ORDER_BOOK_TIME_OFFSET_MINUTES: 5,
  CC_ORDER_BOOK_MAX_DEPTH_LEVELS: 50,
  CC_AGGREGATED_TRADES_MAX_MINUTES: 120,
  CC_POSITION_ENTRY_COST: 200,       // $200 per DCA unit
});

// Inspect the result
const cfg = getConfig();
console.log('Slippage:', cfg.CC_PERCENT_SLIPPAGE);
console.log('Fee:', cfg.CC_PERCENT_FEE);
Call setConfig before registering any schemas (addExchangeSchema, addStrategySchema) for the configuration to take effect for all framework services.

Build docs developers (and LLMs) love