backtest-kit 1.5.6 → 1.5.8

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 CHANGED
@@ -13704,6 +13704,15 @@ class BacktestUtils {
13704
13704
  * @returns Async generator yielding closed signals with PNL
13705
13705
  */
13706
13706
  this.run = (symbol, context) => {
13707
+ {
13708
+ backtest$1.strategyValidationService.validate(context.strategyName, BACKTEST_METHOD_NAME_RUN);
13709
+ backtest$1.exchangeValidationService.validate(context.exchangeName, BACKTEST_METHOD_NAME_RUN);
13710
+ backtest$1.frameValidationService.validate(context.frameName, BACKTEST_METHOD_NAME_RUN);
13711
+ }
13712
+ {
13713
+ const { riskName } = backtest$1.strategySchemaService.get(context.strategyName);
13714
+ riskName && backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_RUN);
13715
+ }
13707
13716
  const instance = this._getInstance(symbol, context.strategyName);
13708
13717
  return instance.run(symbol, context);
13709
13718
  };
@@ -13729,6 +13738,11 @@ class BacktestUtils {
13729
13738
  * ```
13730
13739
  */
13731
13740
  this.background = (symbol, context) => {
13741
+ {
13742
+ backtest$1.strategyValidationService.validate(context.strategyName, BACKTEST_METHOD_NAME_BACKGROUND);
13743
+ backtest$1.exchangeValidationService.validate(context.exchangeName, BACKTEST_METHOD_NAME_BACKGROUND);
13744
+ backtest$1.frameValidationService.validate(context.frameName, BACKTEST_METHOD_NAME_BACKGROUND);
13745
+ }
13732
13746
  const instance = this._getInstance(symbol, context.strategyName);
13733
13747
  return instance.background(symbol, context);
13734
13748
  };
@@ -13750,6 +13764,7 @@ class BacktestUtils {
13750
13764
  * ```
13751
13765
  */
13752
13766
  this.stop = async (symbol, strategyName) => {
13767
+ backtest$1.strategyValidationService.validate(strategyName, BACKTEST_METHOD_NAME_STOP);
13753
13768
  const instance = this._getInstance(symbol, strategyName);
13754
13769
  return await instance.stop(symbol, strategyName);
13755
13770
  };
@@ -13767,6 +13782,7 @@ class BacktestUtils {
13767
13782
  * ```
13768
13783
  */
13769
13784
  this.getData = async (symbol, strategyName) => {
13785
+ backtest$1.strategyValidationService.validate(strategyName, "BacktestUtils.getData");
13770
13786
  const instance = this._getInstance(symbol, strategyName);
13771
13787
  return await instance.getData(symbol, strategyName);
13772
13788
  };
@@ -13784,6 +13800,7 @@ class BacktestUtils {
13784
13800
  * ```
13785
13801
  */
13786
13802
  this.getReport = async (symbol, strategyName) => {
13803
+ backtest$1.strategyValidationService.validate(strategyName, BACKTEST_METHOD_NAME_GET_REPORT);
13787
13804
  const instance = this._getInstance(symbol, strategyName);
13788
13805
  return await instance.getReport(symbol, strategyName);
13789
13806
  };
@@ -13804,6 +13821,7 @@ class BacktestUtils {
13804
13821
  * ```
13805
13822
  */
13806
13823
  this.dump = async (symbol, strategyName, path) => {
13824
+ backtest$1.strategyValidationService.validate(strategyName, BACKTEST_METHOD_NAME_DUMP);
13807
13825
  const instance = this._getInstance(symbol, strategyName);
13808
13826
  return await instance.dump(symbol, strategyName, path);
13809
13827
  };
@@ -14170,6 +14188,14 @@ class LiveUtils {
14170
14188
  * @returns Infinite async generator yielding opened and closed signals
14171
14189
  */
14172
14190
  this.run = (symbol, context) => {
14191
+ {
14192
+ backtest$1.strategyValidationService.validate(context.strategyName, LIVE_METHOD_NAME_RUN);
14193
+ backtest$1.exchangeValidationService.validate(context.exchangeName, LIVE_METHOD_NAME_RUN);
14194
+ }
14195
+ {
14196
+ const { riskName } = backtest$1.strategySchemaService.get(context.strategyName);
14197
+ riskName && backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_RUN);
14198
+ }
14173
14199
  const instance = this._getInstance(symbol, context.strategyName);
14174
14200
  return instance.run(symbol, context);
14175
14201
  };
@@ -14195,6 +14221,8 @@ class LiveUtils {
14195
14221
  * ```
14196
14222
  */
14197
14223
  this.background = (symbol, context) => {
14224
+ backtest$1.strategyValidationService.validate(context.strategyName, LIVE_METHOD_NAME_BACKGROUND);
14225
+ backtest$1.exchangeValidationService.validate(context.exchangeName, LIVE_METHOD_NAME_BACKGROUND);
14198
14226
  const instance = this._getInstance(symbol, context.strategyName);
14199
14227
  return instance.background(symbol, context);
14200
14228
  };
@@ -14216,6 +14244,7 @@ class LiveUtils {
14216
14244
  * ```
14217
14245
  */
14218
14246
  this.stop = async (symbol, strategyName) => {
14247
+ backtest$1.strategyValidationService.validate(strategyName, LIVE_METHOD_NAME_STOP);
14219
14248
  const instance = this._getInstance(symbol, strategyName);
14220
14249
  return await instance.stop(symbol, strategyName);
14221
14250
  };
@@ -14233,6 +14262,7 @@ class LiveUtils {
14233
14262
  * ```
14234
14263
  */
14235
14264
  this.getData = async (symbol, strategyName) => {
14265
+ backtest$1.strategyValidationService.validate(strategyName, "LiveUtils.getData");
14236
14266
  const instance = this._getInstance(symbol, strategyName);
14237
14267
  return await instance.getData(symbol, strategyName);
14238
14268
  };
@@ -14250,6 +14280,7 @@ class LiveUtils {
14250
14280
  * ```
14251
14281
  */
14252
14282
  this.getReport = async (symbol, strategyName) => {
14283
+ backtest$1.strategyValidationService.validate(strategyName, LIVE_METHOD_NAME_GET_REPORT);
14253
14284
  const instance = this._getInstance(symbol, strategyName);
14254
14285
  return await instance.getReport(symbol, strategyName);
14255
14286
  };
@@ -14270,6 +14301,7 @@ class LiveUtils {
14270
14301
  * ```
14271
14302
  */
14272
14303
  this.dump = async (symbol, strategyName, path) => {
14304
+ backtest$1.strategyValidationService.validate(strategyName, LIVE_METHOD_NAME_DUMP);
14273
14305
  const instance = this._getInstance(symbol, strategyName);
14274
14306
  return await instance.dump(symbol, strategyName, path);
14275
14307
  };
@@ -14870,6 +14902,16 @@ class WalkerUtils {
14870
14902
  * @returns Async generator yielding progress updates after each strategy
14871
14903
  */
14872
14904
  this.run = (symbol, context) => {
14905
+ backtest$1.walkerValidationService.validate(context.walkerName, WALKER_METHOD_NAME_RUN);
14906
+ const walkerSchema = backtest$1.walkerSchemaService.get(context.walkerName);
14907
+ backtest$1.exchangeValidationService.validate(walkerSchema.exchangeName, WALKER_METHOD_NAME_RUN);
14908
+ backtest$1.frameValidationService.validate(walkerSchema.frameName, WALKER_METHOD_NAME_RUN);
14909
+ for (const strategyName of walkerSchema.strategies) {
14910
+ backtest$1.strategyValidationService.validate(strategyName, WALKER_METHOD_NAME_RUN);
14911
+ const strategySchema = backtest$1.strategySchemaService.get(strategyName);
14912
+ const riskName = strategySchema.riskName;
14913
+ riskName && backtest$1.riskValidationService.validate(riskName, WALKER_METHOD_NAME_RUN);
14914
+ }
14873
14915
  const instance = this._getInstance(symbol, context.walkerName);
14874
14916
  return instance.run(symbol, context);
14875
14917
  };
@@ -14893,6 +14935,16 @@ class WalkerUtils {
14893
14935
  * ```
14894
14936
  */
14895
14937
  this.background = (symbol, context) => {
14938
+ backtest$1.walkerValidationService.validate(context.walkerName, WALKER_METHOD_NAME_BACKGROUND);
14939
+ const walkerSchema = backtest$1.walkerSchemaService.get(context.walkerName);
14940
+ backtest$1.exchangeValidationService.validate(walkerSchema.exchangeName, WALKER_METHOD_NAME_BACKGROUND);
14941
+ backtest$1.frameValidationService.validate(walkerSchema.frameName, WALKER_METHOD_NAME_BACKGROUND);
14942
+ for (const strategyName of walkerSchema.strategies) {
14943
+ backtest$1.strategyValidationService.validate(strategyName, WALKER_METHOD_NAME_BACKGROUND);
14944
+ const strategySchema = backtest$1.strategySchemaService.get(strategyName);
14945
+ const riskName = strategySchema.riskName;
14946
+ riskName && backtest$1.riskValidationService.validate(riskName, WALKER_METHOD_NAME_BACKGROUND);
14947
+ }
14896
14948
  const instance = this._getInstance(symbol, context.walkerName);
14897
14949
  return instance.background(symbol, context);
14898
14950
  };
@@ -14920,6 +14972,7 @@ class WalkerUtils {
14920
14972
  * ```
14921
14973
  */
14922
14974
  this.stop = async (symbol, walkerName) => {
14975
+ backtest$1.walkerValidationService.validate(walkerName, WALKER_METHOD_NAME_STOP);
14923
14976
  const instance = this._getInstance(symbol, walkerName);
14924
14977
  return await instance.stop(symbol, walkerName);
14925
14978
  };
@@ -14937,6 +14990,7 @@ class WalkerUtils {
14937
14990
  * ```
14938
14991
  */
14939
14992
  this.getData = async (symbol, walkerName) => {
14993
+ backtest$1.walkerValidationService.validate(walkerName, WALKER_METHOD_NAME_GET_DATA);
14940
14994
  const instance = this._getInstance(symbol, walkerName);
14941
14995
  return await instance.getData(symbol, walkerName);
14942
14996
  };
@@ -14954,6 +15008,7 @@ class WalkerUtils {
14954
15008
  * ```
14955
15009
  */
14956
15010
  this.getReport = async (symbol, walkerName) => {
15011
+ backtest$1.walkerValidationService.validate(walkerName, WALKER_METHOD_NAME_GET_REPORT);
14957
15012
  const instance = this._getInstance(symbol, walkerName);
14958
15013
  return await instance.getReport(symbol, walkerName);
14959
15014
  };
@@ -14974,6 +15029,7 @@ class WalkerUtils {
14974
15029
  * ```
14975
15030
  */
14976
15031
  this.dump = async (symbol, walkerName, path) => {
15032
+ backtest$1.walkerValidationService.validate(walkerName, WALKER_METHOD_NAME_DUMP);
14977
15033
  const instance = this._getInstance(symbol, walkerName);
14978
15034
  return await instance.dump(symbol, walkerName, path);
14979
15035
  };
package/build/index.mjs CHANGED
@@ -13702,6 +13702,15 @@ class BacktestUtils {
13702
13702
  * @returns Async generator yielding closed signals with PNL
13703
13703
  */
13704
13704
  this.run = (symbol, context) => {
13705
+ {
13706
+ backtest$1.strategyValidationService.validate(context.strategyName, BACKTEST_METHOD_NAME_RUN);
13707
+ backtest$1.exchangeValidationService.validate(context.exchangeName, BACKTEST_METHOD_NAME_RUN);
13708
+ backtest$1.frameValidationService.validate(context.frameName, BACKTEST_METHOD_NAME_RUN);
13709
+ }
13710
+ {
13711
+ const { riskName } = backtest$1.strategySchemaService.get(context.strategyName);
13712
+ riskName && backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_RUN);
13713
+ }
13705
13714
  const instance = this._getInstance(symbol, context.strategyName);
13706
13715
  return instance.run(symbol, context);
13707
13716
  };
@@ -13727,6 +13736,11 @@ class BacktestUtils {
13727
13736
  * ```
13728
13737
  */
13729
13738
  this.background = (symbol, context) => {
13739
+ {
13740
+ backtest$1.strategyValidationService.validate(context.strategyName, BACKTEST_METHOD_NAME_BACKGROUND);
13741
+ backtest$1.exchangeValidationService.validate(context.exchangeName, BACKTEST_METHOD_NAME_BACKGROUND);
13742
+ backtest$1.frameValidationService.validate(context.frameName, BACKTEST_METHOD_NAME_BACKGROUND);
13743
+ }
13730
13744
  const instance = this._getInstance(symbol, context.strategyName);
13731
13745
  return instance.background(symbol, context);
13732
13746
  };
@@ -13748,6 +13762,7 @@ class BacktestUtils {
13748
13762
  * ```
13749
13763
  */
13750
13764
  this.stop = async (symbol, strategyName) => {
13765
+ backtest$1.strategyValidationService.validate(strategyName, BACKTEST_METHOD_NAME_STOP);
13751
13766
  const instance = this._getInstance(symbol, strategyName);
13752
13767
  return await instance.stop(symbol, strategyName);
13753
13768
  };
@@ -13765,6 +13780,7 @@ class BacktestUtils {
13765
13780
  * ```
13766
13781
  */
13767
13782
  this.getData = async (symbol, strategyName) => {
13783
+ backtest$1.strategyValidationService.validate(strategyName, "BacktestUtils.getData");
13768
13784
  const instance = this._getInstance(symbol, strategyName);
13769
13785
  return await instance.getData(symbol, strategyName);
13770
13786
  };
@@ -13782,6 +13798,7 @@ class BacktestUtils {
13782
13798
  * ```
13783
13799
  */
13784
13800
  this.getReport = async (symbol, strategyName) => {
13801
+ backtest$1.strategyValidationService.validate(strategyName, BACKTEST_METHOD_NAME_GET_REPORT);
13785
13802
  const instance = this._getInstance(symbol, strategyName);
13786
13803
  return await instance.getReport(symbol, strategyName);
13787
13804
  };
@@ -13802,6 +13819,7 @@ class BacktestUtils {
13802
13819
  * ```
13803
13820
  */
13804
13821
  this.dump = async (symbol, strategyName, path) => {
13822
+ backtest$1.strategyValidationService.validate(strategyName, BACKTEST_METHOD_NAME_DUMP);
13805
13823
  const instance = this._getInstance(symbol, strategyName);
13806
13824
  return await instance.dump(symbol, strategyName, path);
13807
13825
  };
@@ -14168,6 +14186,14 @@ class LiveUtils {
14168
14186
  * @returns Infinite async generator yielding opened and closed signals
14169
14187
  */
14170
14188
  this.run = (symbol, context) => {
14189
+ {
14190
+ backtest$1.strategyValidationService.validate(context.strategyName, LIVE_METHOD_NAME_RUN);
14191
+ backtest$1.exchangeValidationService.validate(context.exchangeName, LIVE_METHOD_NAME_RUN);
14192
+ }
14193
+ {
14194
+ const { riskName } = backtest$1.strategySchemaService.get(context.strategyName);
14195
+ riskName && backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_RUN);
14196
+ }
14171
14197
  const instance = this._getInstance(symbol, context.strategyName);
14172
14198
  return instance.run(symbol, context);
14173
14199
  };
@@ -14193,6 +14219,8 @@ class LiveUtils {
14193
14219
  * ```
14194
14220
  */
14195
14221
  this.background = (symbol, context) => {
14222
+ backtest$1.strategyValidationService.validate(context.strategyName, LIVE_METHOD_NAME_BACKGROUND);
14223
+ backtest$1.exchangeValidationService.validate(context.exchangeName, LIVE_METHOD_NAME_BACKGROUND);
14196
14224
  const instance = this._getInstance(symbol, context.strategyName);
14197
14225
  return instance.background(symbol, context);
14198
14226
  };
@@ -14214,6 +14242,7 @@ class LiveUtils {
14214
14242
  * ```
14215
14243
  */
14216
14244
  this.stop = async (symbol, strategyName) => {
14245
+ backtest$1.strategyValidationService.validate(strategyName, LIVE_METHOD_NAME_STOP);
14217
14246
  const instance = this._getInstance(symbol, strategyName);
14218
14247
  return await instance.stop(symbol, strategyName);
14219
14248
  };
@@ -14231,6 +14260,7 @@ class LiveUtils {
14231
14260
  * ```
14232
14261
  */
14233
14262
  this.getData = async (symbol, strategyName) => {
14263
+ backtest$1.strategyValidationService.validate(strategyName, "LiveUtils.getData");
14234
14264
  const instance = this._getInstance(symbol, strategyName);
14235
14265
  return await instance.getData(symbol, strategyName);
14236
14266
  };
@@ -14248,6 +14278,7 @@ class LiveUtils {
14248
14278
  * ```
14249
14279
  */
14250
14280
  this.getReport = async (symbol, strategyName) => {
14281
+ backtest$1.strategyValidationService.validate(strategyName, LIVE_METHOD_NAME_GET_REPORT);
14251
14282
  const instance = this._getInstance(symbol, strategyName);
14252
14283
  return await instance.getReport(symbol, strategyName);
14253
14284
  };
@@ -14268,6 +14299,7 @@ class LiveUtils {
14268
14299
  * ```
14269
14300
  */
14270
14301
  this.dump = async (symbol, strategyName, path) => {
14302
+ backtest$1.strategyValidationService.validate(strategyName, LIVE_METHOD_NAME_DUMP);
14271
14303
  const instance = this._getInstance(symbol, strategyName);
14272
14304
  return await instance.dump(symbol, strategyName, path);
14273
14305
  };
@@ -14868,6 +14900,16 @@ class WalkerUtils {
14868
14900
  * @returns Async generator yielding progress updates after each strategy
14869
14901
  */
14870
14902
  this.run = (symbol, context) => {
14903
+ backtest$1.walkerValidationService.validate(context.walkerName, WALKER_METHOD_NAME_RUN);
14904
+ const walkerSchema = backtest$1.walkerSchemaService.get(context.walkerName);
14905
+ backtest$1.exchangeValidationService.validate(walkerSchema.exchangeName, WALKER_METHOD_NAME_RUN);
14906
+ backtest$1.frameValidationService.validate(walkerSchema.frameName, WALKER_METHOD_NAME_RUN);
14907
+ for (const strategyName of walkerSchema.strategies) {
14908
+ backtest$1.strategyValidationService.validate(strategyName, WALKER_METHOD_NAME_RUN);
14909
+ const strategySchema = backtest$1.strategySchemaService.get(strategyName);
14910
+ const riskName = strategySchema.riskName;
14911
+ riskName && backtest$1.riskValidationService.validate(riskName, WALKER_METHOD_NAME_RUN);
14912
+ }
14871
14913
  const instance = this._getInstance(symbol, context.walkerName);
14872
14914
  return instance.run(symbol, context);
14873
14915
  };
@@ -14891,6 +14933,16 @@ class WalkerUtils {
14891
14933
  * ```
14892
14934
  */
14893
14935
  this.background = (symbol, context) => {
14936
+ backtest$1.walkerValidationService.validate(context.walkerName, WALKER_METHOD_NAME_BACKGROUND);
14937
+ const walkerSchema = backtest$1.walkerSchemaService.get(context.walkerName);
14938
+ backtest$1.exchangeValidationService.validate(walkerSchema.exchangeName, WALKER_METHOD_NAME_BACKGROUND);
14939
+ backtest$1.frameValidationService.validate(walkerSchema.frameName, WALKER_METHOD_NAME_BACKGROUND);
14940
+ for (const strategyName of walkerSchema.strategies) {
14941
+ backtest$1.strategyValidationService.validate(strategyName, WALKER_METHOD_NAME_BACKGROUND);
14942
+ const strategySchema = backtest$1.strategySchemaService.get(strategyName);
14943
+ const riskName = strategySchema.riskName;
14944
+ riskName && backtest$1.riskValidationService.validate(riskName, WALKER_METHOD_NAME_BACKGROUND);
14945
+ }
14894
14946
  const instance = this._getInstance(symbol, context.walkerName);
14895
14947
  return instance.background(symbol, context);
14896
14948
  };
@@ -14918,6 +14970,7 @@ class WalkerUtils {
14918
14970
  * ```
14919
14971
  */
14920
14972
  this.stop = async (symbol, walkerName) => {
14973
+ backtest$1.walkerValidationService.validate(walkerName, WALKER_METHOD_NAME_STOP);
14921
14974
  const instance = this._getInstance(symbol, walkerName);
14922
14975
  return await instance.stop(symbol, walkerName);
14923
14976
  };
@@ -14935,6 +14988,7 @@ class WalkerUtils {
14935
14988
  * ```
14936
14989
  */
14937
14990
  this.getData = async (symbol, walkerName) => {
14991
+ backtest$1.walkerValidationService.validate(walkerName, WALKER_METHOD_NAME_GET_DATA);
14938
14992
  const instance = this._getInstance(symbol, walkerName);
14939
14993
  return await instance.getData(symbol, walkerName);
14940
14994
  };
@@ -14952,6 +15006,7 @@ class WalkerUtils {
14952
15006
  * ```
14953
15007
  */
14954
15008
  this.getReport = async (symbol, walkerName) => {
15009
+ backtest$1.walkerValidationService.validate(walkerName, WALKER_METHOD_NAME_GET_REPORT);
14955
15010
  const instance = this._getInstance(symbol, walkerName);
14956
15011
  return await instance.getReport(symbol, walkerName);
14957
15012
  };
@@ -14972,6 +15027,7 @@ class WalkerUtils {
14972
15027
  * ```
14973
15028
  */
14974
15029
  this.dump = async (symbol, walkerName, path) => {
15030
+ backtest$1.walkerValidationService.validate(walkerName, WALKER_METHOD_NAME_DUMP);
14975
15031
  const instance = this._getInstance(symbol, walkerName);
14976
15032
  return await instance.dump(symbol, walkerName, path);
14977
15033
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backtest-kit",
3
- "version": "1.5.6",
3
+ "version": "1.5.8",
4
4
  "description": "A TypeScript library for trading system backtest",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
package/types.d.ts CHANGED
@@ -4711,7 +4711,7 @@ type TPersistBase = InstanceType<typeof PersistBase>;
4711
4711
  * Constructor type for PersistBase.
4712
4712
  * Used for custom persistence adapters.
4713
4713
  */
4714
- type TPersistBaseCtor<EntityName extends string = string, Entity extends IEntity = IEntity> = new (entityName: EntityName, baseDir: string) => IPersistBase<Entity>;
4714
+ type TPersistBaseCtor<EntityName extends string = string, Entity extends IEntity | null = IEntity> = new (entityName: EntityName, baseDir: string) => IPersistBase<Entity>;
4715
4715
  /**
4716
4716
  * Entity identifier - string or number.
4717
4717
  */
@@ -4725,7 +4725,7 @@ interface IEntity {
4725
4725
  * Persistence interface for CRUD operations.
4726
4726
  * Implemented by PersistBase.
4727
4727
  */
4728
- interface IPersistBase<Entity extends IEntity = IEntity> {
4728
+ interface IPersistBase<Entity extends IEntity | null = IEntity> {
4729
4729
  /**
4730
4730
  * Initialize persistence directory and validate existing files.
4731
4731
  * Uses singleshot to ensure one-time execution.