backtest-kit 1.5.28 → 1.5.30
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 +644 -394
- package/build/index.mjs +643 -395
- package/package.json +1 -1
- package/types.d.ts +107 -1
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -4179,6 +4179,27 @@ declare function listenRisk(fn: (event: RiskContract) => void): () => void;
|
|
|
4179
4179
|
*/
|
|
4180
4180
|
declare function listenRiskOnce(filterFn: (event: RiskContract) => boolean, fn: (event: RiskContract) => void): () => void;
|
|
4181
4181
|
|
|
4182
|
+
/**
|
|
4183
|
+
* Checks if trade context is active (execution and method contexts).
|
|
4184
|
+
*
|
|
4185
|
+
* Returns true when both contexts are active, which is required for calling
|
|
4186
|
+
* exchange functions like getCandles, getAveragePrice, formatPrice, formatQuantity,
|
|
4187
|
+
* getDate, and getMode.
|
|
4188
|
+
*
|
|
4189
|
+
* @returns true if trade context is active, false otherwise
|
|
4190
|
+
*
|
|
4191
|
+
* @example
|
|
4192
|
+
* ```typescript
|
|
4193
|
+
* import { hasTradeContext, getCandles } from "backtest-kit";
|
|
4194
|
+
*
|
|
4195
|
+
* if (hasTradeContext()) {
|
|
4196
|
+
* const candles = await getCandles("BTCUSDT", "1m", 100);
|
|
4197
|
+
* } else {
|
|
4198
|
+
* console.log("Trade context not active");
|
|
4199
|
+
* }
|
|
4200
|
+
* ```
|
|
4201
|
+
*/
|
|
4202
|
+
declare function hasTradeContext(): boolean;
|
|
4182
4203
|
/**
|
|
4183
4204
|
* Fetches historical candle data from the registered exchange.
|
|
4184
4205
|
*
|
|
@@ -7689,6 +7710,91 @@ declare class RiskUtils {
|
|
|
7689
7710
|
*/
|
|
7690
7711
|
declare const Risk: RiskUtils;
|
|
7691
7712
|
|
|
7713
|
+
/**
|
|
7714
|
+
* Utility class for exchange operations.
|
|
7715
|
+
*
|
|
7716
|
+
* Provides simplified access to exchange schema methods with validation.
|
|
7717
|
+
* Exported as singleton instance for convenient usage.
|
|
7718
|
+
*
|
|
7719
|
+
* @example
|
|
7720
|
+
* ```typescript
|
|
7721
|
+
* import { Exchange } from "./classes/Exchange";
|
|
7722
|
+
*
|
|
7723
|
+
* const candles = await Exchange.getCandles("BTCUSDT", "1m", new Date(), 100, {
|
|
7724
|
+
* exchangeName: "binance"
|
|
7725
|
+
* });
|
|
7726
|
+
* const formatted = await Exchange.formatQuantity("BTCUSDT", 0.001, {
|
|
7727
|
+
* exchangeName: "binance"
|
|
7728
|
+
* });
|
|
7729
|
+
* ```
|
|
7730
|
+
*/
|
|
7731
|
+
declare class ExchangeUtils {
|
|
7732
|
+
/**
|
|
7733
|
+
* Memoized function to get or create ExchangeInstance for an exchange.
|
|
7734
|
+
* Each exchange gets its own isolated instance.
|
|
7735
|
+
*/
|
|
7736
|
+
private _getInstance;
|
|
7737
|
+
/**
|
|
7738
|
+
* Fetch candles from data source (API or database).
|
|
7739
|
+
*
|
|
7740
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
7741
|
+
* @param interval - Candle time interval (e.g., "1m", "1h")
|
|
7742
|
+
* @param since - Start date for candle fetching
|
|
7743
|
+
* @param limit - Maximum number of candles to fetch
|
|
7744
|
+
* @param context - Execution context with exchange name
|
|
7745
|
+
* @returns Promise resolving to array of OHLCV candle data
|
|
7746
|
+
*/
|
|
7747
|
+
getCandles: (symbol: string, interval: CandleInterval, since: Date, limit: number, context: {
|
|
7748
|
+
exchangeName: ExchangeName;
|
|
7749
|
+
}) => Promise<ICandleData[]>;
|
|
7750
|
+
/**
|
|
7751
|
+
* Format quantity according to exchange precision rules.
|
|
7752
|
+
*
|
|
7753
|
+
* @param symbol - Trading pair symbol
|
|
7754
|
+
* @param quantity - Raw quantity value
|
|
7755
|
+
* @param context - Execution context with exchange name
|
|
7756
|
+
* @returns Promise resolving to formatted quantity string
|
|
7757
|
+
*/
|
|
7758
|
+
formatQuantity: (symbol: string, quantity: number, context: {
|
|
7759
|
+
exchangeName: ExchangeName;
|
|
7760
|
+
}) => Promise<string>;
|
|
7761
|
+
/**
|
|
7762
|
+
* Format price according to exchange precision rules.
|
|
7763
|
+
*
|
|
7764
|
+
* @param symbol - Trading pair symbol
|
|
7765
|
+
* @param price - Raw price value
|
|
7766
|
+
* @param context - Execution context with exchange name
|
|
7767
|
+
* @returns Promise resolving to formatted price string
|
|
7768
|
+
*/
|
|
7769
|
+
formatPrice: (symbol: string, price: number, context: {
|
|
7770
|
+
exchangeName: ExchangeName;
|
|
7771
|
+
}) => Promise<string>;
|
|
7772
|
+
}
|
|
7773
|
+
/**
|
|
7774
|
+
* Singleton instance of ExchangeUtils for convenient exchange operations.
|
|
7775
|
+
*
|
|
7776
|
+
* @example
|
|
7777
|
+
* ```typescript
|
|
7778
|
+
* import { Exchange } from "./classes/Exchange";
|
|
7779
|
+
*
|
|
7780
|
+
* // Using static-like API with context
|
|
7781
|
+
* const candles = await Exchange.getCandles("BTCUSDT", "1m", new Date(), 100, {
|
|
7782
|
+
* exchangeName: "binance"
|
|
7783
|
+
* });
|
|
7784
|
+
* const qty = await Exchange.formatQuantity("BTCUSDT", 0.001, {
|
|
7785
|
+
* exchangeName: "binance"
|
|
7786
|
+
* });
|
|
7787
|
+
* const price = await Exchange.formatPrice("BTCUSDT", 50000.123, {
|
|
7788
|
+
* exchangeName: "binance"
|
|
7789
|
+
* });
|
|
7790
|
+
*
|
|
7791
|
+
* // Using instance API (no context needed, exchange set in constructor)
|
|
7792
|
+
* const binance = new ExchangeInstance("binance");
|
|
7793
|
+
* const candles2 = await binance.getCandles("BTCUSDT", "1m", new Date(), 100);
|
|
7794
|
+
* ```
|
|
7795
|
+
*/
|
|
7796
|
+
declare const Exchange: ExchangeUtils;
|
|
7797
|
+
|
|
7692
7798
|
/**
|
|
7693
7799
|
* Contract for walker stop signal events.
|
|
7694
7800
|
*
|
|
@@ -10524,4 +10630,4 @@ declare const backtest: {
|
|
|
10524
10630
|
loggerService: LoggerService;
|
|
10525
10631
|
};
|
|
10526
10632
|
|
|
10527
|
-
export { Backtest, type BacktestStatisticsModel, type CandleInterval, type ColumnConfig, type ColumnModel, Constant, type DoneContract, type EntityId, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IOptimizerCallbacks, type IOptimizerData, type IOptimizerFetchArgs, type IOptimizerFilterArgs, type IOptimizerRange, type IOptimizerSchema, type IOptimizerSource, type IOptimizerStrategy, type IOptimizerTemplate, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, 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 IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, Live, type LiveStatisticsModel, type MessageModel, type MessageRole, MethodContextService, Optimizer, Partial$1 as Partial, type PartialData, type PartialLossContract, type PartialProfitContract, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, PositionSize, type ProgressBacktestContract, type ProgressOptimizerContract, type ProgressWalkerContract, Risk, type RiskContract, type RiskData, type RiskStatisticsModel, Schedule, type ScheduleData, type ScheduleStatisticsModel, type SignalData, type SignalInterval, type TPersistBase, type TPersistBaseCtor, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type WalkerStatisticsModel, addExchange, addFrame, addOptimizer, addRisk, addSizing, addStrategy, addWalker, dumpSignal, emitters, formatPrice, formatQuantity, getAveragePrice, getCandles, getColumns, getConfig, getDate, getDefaultColumns, getDefaultConfig, getMode, backtest as lib, listExchanges, listFrames, listOptimizers, listRisks, listSizings, listStrategies, listWalkers, listenBacktestProgress, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenOptimizerProgress, listenPartialLoss, listenPartialLossOnce, listenPartialProfit, listenPartialProfitOnce, listenPerformance, listenRisk, listenRiskOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, setColumns, setConfig, setLogger };
|
|
10633
|
+
export { Backtest, type BacktestStatisticsModel, type CandleInterval, type ColumnConfig, type ColumnModel, Constant, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IOptimizerCallbacks, type IOptimizerData, type IOptimizerFetchArgs, type IOptimizerFilterArgs, type IOptimizerRange, type IOptimizerSchema, type IOptimizerSource, type IOptimizerStrategy, type IOptimizerTemplate, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, 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 IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, Live, type LiveStatisticsModel, type MessageModel, type MessageRole, MethodContextService, Optimizer, Partial$1 as Partial, type PartialData, type PartialLossContract, type PartialProfitContract, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, PositionSize, type ProgressBacktestContract, type ProgressOptimizerContract, type ProgressWalkerContract, Risk, type RiskContract, type RiskData, type RiskStatisticsModel, Schedule, type ScheduleData, type ScheduleStatisticsModel, type SignalData, type SignalInterval, type TPersistBase, type TPersistBaseCtor, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type WalkerStatisticsModel, addExchange, addFrame, addOptimizer, addRisk, addSizing, addStrategy, addWalker, dumpSignal, emitters, formatPrice, formatQuantity, getAveragePrice, getCandles, getColumns, getConfig, getDate, getDefaultColumns, getDefaultConfig, getMode, hasTradeContext, backtest as lib, listExchanges, listFrames, listOptimizers, listRisks, listSizings, listStrategies, listWalkers, listenBacktestProgress, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenOptimizerProgress, listenPartialLoss, listenPartialLossOnce, listenPartialProfit, listenPartialProfitOnce, listenPerformance, listenRisk, listenRiskOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, setColumns, setConfig, setLogger };
|