backtest-kit 1.12.1 → 1.12.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/README.md +1 -1
- package/build/index.cjs +50 -0
- package/build/index.mjs +48 -1
- package/package.json +1 -1
- package/types.d.ts +33 -1
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ Build reliable trading systems: backtest on historical data, deploy live bots wi
|
|
|
40
40
|
|
|
41
41
|
### 🎯 The Fastest Way: Sidekick CLI
|
|
42
42
|
|
|
43
|
-
> Create a production-ready trading bot in seconds
|
|
43
|
+
> **Create a production-ready trading bot in seconds:**
|
|
44
44
|
|
|
45
45
|
```bash
|
|
46
46
|
# Create project with npx (recommended)
|
package/build/index.cjs
CHANGED
|
@@ -28546,6 +28546,53 @@ class BreakevenUtils {
|
|
|
28546
28546
|
*/
|
|
28547
28547
|
const Breakeven = new BreakevenUtils();
|
|
28548
28548
|
|
|
28549
|
+
/**
|
|
28550
|
+
* Rounds a price to the appropriate precision based on the tick size.
|
|
28551
|
+
*
|
|
28552
|
+
* @param {string | number} price - The price to round, can be a string or number
|
|
28553
|
+
* @param {number} tickSize - The tick size that determines the precision (e.g., 0.01 for 2 decimal places)
|
|
28554
|
+
* @returns {string} The price rounded to the precision specified by the tick size
|
|
28555
|
+
*
|
|
28556
|
+
* @example
|
|
28557
|
+
* roundTicks(123.456789, 0.01) // returns "123.46"
|
|
28558
|
+
* roundTicks("100.12345", 0.001) // returns "100.123"
|
|
28559
|
+
*/
|
|
28560
|
+
const roundTicks = (price, tickSize) => {
|
|
28561
|
+
const formatter = new Intl.NumberFormat('en-US', {
|
|
28562
|
+
style: 'decimal',
|
|
28563
|
+
minimumFractionDigits: 0,
|
|
28564
|
+
maximumFractionDigits: 8
|
|
28565
|
+
});
|
|
28566
|
+
// @ts-ignore
|
|
28567
|
+
const precision = formatter.format(tickSize).split('.')[1].length || 0;
|
|
28568
|
+
if (typeof price === 'string')
|
|
28569
|
+
price = parseFloat(price);
|
|
28570
|
+
return price.toFixed(precision);
|
|
28571
|
+
};
|
|
28572
|
+
|
|
28573
|
+
/**
|
|
28574
|
+
* Updates the value of a nested object property using a specific path.
|
|
28575
|
+
*
|
|
28576
|
+
* @param object - The object to update.
|
|
28577
|
+
* @param path - The path to the property. Can be either a dot-separated string or an array of strings.
|
|
28578
|
+
* @param value - The new value to set for the property.
|
|
28579
|
+
* @returns - Returns true if the property was successfully updated, false otherwise.
|
|
28580
|
+
*/
|
|
28581
|
+
const set = (object, path, value) => {
|
|
28582
|
+
const pathArray = Array.isArray(path) ? path : path.split('.').filter((key) => key);
|
|
28583
|
+
const pathArrayFlat = pathArray.flatMap((part) => typeof part === 'string' ? part.split('.') : part);
|
|
28584
|
+
const parentPath = pathArrayFlat.slice(0, pathArrayFlat.length - 1);
|
|
28585
|
+
const parent = parentPath.reduce((obj, key) => obj && obj[key], object);
|
|
28586
|
+
const [name] = pathArrayFlat.reverse();
|
|
28587
|
+
try {
|
|
28588
|
+
parent[name] = value;
|
|
28589
|
+
return true;
|
|
28590
|
+
}
|
|
28591
|
+
catch {
|
|
28592
|
+
return false;
|
|
28593
|
+
}
|
|
28594
|
+
};
|
|
28595
|
+
|
|
28549
28596
|
exports.Backtest = Backtest;
|
|
28550
28597
|
exports.Breakeven = Breakeven;
|
|
28551
28598
|
exports.Cache = Cache;
|
|
@@ -28587,6 +28634,7 @@ exports.dumpSignal = dumpSignal;
|
|
|
28587
28634
|
exports.emitters = emitters;
|
|
28588
28635
|
exports.formatPrice = formatPrice;
|
|
28589
28636
|
exports.formatQuantity = formatQuantity;
|
|
28637
|
+
exports.get = get;
|
|
28590
28638
|
exports.getAveragePrice = getAveragePrice;
|
|
28591
28639
|
exports.getCandles = getCandles;
|
|
28592
28640
|
exports.getColumns = getColumns;
|
|
@@ -28639,6 +28687,8 @@ exports.listenWalkerOnce = listenWalkerOnce;
|
|
|
28639
28687
|
exports.listenWalkerProgress = listenWalkerProgress;
|
|
28640
28688
|
exports.partialLoss = partialLoss;
|
|
28641
28689
|
exports.partialProfit = partialProfit;
|
|
28690
|
+
exports.roundTicks = roundTicks;
|
|
28691
|
+
exports.set = set;
|
|
28642
28692
|
exports.setColumns = setColumns;
|
|
28643
28693
|
exports.setConfig = setConfig;
|
|
28644
28694
|
exports.setLogger = setLogger;
|
package/build/index.mjs
CHANGED
|
@@ -28526,4 +28526,51 @@ class BreakevenUtils {
|
|
|
28526
28526
|
*/
|
|
28527
28527
|
const Breakeven = new BreakevenUtils();
|
|
28528
28528
|
|
|
28529
|
-
|
|
28529
|
+
/**
|
|
28530
|
+
* Rounds a price to the appropriate precision based on the tick size.
|
|
28531
|
+
*
|
|
28532
|
+
* @param {string | number} price - The price to round, can be a string or number
|
|
28533
|
+
* @param {number} tickSize - The tick size that determines the precision (e.g., 0.01 for 2 decimal places)
|
|
28534
|
+
* @returns {string} The price rounded to the precision specified by the tick size
|
|
28535
|
+
*
|
|
28536
|
+
* @example
|
|
28537
|
+
* roundTicks(123.456789, 0.01) // returns "123.46"
|
|
28538
|
+
* roundTicks("100.12345", 0.001) // returns "100.123"
|
|
28539
|
+
*/
|
|
28540
|
+
const roundTicks = (price, tickSize) => {
|
|
28541
|
+
const formatter = new Intl.NumberFormat('en-US', {
|
|
28542
|
+
style: 'decimal',
|
|
28543
|
+
minimumFractionDigits: 0,
|
|
28544
|
+
maximumFractionDigits: 8
|
|
28545
|
+
});
|
|
28546
|
+
// @ts-ignore
|
|
28547
|
+
const precision = formatter.format(tickSize).split('.')[1].length || 0;
|
|
28548
|
+
if (typeof price === 'string')
|
|
28549
|
+
price = parseFloat(price);
|
|
28550
|
+
return price.toFixed(precision);
|
|
28551
|
+
};
|
|
28552
|
+
|
|
28553
|
+
/**
|
|
28554
|
+
* Updates the value of a nested object property using a specific path.
|
|
28555
|
+
*
|
|
28556
|
+
* @param object - The object to update.
|
|
28557
|
+
* @param path - The path to the property. Can be either a dot-separated string or an array of strings.
|
|
28558
|
+
* @param value - The new value to set for the property.
|
|
28559
|
+
* @returns - Returns true if the property was successfully updated, false otherwise.
|
|
28560
|
+
*/
|
|
28561
|
+
const set = (object, path, value) => {
|
|
28562
|
+
const pathArray = Array.isArray(path) ? path : path.split('.').filter((key) => key);
|
|
28563
|
+
const pathArrayFlat = pathArray.flatMap((part) => typeof part === 'string' ? part.split('.') : part);
|
|
28564
|
+
const parentPath = pathArrayFlat.slice(0, pathArrayFlat.length - 1);
|
|
28565
|
+
const parent = parentPath.reduce((obj, key) => obj && obj[key], object);
|
|
28566
|
+
const [name] = pathArrayFlat.reverse();
|
|
28567
|
+
try {
|
|
28568
|
+
parent[name] = value;
|
|
28569
|
+
return true;
|
|
28570
|
+
}
|
|
28571
|
+
catch {
|
|
28572
|
+
return false;
|
|
28573
|
+
}
|
|
28574
|
+
};
|
|
28575
|
+
|
|
28576
|
+
export { Backtest, Breakeven, Cache, Constant, Exchange, ExecutionContextService, Heat, Live, Markdown, MarkdownFileBase, MarkdownFolderBase, MethodContextService, Notification, Optimizer, Partial, Performance, PersistBase, PersistBreakevenAdapter, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, PositionSize, Report, ReportBase, Risk, Schedule, Walker, addExchange, addFrame, addOptimizer, addRisk, addSizing, addStrategy, addWalker, breakeven, cancel, dumpSignal, emitters, formatPrice, formatQuantity, get, getAveragePrice, getCandles, getColumns, getConfig, getDate, getDefaultColumns, getDefaultConfig, getMode, getOrderBook, hasTradeContext, backtest as lib, listExchanges, listFrames, listOptimizers, listRisks, listSizings, listStrategies, listWalkers, listenBacktestProgress, listenBreakeven, listenBreakevenOnce, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenOptimizerProgress, listenPartialLoss, listenPartialLossOnce, listenPartialProfit, listenPartialProfitOnce, listenPerformance, listenPing, listenPingOnce, listenRisk, listenRiskOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, partialLoss, partialProfit, roundTicks, set, setColumns, setConfig, setLogger, stop, trailingStop, trailingTake, validate };
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -11970,6 +11970,38 @@ declare namespace emitters {
|
|
|
11970
11970
|
export { emitters_breakevenSubject as breakevenSubject, emitters_doneBacktestSubject as doneBacktestSubject, emitters_doneLiveSubject as doneLiveSubject, emitters_doneWalkerSubject as doneWalkerSubject, emitters_errorEmitter as errorEmitter, emitters_exitEmitter as exitEmitter, emitters_partialLossSubject as partialLossSubject, emitters_partialProfitSubject as partialProfitSubject, emitters_performanceEmitter as performanceEmitter, emitters_pingSubject as pingSubject, emitters_progressBacktestEmitter as progressBacktestEmitter, emitters_progressOptimizerEmitter as progressOptimizerEmitter, emitters_progressWalkerEmitter as progressWalkerEmitter, emitters_riskSubject as riskSubject, emitters_signalBacktestEmitter as signalBacktestEmitter, emitters_signalEmitter as signalEmitter, emitters_signalLiveEmitter as signalLiveEmitter, emitters_validationSubject as validationSubject, emitters_walkerCompleteSubject as walkerCompleteSubject, emitters_walkerEmitter as walkerEmitter, emitters_walkerStopSubject as walkerStopSubject };
|
|
11971
11971
|
}
|
|
11972
11972
|
|
|
11973
|
+
/**
|
|
11974
|
+
* Rounds a price to the appropriate precision based on the tick size.
|
|
11975
|
+
*
|
|
11976
|
+
* @param {string | number} price - The price to round, can be a string or number
|
|
11977
|
+
* @param {number} tickSize - The tick size that determines the precision (e.g., 0.01 for 2 decimal places)
|
|
11978
|
+
* @returns {string} The price rounded to the precision specified by the tick size
|
|
11979
|
+
*
|
|
11980
|
+
* @example
|
|
11981
|
+
* roundTicks(123.456789, 0.01) // returns "123.46"
|
|
11982
|
+
* roundTicks("100.12345", 0.001) // returns "100.123"
|
|
11983
|
+
*/
|
|
11984
|
+
declare const roundTicks: (price: string | number, tickSize: number) => string;
|
|
11985
|
+
|
|
11986
|
+
/**
|
|
11987
|
+
* Retrieves a value from an object using a given path.
|
|
11988
|
+
*
|
|
11989
|
+
* @param object - The object from which to retrieve the value.
|
|
11990
|
+
* @param path - The path to the desired value, either as an array or dot-separated string.
|
|
11991
|
+
* @returns - The value at the specified path, or undefined if it does not exist.
|
|
11992
|
+
*/
|
|
11993
|
+
declare const get: (object: any, path: any) => any;
|
|
11994
|
+
|
|
11995
|
+
/**
|
|
11996
|
+
* Updates the value of a nested object property using a specific path.
|
|
11997
|
+
*
|
|
11998
|
+
* @param object - The object to update.
|
|
11999
|
+
* @param path - The path to the property. Can be either a dot-separated string or an array of strings.
|
|
12000
|
+
* @param value - The new value to set for the property.
|
|
12001
|
+
* @returns - Returns true if the property was successfully updated, false otherwise.
|
|
12002
|
+
*/
|
|
12003
|
+
declare const set: (object: any, path: any, value: any) => boolean;
|
|
12004
|
+
|
|
11973
12005
|
/**
|
|
11974
12006
|
* Logger service with automatic context injection.
|
|
11975
12007
|
*
|
|
@@ -16266,4 +16298,4 @@ declare const backtest: {
|
|
|
16266
16298
|
loggerService: LoggerService;
|
|
16267
16299
|
};
|
|
16268
16300
|
|
|
16269
|
-
export { Backtest, type BacktestDoneNotification, type BacktestStatisticsModel, type BootstrapNotification, Breakeven, type BreakevenContract, type BreakevenData, Cache, 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, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, type PingContract, 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 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, addExchange, addFrame, addOptimizer, addRisk, addSizing, addStrategy, addWalker, breakeven, cancel, dumpSignal, emitters, formatPrice, formatQuantity, getAveragePrice, getCandles, getColumns, getConfig, getDate, getDefaultColumns, getDefaultConfig, getMode, getOrderBook, hasTradeContext, backtest as lib, listExchanges, listFrames, listOptimizers, listRisks, listSizings, listStrategies, listWalkers, listenBacktestProgress, listenBreakeven, listenBreakevenOnce, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenOptimizerProgress, listenPartialLoss, listenPartialLossOnce, listenPartialProfit, listenPartialProfitOnce, listenPerformance, listenPing, listenPingOnce, listenRisk, listenRiskOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, partialLoss, partialProfit, setColumns, setConfig, setLogger, stop, trailingStop, trailingTake, validate };
|
|
16301
|
+
export { Backtest, type BacktestDoneNotification, type BacktestStatisticsModel, type BootstrapNotification, Breakeven, type BreakevenContract, type BreakevenData, Cache, 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, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, type PingContract, 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 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, addExchange, addFrame, addOptimizer, addRisk, addSizing, addStrategy, addWalker, breakeven, cancel, dumpSignal, emitters, formatPrice, formatQuantity, get, getAveragePrice, getCandles, getColumns, getConfig, getDate, getDefaultColumns, getDefaultConfig, getMode, getOrderBook, hasTradeContext, backtest as lib, listExchanges, listFrames, listOptimizers, listRisks, listSizings, listStrategies, listWalkers, listenBacktestProgress, listenBreakeven, listenBreakevenOnce, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenOptimizerProgress, listenPartialLoss, listenPartialLossOnce, listenPartialProfit, listenPartialProfitOnce, listenPerformance, listenPing, listenPingOnce, listenRisk, listenRiskOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, partialLoss, partialProfit, roundTicks, set, setColumns, setConfig, setLogger, stop, trailingStop, trailingTake, validate };
|