This page documents the global configuration system for backtest-kit, including the GLOBAL_CONFIG object, the setConfig() function, and all runtime configuration parameters that control validation rules and timing constraints across the framework.
For detailed information about specific parameter categories, see:
The framework uses a singleton GLOBAL_CONFIG object to store runtime parameters that affect signal validation, scheduling behavior, risk management, and exchange data retrieval. This object is defined in src/config/params.ts:1-30 and contains eleven configuration parameters organized into three categories: signal validation, scheduling, and data retrieval.
GLOBAL_CONFIG Parameter Summary
| Parameter | Default | Unit | Category | Purpose |
|---|---|---|---|---|
CC_SCHEDULE_AWAIT_MINUTES |
120 | minutes | Scheduling | Maximum wait time for scheduled signals to activate |
CC_AVG_PRICE_CANDLES_COUNT |
5 | candles | Exchange | Number of 1-minute candles for VWAP calculation |
CC_MIN_TAKEPROFIT_DISTANCE_PERCENT |
0.3 | percent | Validation | Minimum TP distance from priceOpen (fee coverage) |
CC_MAX_STOPLOSS_DISTANCE_PERCENT |
20 | percent | Validation | Maximum SL distance from priceOpen (risk limit) |
CC_MAX_SIGNAL_LIFETIME_MINUTES |
1440 | minutes | Validation | Maximum signal duration (1 day default) |
CC_GET_CANDLES_RETRY_COUNT |
3 | count | Exchange | Number of retries for getCandles function |
CC_GET_CANDLES_RETRY_DELAY_MS |
5000 | milliseconds | Exchange | Delay between retries for getCandles function |
CC_GET_CANDLES_PRICE_ANOMALY_THRESHOLD_FACTOR |
1000 | factor | Exchange | Maximum allowed deviation for price anomaly detection |
CC_GET_CANDLES_MIN_CANDLES_FOR_MEDIAN |
5 | candles | Exchange | Minimum candles required for median calculation |
The setConfig() function allows runtime modification of global configuration parameters. It accepts a partial configuration object, enabling selective parameter updates without affecting other values.
setConfig(config: Partial<GlobalConfig>): Promise<void>
Parameters:
config: Partial<GlobalConfig> - Object containing configuration parameters to update. Only specified parameters are modified; others retain their current values.Returns:
Promise<void> - Resolves when configuration is updatedBehavior:
GLOBAL_CONFIG object in-place via object spreadCode Flow:
Purpose: Maximum time in minutes to wait for a scheduled signal to activate before cancelling it.
Default Value: 120 minutes (2 hours)
Usage Context:
priceOpen specified)scheduledAt timestamppriceOpen not reached within timeoutValidation Flow:
Example:
// Extend timeout for long-term scheduled signals
setConfig({
CC_SCHEDULE_AWAIT_MINUTES: 240, // 4 hours
});
Purpose: Number of 1-minute candles to use for Volume-Weighted Average Price (VWAP) calculation.
Default Value: 5 candles (last 5 minutes)
Usage Context:
ClientExchange.getAveragePrice() methodVWAP = Σ(Typical Price × Volume) / Σ(Volume)(High + Low + Close) / 3VWAP Calculation Flow:
Example:
// Use 10 candles for smoother VWAP
setConfig({
CC_AVG_PRICE_CANDLES_COUNT: 10,
});
Purpose: Minimum percentage distance between priceTakeProfit and priceOpen to ensure profit exceeds trading fees.
Default Value: 0.1% (minimum profit after 2×0.1% fees)
Usage Context:
VALIDATE_SIGNAL_FNValidation Logic:
Example:
// Require 0.5% minimum TP distance for high-fee exchanges
setConfig({
CC_MIN_TAKEPROFIT_DISTANCE_PERCENT: 0.5,
});
Purpose: Maximum percentage distance between priceStopLoss and priceOpen to prevent catastrophic losses from extreme StopLoss values.
Default Value: 20% (one signal cannot lose more than 20% of position)
Usage Context:
VALIDATE_SIGNAL_FNValidation Logic:
Example:
// Allow 10% max risk per signal for conservative strategy
setConfig({
CC_MAX_STOPLOSS_DISTANCE_PERCENT: 10,
});
Purpose: Maximum signal duration in minutes before automatic closure via time expiration.
Default Value: 1440 minutes (1 day)
Usage Context:
pendingAt timestamp (when signal becomes active)closeReason: "time_expired" when exceededLifecycle Monitoring:
Example:
// Allow 7-day positions for long-term strategies
setConfig({
CC_MAX_SIGNAL_LIFETIME_MINUTES: 10080, // 7 days
});
Purpose: Number of retry attempts for the getCandles() function when exchange data fetching fails.
Default Value: 3 retries
Usage Context:
ClientExchange.getCandles() when fetching historical candle dataCC_GET_CANDLES_RETRY_DELAY_MS milliseconds before retryingRetry Logic Flow:
Example:
// Increase retries for unreliable exchange APIs
setConfig({
CC_GET_CANDLES_RETRY_COUNT: 5,
});
Purpose: Delay in milliseconds between retry attempts for the getCandles() function.
Default Value: 5000 milliseconds (5 seconds)
Usage Context:
ClientExchange.getCandles()Example:
// Reduce delay for faster retries in testing
setConfig({
CC_GET_CANDLES_RETRY_DELAY_MS: 1000, // 1 second
});
Purpose: Maximum allowed deviation factor for price anomaly detection in candle data. Prices more than this factor below the reference price are considered anomalies and filtered out.
Default Value: 1000 (prices below 1/1000th of median are filtered)
Usage Context:
ClientExchange.getCandles()referencePrice / CC_GET_CANDLES_PRICE_ANOMALY_THRESHOLD_FACTORReasoning:
Anomaly Detection Logic:
Example:
// More aggressive anomaly detection for high-value assets
setConfig({
CC_GET_CANDLES_PRICE_ANOMALY_THRESHOLD_FACTOR: 10000, // Filter prices below 1/10000th
});
Purpose: Minimum number of candles required for reliable median calculation. Below this threshold, simple average is used instead of median.
Default Value: 5 candles
Usage Context:
ClientExchange.getCandles()Reasoning:
Statistical Method Selection:
Example:
// Require more data points for median calculation
setConfig({
CC_GET_CANDLES_MIN_CANDLES_FOR_MEDIAN: 10,
});
The configuration system follows a simple write-once-read-many pattern, where configuration parameters are read by validation and monitoring logic throughout the framework.
Configuration Consumers by Code Entity:
| Consumer Code Entity | File Location | Configuration Parameter | Usage |
|---|---|---|---|
VALIDATE_SIGNAL_FN |
ClientStrategy.ts:41 | CC_MIN_TAKEPROFIT_DISTANCE_PERCENT |
Validate minimum TP distance ClientStrategy.ts:138-148 |
VALIDATE_SIGNAL_FN |
ClientStrategy.ts:41 | CC_MAX_STOPLOSS_DISTANCE_PERCENT |
Validate maximum SL distance ClientStrategy.ts:151-161 |
VALIDATE_SIGNAL_FN |
ClientStrategy.ts:41 | CC_MAX_SIGNAL_LIFETIME_MINUTES |
Validate signal lifetime ClientStrategy.ts:237-246 |
ClientExchange.getAveragePrice() |
ClientExchange.ts | CC_AVG_PRICE_CANDLES_COUNT |
VWAP candle count |
ClientExchange.getCandles() |
ClientExchange.ts | CC_GET_CANDLES_RETRY_COUNT |
Number of retry attempts |
ClientExchange.getCandles() |
ClientExchange.ts | CC_GET_CANDLES_RETRY_DELAY_MS |
Delay between retries |
ClientExchange.getCandles() |
ClientExchange.ts | CC_GET_CANDLES_PRICE_ANOMALY_THRESHOLD_FACTOR |
Anomaly detection threshold |
ClientExchange.getCandles() |
ClientExchange.ts | CC_GET_CANDLES_MIN_CANDLES_FOR_MEDIAN |
Median calculation threshold |
CHECK_PENDING_SIGNAL_COMPLETION_FN |
ClientStrategy.ts:817 | CC_MAX_SIGNAL_LIFETIME_MINUTES |
Check signal expiration |
CHECK_SCHEDULED_SIGNAL_TIMEOUT_FN |
ClientStrategy.ts:474 | CC_SCHEDULE_AWAIT_MINUTES |
Check scheduled timeout |
PROCESS_SCHEDULED_SIGNAL_CANDLES_FN |
ClientStrategy.ts:1263 | CC_SCHEDULE_AWAIT_MINUTES |
Check scheduled timeout in backtest |
The configuration system uses TypeScript's typeof operator to derive the GlobalConfig type from the runtime GLOBAL_CONFIG object, ensuring type safety for partial updates via setConfig().
Type Definition:
// Runtime object
const GLOBAL_CONFIG = {
CC_SCHEDULE_AWAIT_MINUTES: 120,
CC_AVG_PRICE_CANDLES_COUNT: 5,
CC_MIN_TAKEPROFIT_DISTANCE_PERCENT: 0.1,
CC_MAX_STOPLOSS_DISTANCE_PERCENT: 20,
CC_MAX_SIGNAL_LIFETIME_MINUTES: 1440,
};
// Type derived from runtime object
type GlobalConfig = typeof GLOBAL_CONFIG;
// setConfig accepts partial configuration
function setConfig(config: Partial<GlobalConfig>): Promise<void>;
Type Safety Benefits:
Test environments often require relaxed validation rules to test edge cases:
// Disable all validation constraints for testing
await setConfig({
CC_MIN_TAKEPROFIT_DISTANCE_PERCENT: 0, // Allow any TP distance
CC_MAX_STOPLOSS_DISTANCE_PERCENT: 100, // Allow any SL distance
CC_MAX_SIGNAL_LIFETIME_MINUTES: 999999, // Allow any lifetime
});
Production strategies may require stricter validation:
// Conservative configuration for production
await setConfig({
CC_MIN_TAKEPROFIT_DISTANCE_PERCENT: 0.5, // 0.5% minimum profit
CC_MAX_STOPLOSS_DISTANCE_PERCENT: 5, // 5% maximum loss per signal
CC_MAX_SIGNAL_LIFETIME_MINUTES: 720, // 12 hours max signal duration
CC_SCHEDULE_AWAIT_MINUTES: 60, // 1 hour scheduled signal timeout
});
Update only specific parameters while preserving defaults for others:
// Only modify scheduled signal timeout
await setConfig({
CC_SCHEDULE_AWAIT_MINUTES: 180, // 3 hours
});
// All other parameters retain their default values
Swing trading strategies may require extended timeouts:
// Configuration for multi-day swing trading
await setConfig({
CC_MAX_SIGNAL_LIFETIME_MINUTES: 10080, // 7 days
CC_SCHEDULE_AWAIT_MINUTES: 1440, // 24 hours for limit orders
CC_AVG_PRICE_CANDLES_COUNT: 15, // 15-minute VWAP for stability
});
Scalping strategies require tighter constraints:
// Configuration for high-frequency scalping
await setConfig({
CC_MAX_SIGNAL_LIFETIME_MINUTES: 60, // 1 hour max
CC_SCHEDULE_AWAIT_MINUTES: 15, // 15 minutes scheduled timeout
CC_AVG_PRICE_CANDLES_COUNT: 3, // 3-minute VWAP for responsiveness
CC_MIN_TAKEPROFIT_DISTANCE_PERCENT: 0.2, // Tight TP for quick exits
});
Configuration changes take effect immediately but only affect future operations:
getAveragePrice() call uses updated candle countImportant: Configuration changes do NOT retroactively affect active or scheduled signals. Signals retain the validation parameters that were active when they were created.
The default configuration values represent a balanced approach suitable for most cryptocurrency trading strategies:
| Parameter | Default | Rationale |
|---|---|---|
CC_SCHEDULE_AWAIT_MINUTES |
120 min | 2-hour window balances limit order patience vs. stale signals |
CC_AVG_PRICE_CANDLES_COUNT |
5 candles | 5-minute lookback reduces noise while remaining responsive |
CC_MIN_TAKEPROFIT_DISTANCE_PERCENT |
0.1% | Minimal profit check (fees typically 0.1% each side = 0.2% total) |
CC_MAX_STOPLOSS_DISTANCE_PERCENT |
20% | Prevents catastrophic single-signal portfolio damage |
CC_MAX_SIGNAL_LIFETIME_MINUTES |
1440 min | 24-hour limit prevents eternal signals blocking risk limits |
Note: The default CC_MIN_TAKEPROFIT_DISTANCE_PERCENT of 0.1% is intentionally permissive. For production use with 0.1% trading fees, consider increasing to 0.3% or higher to ensure profitable trades after fees.