backtest-kit 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.cjs +350 -80
- package/build/index.mjs +350 -81
- package/package.json +1 -1
- package/types.d.ts +101 -10
package/types.d.ts
CHANGED
|
@@ -397,6 +397,26 @@ interface IExchange {
|
|
|
397
397
|
* @returns Promise resolving to order book data
|
|
398
398
|
*/
|
|
399
399
|
getOrderBook: (symbol: string, depth?: number) => Promise<IOrderBookData>;
|
|
400
|
+
/**
|
|
401
|
+
* Fetch raw candles with flexible date/limit parameters.
|
|
402
|
+
*
|
|
403
|
+
* All modes respect execution context and prevent look-ahead bias.
|
|
404
|
+
*
|
|
405
|
+
* Parameter combinations:
|
|
406
|
+
* 1. sDate + eDate + limit: fetches with explicit parameters, validates eDate <= when
|
|
407
|
+
* 2. sDate + eDate: calculates limit from date range, validates eDate <= when
|
|
408
|
+
* 3. eDate + limit: calculates sDate backward, validates eDate <= when
|
|
409
|
+
* 4. sDate + limit: fetches forward, validates calculated endTimestamp <= when
|
|
410
|
+
* 5. Only limit: uses execution.context.when as reference (backward)
|
|
411
|
+
*
|
|
412
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
413
|
+
* @param interval - Candle interval (e.g., "1m", "1h")
|
|
414
|
+
* @param limit - Optional number of candles to fetch
|
|
415
|
+
* @param sDate - Optional start date in milliseconds
|
|
416
|
+
* @param eDate - Optional end date in milliseconds
|
|
417
|
+
* @returns Promise resolving to array of candles
|
|
418
|
+
*/
|
|
419
|
+
getRawCandles: (symbol: string, interval: CandleInterval, limit?: number, sDate?: number, eDate?: number) => Promise<ICandleData[]>;
|
|
400
420
|
}
|
|
401
421
|
/**
|
|
402
422
|
* Unique exchange identifier.
|
|
@@ -6825,6 +6845,38 @@ declare function getContext(): Promise<IMethodContext>;
|
|
|
6825
6845
|
* ```
|
|
6826
6846
|
*/
|
|
6827
6847
|
declare function getOrderBook(symbol: string, depth?: number): Promise<IOrderBookData>;
|
|
6848
|
+
/**
|
|
6849
|
+
* Fetches raw candles with flexible date/limit parameters.
|
|
6850
|
+
*
|
|
6851
|
+
* All modes respect execution context and prevent look-ahead bias.
|
|
6852
|
+
*
|
|
6853
|
+
* Parameter combinations:
|
|
6854
|
+
* 1. sDate + eDate + limit: fetches with explicit parameters, validates eDate <= when
|
|
6855
|
+
* 2. sDate + eDate: calculates limit from date range, validates eDate <= when
|
|
6856
|
+
* 3. eDate + limit: calculates sDate backward, validates eDate <= when
|
|
6857
|
+
* 4. sDate + limit: fetches forward, validates calculated endTimestamp <= when
|
|
6858
|
+
* 5. Only limit: uses execution.context.when as reference (backward)
|
|
6859
|
+
*
|
|
6860
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
6861
|
+
* @param interval - Candle interval ("1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h")
|
|
6862
|
+
* @param limit - Optional number of candles to fetch
|
|
6863
|
+
* @param sDate - Optional start date in milliseconds
|
|
6864
|
+
* @param eDate - Optional end date in milliseconds
|
|
6865
|
+
* @returns Promise resolving to array of candle data
|
|
6866
|
+
*
|
|
6867
|
+
* @example
|
|
6868
|
+
* ```typescript
|
|
6869
|
+
* // Fetch 100 candles backward from current context time
|
|
6870
|
+
* const candles = await getRawCandles("BTCUSDT", "1m", 100);
|
|
6871
|
+
*
|
|
6872
|
+
* // Fetch candles for specific date range
|
|
6873
|
+
* const rangeCandles = await getRawCandles("BTCUSDT", "1h", undefined, startMs, endMs);
|
|
6874
|
+
*
|
|
6875
|
+
* // Fetch with all parameters specified
|
|
6876
|
+
* const exactCandles = await getRawCandles("BTCUSDT", "1m", 100, startMs, endMs);
|
|
6877
|
+
* ```
|
|
6878
|
+
*/
|
|
6879
|
+
declare function getRawCandles(symbol: string, interval: CandleInterval, limit?: number, sDate?: number, eDate?: number): Promise<ICandleData[]>;
|
|
6828
6880
|
|
|
6829
6881
|
/**
|
|
6830
6882
|
* Commits signal prompt history to the message array.
|
|
@@ -12788,6 +12840,22 @@ declare class ExchangeUtils {
|
|
|
12788
12840
|
getOrderBook: (symbol: string, context: {
|
|
12789
12841
|
exchangeName: ExchangeName;
|
|
12790
12842
|
}, depth?: number) => Promise<IOrderBookData>;
|
|
12843
|
+
/**
|
|
12844
|
+
* Fetches raw candles with flexible date/limit parameters.
|
|
12845
|
+
*
|
|
12846
|
+
* Uses Date.now() instead of execution context when for look-ahead bias protection.
|
|
12847
|
+
*
|
|
12848
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
12849
|
+
* @param interval - Candle interval (e.g., "1m", "1h")
|
|
12850
|
+
* @param context - Execution context with exchange name
|
|
12851
|
+
* @param limit - Optional number of candles to fetch
|
|
12852
|
+
* @param sDate - Optional start date in milliseconds
|
|
12853
|
+
* @param eDate - Optional end date in milliseconds
|
|
12854
|
+
* @returns Promise resolving to array of candle data
|
|
12855
|
+
*/
|
|
12856
|
+
getRawCandles: (symbol: string, interval: CandleInterval, context: {
|
|
12857
|
+
exchangeName: ExchangeName;
|
|
12858
|
+
}, limit?: number, sDate?: number, eDate?: number) => Promise<ICandleData[]>;
|
|
12791
12859
|
}
|
|
12792
12860
|
/**
|
|
12793
12861
|
* Singleton instance of ExchangeUtils for convenient exchange operations.
|
|
@@ -14421,22 +14489,19 @@ declare class ClientExchange implements IExchange {
|
|
|
14421
14489
|
/**
|
|
14422
14490
|
* Fetches raw candles with flexible date/limit parameters.
|
|
14423
14491
|
*
|
|
14424
|
-
*
|
|
14425
|
-
* - RAW MODE (sDate + eDate + limit): fetches exactly as specified, NO look-ahead bias protection
|
|
14426
|
-
* - Other modes: respects execution context and prevents look-ahead bias
|
|
14492
|
+
* All modes respect execution context and prevent look-ahead bias.
|
|
14427
14493
|
*
|
|
14428
14494
|
* Parameter combinations:
|
|
14429
|
-
* 1. sDate + eDate + limit:
|
|
14430
|
-
* 2. sDate + eDate: calculates limit from date range, validates
|
|
14431
|
-
* 3. eDate + limit: calculates sDate backward, validates
|
|
14432
|
-
* 4. sDate + limit: fetches forward, validates endTimestamp <= when
|
|
14495
|
+
* 1. sDate + eDate + limit: fetches with explicit parameters, validates eDate <= when
|
|
14496
|
+
* 2. sDate + eDate: calculates limit from date range, validates eDate <= when
|
|
14497
|
+
* 3. eDate + limit: calculates sDate backward, validates eDate <= when
|
|
14498
|
+
* 4. sDate + limit: fetches forward, validates calculated endTimestamp <= when
|
|
14433
14499
|
* 5. Only limit: uses execution.context.when as reference (backward)
|
|
14434
14500
|
*
|
|
14435
14501
|
* Edge cases:
|
|
14436
14502
|
* - If calculated limit is 0 or negative: throws error
|
|
14437
14503
|
* - If sDate >= eDate: throws error
|
|
14438
|
-
* - If
|
|
14439
|
-
* - If endTimestamp > when (non-RAW modes only): throws error to prevent look-ahead bias
|
|
14504
|
+
* - If eDate > when: throws error to prevent look-ahead bias
|
|
14440
14505
|
*
|
|
14441
14506
|
* @param symbol - Trading pair symbol
|
|
14442
14507
|
* @param interval - Candle interval
|
|
@@ -14564,6 +14629,19 @@ declare class ExchangeConnectionService implements IExchange {
|
|
|
14564
14629
|
* @returns Promise resolving to order book data
|
|
14565
14630
|
*/
|
|
14566
14631
|
getOrderBook: (symbol: string, depth?: number) => Promise<IOrderBookData>;
|
|
14632
|
+
/**
|
|
14633
|
+
* Fetches raw candles with flexible date/limit parameters.
|
|
14634
|
+
*
|
|
14635
|
+
* Routes to exchange determined by methodContextService.context.exchangeName.
|
|
14636
|
+
*
|
|
14637
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
14638
|
+
* @param interval - Candle interval (e.g., "1h", "1d")
|
|
14639
|
+
* @param limit - Optional number of candles to fetch
|
|
14640
|
+
* @param sDate - Optional start date in milliseconds
|
|
14641
|
+
* @param eDate - Optional end date in milliseconds
|
|
14642
|
+
* @returns Promise resolving to array of candle data
|
|
14643
|
+
*/
|
|
14644
|
+
getRawCandles: (symbol: string, interval: CandleInterval, limit?: number, sDate?: number, eDate?: number) => Promise<ICandleData[]>;
|
|
14567
14645
|
}
|
|
14568
14646
|
|
|
14569
14647
|
/**
|
|
@@ -16243,6 +16321,19 @@ declare class ExchangeCoreService implements TExchange {
|
|
|
16243
16321
|
* @returns Promise resolving to order book data
|
|
16244
16322
|
*/
|
|
16245
16323
|
getOrderBook: (symbol: string, when: Date, backtest: boolean, depth?: number) => Promise<IOrderBookData>;
|
|
16324
|
+
/**
|
|
16325
|
+
* Fetches raw candles with flexible date/limit parameters and execution context.
|
|
16326
|
+
*
|
|
16327
|
+
* @param symbol - Trading pair symbol
|
|
16328
|
+
* @param interval - Candle interval (e.g., "1m", "1h")
|
|
16329
|
+
* @param when - Timestamp for context (used in backtest mode)
|
|
16330
|
+
* @param backtest - Whether running in backtest mode
|
|
16331
|
+
* @param limit - Optional number of candles to fetch
|
|
16332
|
+
* @param sDate - Optional start date in milliseconds
|
|
16333
|
+
* @param eDate - Optional end date in milliseconds
|
|
16334
|
+
* @returns Promise resolving to array of candles
|
|
16335
|
+
*/
|
|
16336
|
+
getRawCandles: (symbol: string, interval: CandleInterval, when: Date, backtest: boolean, limit?: number, sDate?: number, eDate?: number) => Promise<ICandleData[]>;
|
|
16246
16337
|
}
|
|
16247
16338
|
|
|
16248
16339
|
/**
|
|
@@ -19455,4 +19546,4 @@ declare const backtest: {
|
|
|
19455
19546
|
loggerService: LoggerService;
|
|
19456
19547
|
};
|
|
19457
19548
|
|
|
19458
|
-
export { ActionBase, type ActivePingContract, Backtest, type BacktestDoneNotification, type BacktestStatisticsModel, Breakeven, type BreakevenContract, type BreakevenData, Cache, type CandleData, type CandleInterval, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type IBidData, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IMarkdownDumpOptions, type IOptimizerCallbacks, type IOptimizerData, type IOptimizerFetchArgs, type IOptimizerFilterArgs, type IOptimizerRange, type IOptimizerSchema, type IOptimizerSource, type IOptimizerStrategy, type IOptimizerTemplate, type IOrderBookData, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IPublicSignalRow, type IReportDumpOptions, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, type IScheduledSignalCancelRow, type IScheduledSignalRow, type ISignalDto, type ISignalRow, type ISizingCalculateParams, type ISizingCalculateParamsATR, type ISizingCalculateParamsFixedPercentage, type ISizingCalculateParamsKelly, type ISizingSchema, type ISizingSchemaATR, type ISizingSchemaFixedPercentage, type ISizingSchemaKelly, type IStrategyPnL, type IStrategyResult, type IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, type InfoErrorNotification, Live, type LiveDoneNotification, type LiveStatisticsModel, Markdown, MarkdownFileBase, MarkdownFolderBase, type MarkdownName, type MessageModel, type MessageRole, MethodContextService, type MetricStats, Notification, type NotificationModel, Optimizer, Partial$1 as Partial, type PartialData, type PartialEvent, type PartialLossContract, type PartialLossNotification, type PartialProfitContract, type PartialProfitNotification, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistBreakevenAdapter, PersistCandleAdapter, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, PositionSize, type ProgressBacktestContract, type ProgressBacktestNotification, type ProgressOptimizerContract, type ProgressWalkerContract, Report, ReportBase, type ReportName, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, Schedule, type ScheduleData, type SchedulePingContract, type ScheduleStatisticsModel, type ScheduledEvent, type SignalCancelledNotification, type SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenedNotification, type SignalScheduledNotification, type TMarkdownBase, type TPersistBase, type TPersistBaseCtor, type TReportBase, type TickEvent, type ValidationErrorNotification, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type SignalData$1 as WalkerSignalData, type WalkerStatisticsModel, addActionSchema, addExchangeSchema, addFrameSchema, addOptimizerSchema, addRiskSchema, addSizingSchema, addStrategySchema, addWalkerSchema, commitBreakeven, commitCancelScheduled, commitClosePending, commitPartialLoss, commitPartialProfit, commitSignalPromptHistory, commitTrailingStop, commitTrailingTake, dumpSignalData, emitters, formatPrice, formatQuantity, get, getActionSchema, getAveragePrice, getBacktestTimeframe, getCandles, getColumns, getConfig, getContext, getDate, getDefaultColumns, getDefaultConfig, getExchangeSchema, getFrameSchema, getMode, getOptimizerSchema, getOrderBook, getRiskSchema, getSizingSchema, getStrategySchema, getSymbol, getWalkerSchema, hasTradeContext, backtest as lib, listExchangeSchema, listFrameSchema, listOptimizerSchema, listRiskSchema, listSizingSchema, listStrategySchema, listWalkerSchema, listenActivePing, listenActivePingOnce, listenBacktestProgress, listenBreakevenAvailable, listenBreakevenAvailableOnce, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenOptimizerProgress, listenPartialLossAvailable, listenPartialLossAvailableOnce, listenPartialProfitAvailable, listenPartialProfitAvailableOnce, listenPerformance, listenRisk, listenRiskOnce, listenSchedulePing, listenSchedulePingOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, overrideActionSchema, overrideExchangeSchema, overrideFrameSchema, overrideOptimizerSchema, overrideRiskSchema, overrideSizingSchema, overrideStrategySchema, overrideWalkerSchema, parseArgs, roundTicks, set, setColumns, setConfig, setLogger, stopStrategy, validate };
|
|
19549
|
+
export { ActionBase, type ActivePingContract, Backtest, type BacktestDoneNotification, type BacktestStatisticsModel, Breakeven, type BreakevenContract, type BreakevenData, Cache, type CandleData, type CandleInterval, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type IBidData, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IMarkdownDumpOptions, type IOptimizerCallbacks, type IOptimizerData, type IOptimizerFetchArgs, type IOptimizerFilterArgs, type IOptimizerRange, type IOptimizerSchema, type IOptimizerSource, type IOptimizerStrategy, type IOptimizerTemplate, type IOrderBookData, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IPublicSignalRow, type IReportDumpOptions, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, type IScheduledSignalCancelRow, type IScheduledSignalRow, type ISignalDto, type ISignalRow, type ISizingCalculateParams, type ISizingCalculateParamsATR, type ISizingCalculateParamsFixedPercentage, type ISizingCalculateParamsKelly, type ISizingSchema, type ISizingSchemaATR, type ISizingSchemaFixedPercentage, type ISizingSchemaKelly, type IStrategyPnL, type IStrategyResult, type IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, type InfoErrorNotification, Live, type LiveDoneNotification, type LiveStatisticsModel, Markdown, MarkdownFileBase, MarkdownFolderBase, type MarkdownName, type MessageModel, type MessageRole, MethodContextService, type MetricStats, Notification, type NotificationModel, Optimizer, Partial$1 as Partial, type PartialData, type PartialEvent, type PartialLossContract, type PartialLossNotification, type PartialProfitContract, type PartialProfitNotification, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistBreakevenAdapter, PersistCandleAdapter, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, PositionSize, type ProgressBacktestContract, type ProgressBacktestNotification, type ProgressOptimizerContract, type ProgressWalkerContract, Report, ReportBase, type ReportName, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, Schedule, type ScheduleData, type SchedulePingContract, type ScheduleStatisticsModel, type ScheduledEvent, type SignalCancelledNotification, type SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenedNotification, type SignalScheduledNotification, type TMarkdownBase, type TPersistBase, type TPersistBaseCtor, type TReportBase, type TickEvent, type ValidationErrorNotification, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type SignalData$1 as WalkerSignalData, type WalkerStatisticsModel, addActionSchema, addExchangeSchema, addFrameSchema, addOptimizerSchema, addRiskSchema, addSizingSchema, addStrategySchema, addWalkerSchema, commitBreakeven, commitCancelScheduled, commitClosePending, commitPartialLoss, commitPartialProfit, commitSignalPromptHistory, commitTrailingStop, commitTrailingTake, dumpSignalData, emitters, formatPrice, formatQuantity, get, getActionSchema, getAveragePrice, getBacktestTimeframe, getCandles, getColumns, getConfig, getContext, getDate, getDefaultColumns, getDefaultConfig, getExchangeSchema, getFrameSchema, getMode, getOptimizerSchema, getOrderBook, getRawCandles, getRiskSchema, getSizingSchema, getStrategySchema, getSymbol, getWalkerSchema, hasTradeContext, backtest as lib, listExchangeSchema, listFrameSchema, listOptimizerSchema, listRiskSchema, listSizingSchema, listStrategySchema, listWalkerSchema, listenActivePing, listenActivePingOnce, listenBacktestProgress, listenBreakevenAvailable, listenBreakevenAvailableOnce, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenOptimizerProgress, listenPartialLossAvailable, listenPartialLossAvailableOnce, listenPartialProfitAvailable, listenPartialProfitAvailableOnce, listenPerformance, listenRisk, listenRiskOnce, listenSchedulePing, listenSchedulePingOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, overrideActionSchema, overrideExchangeSchema, overrideFrameSchema, overrideOptimizerSchema, overrideRiskSchema, overrideSizingSchema, overrideStrategySchema, overrideWalkerSchema, parseArgs, roundTicks, set, setColumns, setConfig, setLogger, stopStrategy, validate };
|