Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-kit-redis-mongo-docker/llms.txt

Use this file to discover all available pages before exploring further.

The backtest-kit library uses a small set of string enums to identify exchanges, backtesting frames, and strategies throughout the codebase. These values appear as components of composite Redis cache keys, Mongoose document filter fields, and adapter configuration objects. Alongside the enums, the library ships a set of generic ParseFormat utility types that enable structured, type-safe extraction of fields from free-form text — useful when parsing LLM outputs or loosely-structured API responses.

Enums

Three string enums — ExchangeName, FrameName, and StrategyName — provide compile-time safety for the string identifiers threaded through every service call.

ParseFormat types

A family of four generic utility types — ExtractConfig, FieldMapping, ExtractedData, and ParseFormat — for declarative regex-based field extraction with optional transforms and validation.

Enums

ExchangeName

ExchangeName identifies the exchange adapter used by the backtesting engine. The string value is embedded directly in Redis cache keys and Mongoose filter documents as the exchangeName field.
export enum ExchangeName {
    CCXT = "ccxt-exchange",
}
MemberString valueUsage
ExchangeName.CCXT"ccxt-exchange"The CCXT-based exchange adapter. Appears in cache keys such as signal_cache:ccxt-exchange:jan_2026_strategy:TRXUSDT.
Adding a new exchange: append a new member to the enum and ensure the corresponding adapter is registered in the IoC container before use.
export enum ExchangeName {
    CCXT = "ccxt-exchange",
    Binance = "binance-exchange",  // example — add your adapter alongside this
}

FrameName

FrameName identifies a backtesting time frame — a named window of historical data with defined start and end boundaries. Frame names appear in configuration objects that select which dataset a strategy runs against.
export enum FrameName {
    Jan2026Frame = "jan_2026_frame",
}
MemberString valueUsage
FrameName.Jan2026Frame"jan_2026_frame"The January 2026 backtesting dataset.
Adding a new frame: append a new member and create the corresponding dataset loader or configuration file that maps the frame name to its date range and data source.
export enum FrameName {
    Jan2026Frame = "jan_2026_frame",
    Feb2026Frame = "feb_2026_frame",  // example
}

StrategyName

StrategyName identifies a trading strategy implementation. The string value is used as the strategyName component of composite cache keys and Mongoose filter queries.
export enum StrategyName {
    Jan2026Strategy = "jan_2026_strategy",
}
MemberString valueUsage
StrategyName.Jan2026Strategy"jan_2026_strategy"The January 2026 strategy. Appears in cache keys such as signal_cache:ccxt-exchange:jan_2026_strategy:TRXUSDT.
Adding a new strategy: append a new member and register the strategy class in the strategy registry. The string value becomes part of every Redis key and MongoDB document written by that strategy, so choose a value that is stable and unique.
export enum StrategyName {
    Jan2026Strategy = "jan_2026_strategy",
    Feb2026Strategy = "feb_2026_strategy",  // example
}
Enum string values are written into MongoDB documents and Redis keys. Changing an existing enum value after data has been stored will orphan existing records — the old keys will no longer be found by findByContext or the cache lookup. Always treat enum string values as immutable once data is in production.

ParseFormat types

The ParseFormat family of types in src/model/ParseFormat.model.ts provides a declarative, type-safe API for extracting structured fields from free-form strings using regular expressions. It is particularly useful when processing LLM completions or API text responses that follow a semi-structured pattern but cannot be reliably parsed with a JSON schema.
export type ExtractConfig<T = string> = {
    pattern: RegExp;
    group?: number;
    transform?: (raw: string, match: RegExpMatchArray) => T;
    validate?: (value: T) => boolean;
    multi?: boolean;
    optional?: boolean;
};

export type FieldMapping = {
    [key: string]: RegExp | ExtractConfig<any>;
};

export type ExtractedData<M extends FieldMapping> = {
    [K in keyof M]: M[K] extends ExtractConfig<infer R>
        ? M[K] extends { multi: true } ? R[] : R
        : M[K] extends RegExp ? string : never;
};

export type ParseFormat<T> = {
    [K in keyof T]: RegExp | ExtractConfig<T[K] extends (infer U)[] ? U : T[K]>;
};

ExtractConfig<T>

ExtractConfig is the per-field extraction descriptor. It tells the parser how to find, transform, and validate a single field’s value within a larger string.
pattern
RegExp
required
The regular expression applied to the input string to locate this field’s value. This is the only required property.
group
number
The capture group index within pattern whose text is used as the raw value. Defaults to group 1 if omitted. Use 0 to capture the entire match.
transform
(raw: string, match: RegExpMatchArray) => T
An optional function that converts the raw captured string into the desired type T. Receives both the raw captured string and the full RegExpMatchArray so you can reference other groups during transformation.
validate
(value: T) => boolean
An optional predicate run after transform. If it returns false, the field is treated as unmatched. Use this to reject captures that match the pattern but fail a semantic check (e.g., a number that is out of range).
multi
boolean
When true, the parser collects all matches of pattern in the input string rather than stopping at the first match. The extracted field type becomes T[] instead of T. Reflected in ExtractedData via the conditional M[K] extends { multi: true } ? R[] : R.
optional
boolean
When true, a failure to match pattern is not treated as a parse error — the field is simply absent or undefined in the result. When false (the default), a missing match raises an error.

FieldMapping

FieldMapping is a plain record type where each key is a field name and each value is either a bare RegExp (shorthand for ExtractConfig with just a pattern) or a full ExtractConfig object.
export type FieldMapping = {
    [key: string]: RegExp | ExtractConfig<any>;
};
A bare RegExp value is equivalent to { pattern: theRegex } — it extracts the first capture group as a string with no transform, validation, or multi-match.

ExtractedData<M>

ExtractedData is a mapped type that derives the shape of the parsed result object from a FieldMapping. The conditional types preserve the correct output type for each field:
  • A field with a bare RegExp produces string.
  • A field with ExtractConfig<R> produces R.
  • A field with ExtractConfig<R> & { multi: true } produces R[].
export type ExtractedData<M extends FieldMapping> = {
    [K in keyof M]: M[K] extends ExtractConfig<infer R>
        ? M[K] extends { multi: true } ? R[] : R
        : M[K] extends RegExp ? string : never;
};

ParseFormat<T>

ParseFormat<T> is the inverse of ExtractedData — given a known output type T, it produces the type of the mapping object needed to parse it. This is useful when you want to define a parser that is statically typed to produce a known interface T.
export type ParseFormat<T> = {
    [K in keyof T]: RegExp | ExtractConfig<T[K] extends (infer U)[] ? U : T[K]>;
};
The conditional T[K] extends (infer U)[] ? U : T[K] unwraps array fields so that ExtractConfig is typed for the element type rather than the array type — the multi: true flag on the config is what produces the array in the output.

When to use ParseFormat

ParseFormat is most valuable when consuming LLM completions or semi-structured API text that follows a pattern but is not valid JSON. Define a ParseFormat<T> mapping once, then run it over any number of input strings to extract fully typed, validated result objects.
A minimal example:
import type { ParseFormat, ExtractedData } from "backtest-kit";

interface TradeSignal {
    symbol: string;
    price: number;
    tags: string[];
}

const format: ParseFormat<TradeSignal> = {
    symbol:  /Symbol:\s*([A-Z]+USDT)/,
    price: {
        pattern: /Price:\s*([\d.]+)/,
        transform: (raw) => parseFloat(raw),
        validate:  (v)   => v > 0,
    },
    tags: {
        pattern: /#(\w+)/g,
        multi: true,
    },
};
The ExtractedData<typeof format> type resolves to { symbol: string; price: number; tags: string[] }, matching TradeSignal exactly.

Build docs developers (and LLMs) love