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.

By default Backtest Kit suppresses all internal log output. Call setLogger once at startup — before registering schemas — to route framework messages to console, a structured logger like pino or winston, or any custom sink. The ILogger interface is intentionally minimal: four methods that accept a topic string followed by variadic arguments.

setLogger

setLogger(logger: ILogger): void
logger
ILogger
required
An object implementing the ILogger interface. All four methods are required; use no-op functions to silence specific levels.
Call this before any schema registration for complete log coverage, including initialization messages from addExchangeSchema, addStrategySchema, and related functions.

ILogger Interface

interface ILogger {
  log(topic: string, ...args: any[]): void;
  debug(topic: string, ...args: any[]): void;
  info(topic: string, ...args: any[]): void;
  warn(topic: string, ...args: any[]): void;
}
log
(topic: string, ...args: any[]) => void
required
General-purpose messages: significant lifecycle events, strategy ticks, signal state changes.
debug
(topic: string, ...args: any[]) => void
required
Detailed diagnostic output: intermediate states during candle fetches, indicator calculations, DI service routing.
info
(topic: string, ...args: any[]) => void
required
Informational summaries: successful completions, schema validations, cache hits/misses.
warn
(topic: string, ...args: any[]) => void
required
Potentially problematic situations: deprecated usage, missing optional configuration, unexpected conditions that do not stop execution.

Examples

Using console

The simplest approach — route everything to the standard Node.js console:
import { setLogger } from 'backtest-kit';

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

Silent (no logging)

Pass no-op functions to suppress all output:
import { setLogger } from 'backtest-kit';

const noop = () => {};
setLogger({ log: noop, debug: noop, info: noop, warn: noop });

Production-only logging (warn + info only)

Suppress verbose debug/log output in production:
import { setLogger } from 'backtest-kit';

setLogger({
  log: () => {},           // suppress verbose tick logs
  debug: () => {},         // suppress debug output
  info: console.info,      // keep informational summaries
  warn: console.warn,      // always show warnings
});

Using pino

import pino from 'pino';
import { setLogger } from 'backtest-kit';

const logger = pino({ level: 'info' });

setLogger({
  log: (topic, ...args) => logger.info({ topic }, ...args),
  debug: (topic, ...args) => logger.debug({ topic }, ...args),
  info: (topic, ...args) => logger.info({ topic }, ...args),
  warn: (topic, ...args) => logger.warn({ topic }, ...args),
});

Additional Startup Utilities

getBacktestTimeframe

Retrieve the current backtest timeframe for a given symbol — the array of Date objects representing every tick timestamp in the active frame. Throws if called outside of a backtest execution context.
getBacktestTimeframe(symbol: string): Promise<Date[]>
symbol
string
required
Trading pair symbol (e.g., "BTCUSDT").
import { getBacktestTimeframe } from 'backtest-kit';

const timeframe = await getBacktestTimeframe('BTCUSDT');
console.log(`Total ticks: ${timeframe.length}`);
console.log(`Start: ${timeframe[0].toISOString()}`);
console.log(`End:   ${timeframe[timeframe.length - 1].toISOString()}`);

waitForReady

Block until all required schema registries are populated. Useful when schemas are registered asynchronously (lazy imports, remote config, plugin loading).
waitForReady(isBacktest?: boolean): Promise<void>
isBacktest
boolean
default:"true"
When true (default), waits for exchange, frame, and strategy schemas to be registered. When false (live mode), only exchange and strategy schemas are required — frames are unused in live mode.
Polls every second for up to a framework-defined maximum timeout. Returns silently if the timeout elapses — the subsequent Backtest.run / Live.run call will surface a clearer error.
import { waitForReady, Backtest } from 'backtest-kit';

import './schemas/exchange';
import './schemas/strategy';
import './schemas/frame';

await waitForReady();
Backtest.background('BTCUSDT', { strategyName, exchangeName, frameName });

stopStrategy

Gracefully stop a live strategy from generating new signals without force-closing any currently open position. The existing signal continues to monitor TP/SL until natural closure.
stopStrategy(symbol: string): Promise<void>
symbol
string
required
Trading pair symbol to stop signal generation for.

shutdown

Emit a shutdown signal to all components listening to shutdownEmitter. Use in SIGINT / SIGTERM handlers for graceful process exit.
shutdown(): void
process.on('SIGINT', () => {
  shutdown();
  process.exit(0);
});

Build docs developers (and LLMs) love