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.
addRiskSchema registers a named risk profile that gates signal acceptance before any position is opened. When a strategy references a riskName, Backtest Kit runs all validation functions in that profile against the incoming signal. Any validation that throws—or returns an IRiskRejectionResult—rejects the signal and emits a riskSubject event. Returning void or null from a validation approves the signal.
Multiple strategies can share the same risk profile, and a single strategy can reference multiple profiles via riskList. The ClientRisk instance tracking active positions is shared across all strategies that reference the same riskName, enabling cross-strategy portfolio-level limits.
Function Signature
Parameters
A unique string identifier for this risk profile. Referenced as
riskName in addStrategySchema and as riskList entries. Duplicate names throw at registration.Array of validation rules. Each entry is either:
- A plain function
(payload: IRiskValidationPayload) => RiskRejection | Promise<RiskRejection> - An object
{ validate: IRiskValidationFn, note?: string }with an optional description.
Optional developer note for documentation or introspection.
Optional lifecycle callbacks:
onRejected(symbol, params)— called when a signal is rejected.onAllowed(symbol, params)— called when a signal passes all validations.
IRiskValidationPayload — Validation Context
Each validation function receives this payload:Trading pair symbol (e.g.,
"BTCUSDT").The signal being evaluated. Includes
position, priceOpen, priceTakeProfit, priceStopLoss, minuteEstimatedTime, and cost. priceOpen is always present (Backtest Kit calculates the effective entry before running validations).The strategy requesting the position.
The exchange on which the signal will be executed.
The risk profile being evaluated.
The frame for backtest runs; empty string for live mode.
Current VWAP price at the moment of validation.
Unix timestamp in milliseconds of the current tick.
Total number of open positions tracked across all strategies sharing this risk profile. Use this to enforce portfolio-wide position limits.
Full list of currently active positions with
strategyName, exchangeName, symbol, position, priceOpen, priceStopLoss, priceTakeProfit, minuteEstimatedTime, and openTimestamp.Example — TP Distance and R/R Ratio Validations
Throwing an error inside a validation function is the recommended rejection pattern. The error message becomes the
rejectionNote on the emitted RiskContract event and is accessible via listenRisk. You can also return an IRiskRejectionResult object { id: string | null, note: string } for structured rejection data.