backtest-kit 9.8.0 → 9.8.1

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.mjs CHANGED
@@ -37392,7 +37392,19 @@ class BrokerProxy {
37392
37392
  */
37393
37393
  class BrokerAdapter {
37394
37394
  constructor() {
37395
- this._brokerInstance = null;
37395
+ /** Factory producing the active `BrokerProxy` instance */
37396
+ this._brokerFactory = () => null;
37397
+ /**
37398
+ * Lazily constructs the `BrokerProxy` from the registered factory and
37399
+ * memoizes the result via `singleshot`.
37400
+ *
37401
+ * The proxy is built on the first call and cached for all subsequent calls.
37402
+ * Returns `null` when no adapter has been registered via `useBrokerAdapter()`.
37403
+ *
37404
+ * Reset via `clear()` so the next call rebuilds from the current factory
37405
+ * (e.g. when `process.cwd()` changes between strategy iterations).
37406
+ */
37407
+ this.getInstance = singleshot(() => this._brokerFactory());
37396
37408
  /**
37397
37409
  * Forwards a signal-open event to the registered broker adapter.
37398
37410
  *
@@ -37426,7 +37438,10 @@ class BrokerAdapter {
37426
37438
  if (payload.backtest) {
37427
37439
  return;
37428
37440
  }
37429
- await this._brokerInstance?.onSignalOpenCommit(payload);
37441
+ const instance = this.getInstance();
37442
+ if (instance) {
37443
+ await instance.onSignalOpenCommit(payload);
37444
+ }
37430
37445
  };
37431
37446
  /**
37432
37447
  * Forwards a signal-close event to the registered broker adapter.
@@ -37464,7 +37479,10 @@ class BrokerAdapter {
37464
37479
  if (payload.backtest) {
37465
37480
  return;
37466
37481
  }
37467
- await this._brokerInstance?.onSignalCloseCommit(payload);
37482
+ const instance = this.getInstance();
37483
+ if (instance) {
37484
+ await instance.onSignalCloseCommit(payload);
37485
+ }
37468
37486
  };
37469
37487
  /**
37470
37488
  * Intercepts a partial-profit close before DI-core mutation.
@@ -37500,7 +37518,10 @@ class BrokerAdapter {
37500
37518
  if (payload.backtest) {
37501
37519
  return;
37502
37520
  }
37503
- await this._brokerInstance?.onPartialProfitCommit(payload);
37521
+ const instance = this.getInstance();
37522
+ if (instance) {
37523
+ await instance.onPartialProfitCommit(payload);
37524
+ }
37504
37525
  };
37505
37526
  /**
37506
37527
  * Intercepts a partial-loss close before DI-core mutation.
@@ -37536,7 +37557,10 @@ class BrokerAdapter {
37536
37557
  if (payload.backtest) {
37537
37558
  return;
37538
37559
  }
37539
- await this._brokerInstance?.onPartialLossCommit(payload);
37560
+ const instance = this.getInstance();
37561
+ if (instance) {
37562
+ await instance.onPartialLossCommit(payload);
37563
+ }
37540
37564
  };
37541
37565
  /**
37542
37566
  * Intercepts a trailing stop-loss update before DI-core mutation.
@@ -37572,7 +37596,10 @@ class BrokerAdapter {
37572
37596
  if (payload.backtest) {
37573
37597
  return;
37574
37598
  }
37575
- await this._brokerInstance?.onTrailingStopCommit(payload);
37599
+ const instance = this.getInstance();
37600
+ if (instance) {
37601
+ await instance.onTrailingStopCommit(payload);
37602
+ }
37576
37603
  };
37577
37604
  /**
37578
37605
  * Intercepts a trailing take-profit update before DI-core mutation.
@@ -37608,7 +37635,10 @@ class BrokerAdapter {
37608
37635
  if (payload.backtest) {
37609
37636
  return;
37610
37637
  }
37611
- await this._brokerInstance?.onTrailingTakeCommit(payload);
37638
+ const instance = this.getInstance();
37639
+ if (instance) {
37640
+ await instance.onTrailingTakeCommit(payload);
37641
+ }
37612
37642
  };
37613
37643
  /**
37614
37644
  * Intercepts a breakeven operation before DI-core mutation.
@@ -37645,7 +37675,10 @@ class BrokerAdapter {
37645
37675
  if (payload.backtest) {
37646
37676
  return;
37647
37677
  }
37648
- await this._brokerInstance?.onBreakevenCommit(payload);
37678
+ const instance = this.getInstance();
37679
+ if (instance) {
37680
+ await instance.onBreakevenCommit(payload);
37681
+ }
37649
37682
  };
37650
37683
  /**
37651
37684
  * Intercepts a DCA average-buy entry before DI-core mutation.
@@ -37681,7 +37714,10 @@ class BrokerAdapter {
37681
37714
  if (payload.backtest) {
37682
37715
  return;
37683
37716
  }
37684
- await this._brokerInstance?.onAverageBuyCommit(payload);
37717
+ const instance = this.getInstance();
37718
+ if (instance) {
37719
+ await instance.onAverageBuyCommit(payload);
37720
+ }
37685
37721
  };
37686
37722
  /**
37687
37723
  * Registers a broker adapter instance or constructor to receive commit* callbacks.
@@ -37705,11 +37741,12 @@ class BrokerAdapter {
37705
37741
  this.useBrokerAdapter = (broker) => {
37706
37742
  backtest.loggerService.info(BROKER_METHOD_NAME_USE_BROKER_ADAPTER, {});
37707
37743
  if (typeof broker === "function") {
37708
- const instance = Reflect.construct(broker, []);
37709
- this._brokerInstance = new BrokerProxy(instance);
37710
- return;
37744
+ this._brokerFactory = () => new BrokerProxy(Reflect.construct(broker, []));
37745
+ }
37746
+ else {
37747
+ this._brokerFactory = () => new BrokerProxy(broker);
37711
37748
  }
37712
- this._brokerInstance = new BrokerProxy(broker);
37749
+ this.getInstance.clear();
37713
37750
  };
37714
37751
  /**
37715
37752
  * Activates the broker: subscribes to syncSubject for signal-open / signal-close routing.
@@ -37736,7 +37773,8 @@ class BrokerAdapter {
37736
37773
  */
37737
37774
  this.enable = singleshot(() => {
37738
37775
  backtest.loggerService.info(BROKER_METHOD_NAME_ENABLE, {});
37739
- if (!this._brokerInstance) {
37776
+ const instance = this.getInstance();
37777
+ if (!instance) {
37740
37778
  this.enable.clear();
37741
37779
  throw new Error("No broker instance provided. Call Broker.useBrokerAdapter first.");
37742
37780
  }
@@ -37824,7 +37862,7 @@ class BrokerAdapter {
37824
37862
  */
37825
37863
  this.clear = () => {
37826
37864
  backtest.loggerService.info(BROKER_METHOD_NAME_CLEAR, {});
37827
- this._brokerInstance = null;
37865
+ this.getInstance.clear();
37828
37866
  this.enable.clear();
37829
37867
  };
37830
37868
  }
@@ -48844,8 +48882,16 @@ class RecentMemoryLiveUtils {
48844
48882
  */
48845
48883
  class RecentBacktestAdapter {
48846
48884
  constructor() {
48847
- /** Internal storage utils instance */
48848
- this._recentBacktestUtils = new RecentMemoryBacktestUtils();
48885
+ /** Factory producing the active storage utils instance */
48886
+ this._recentBacktestFactory = () => new RecentMemoryBacktestUtils();
48887
+ /**
48888
+ * Lazily constructs the storage utils from the registered factory and memoizes
48889
+ * the result via `singleshot`.
48890
+ *
48891
+ * The instance is built on the first call and cached for all subsequent calls.
48892
+ * Reset via `clear()` so the next call rebuilds from the current factory.
48893
+ */
48894
+ this.getInstance = singleshot(() => this._recentBacktestFactory());
48849
48895
  /**
48850
48896
  * Handles active ping event.
48851
48897
  * Proxies call to the underlying storage adapter.
@@ -48855,7 +48901,7 @@ class RecentBacktestAdapter {
48855
48901
  backtest.loggerService.info(RECENT_BACKTEST_ADAPTER_METHOD_NAME_HANDLE_ACTIVE_PING, {
48856
48902
  signalId: event.data.id,
48857
48903
  });
48858
- return await this._recentBacktestUtils.handleActivePing(event);
48904
+ return await this.getInstance().handleActivePing(event);
48859
48905
  };
48860
48906
  /**
48861
48907
  * Retrieves the latest signal for the given context.
@@ -48876,7 +48922,7 @@ class RecentBacktestAdapter {
48876
48922
  frameName,
48877
48923
  backtest: backtest$1,
48878
48924
  });
48879
- return await this._recentBacktestUtils.getLatestSignal(symbol, strategyName, exchangeName, frameName, backtest$1, when);
48925
+ return await this.getInstance().getLatestSignal(symbol, strategyName, exchangeName, frameName, backtest$1, when);
48880
48926
  };
48881
48927
  /**
48882
48928
  * Returns the number of whole minutes elapsed since the latest signal's creation timestamp.
@@ -48900,7 +48946,7 @@ class RecentBacktestAdapter {
48900
48946
  backtest: backtest$1,
48901
48947
  timestamp,
48902
48948
  });
48903
- const signal = await this._recentBacktestUtils.getLatestSignal(symbol, strategyName, exchangeName, frameName, backtest$1, new Date(timestamp));
48949
+ const signal = await this.getInstance().getLatestSignal(symbol, strategyName, exchangeName, frameName, backtest$1, new Date(timestamp));
48904
48950
  if (!signal) {
48905
48951
  return null;
48906
48952
  }
@@ -48913,7 +48959,8 @@ class RecentBacktestAdapter {
48913
48959
  */
48914
48960
  this.useRecentAdapter = (Ctor) => {
48915
48961
  backtest.loggerService.info(RECENT_BACKTEST_ADAPTER_METHOD_NAME_USE_ADAPTER);
48916
- this._recentBacktestUtils = Reflect.construct(Ctor, []);
48962
+ this._recentBacktestFactory = () => Reflect.construct(Ctor, []);
48963
+ this.getInstance.clear();
48917
48964
  };
48918
48965
  /**
48919
48966
  * Switches to persistent storage adapter.
@@ -48921,7 +48968,8 @@ class RecentBacktestAdapter {
48921
48968
  */
48922
48969
  this.usePersist = () => {
48923
48970
  backtest.loggerService.info(RECENT_BACKTEST_ADAPTER_METHOD_NAME_USE_PERSIST);
48924
- this._recentBacktestUtils = new RecentPersistBacktestUtils();
48971
+ this._recentBacktestFactory = () => new RecentPersistBacktestUtils();
48972
+ this.getInstance.clear();
48925
48973
  };
48926
48974
  /**
48927
48975
  * Switches to in-memory storage adapter (default).
@@ -48929,14 +48977,17 @@ class RecentBacktestAdapter {
48929
48977
  */
48930
48978
  this.useMemory = () => {
48931
48979
  backtest.loggerService.info(RECENT_BACKTEST_ADAPTER_METHOD_NAME_USE_MEMORY);
48932
- this._recentBacktestUtils = new RecentMemoryBacktestUtils();
48980
+ this._recentBacktestFactory = () => new RecentMemoryBacktestUtils();
48981
+ this.getInstance.clear();
48933
48982
  };
48934
48983
  /**
48935
- * Clears the cached utils instance by resetting to the default in-memory adapter.
48984
+ * Clears the memoized utils instance.
48985
+ * Call this when process.cwd() changes between strategy iterations
48986
+ * so a new instance is created with the updated base path.
48936
48987
  */
48937
48988
  this.clear = () => {
48938
48989
  backtest.loggerService.info(RECENT_BACKTEST_ADAPTER_METHOD_NAME_CLEAR);
48939
- this._recentBacktestUtils = new RecentMemoryBacktestUtils();
48990
+ this.getInstance.clear();
48940
48991
  };
48941
48992
  }
48942
48993
  }
@@ -48951,8 +49002,16 @@ class RecentBacktestAdapter {
48951
49002
  */
48952
49003
  class RecentLiveAdapter {
48953
49004
  constructor() {
48954
- /** Internal storage utils instance */
48955
- this._recentLiveUtils = new RecentPersistLiveUtils();
49005
+ /** Factory producing the active storage utils instance */
49006
+ this._recentLiveFactory = () => new RecentPersistLiveUtils();
49007
+ /**
49008
+ * Lazily constructs the storage utils from the registered factory and memoizes
49009
+ * the result via `singleshot`.
49010
+ *
49011
+ * The instance is built on the first call and cached for all subsequent calls.
49012
+ * Reset via `clear()` so the next call rebuilds from the current factory.
49013
+ */
49014
+ this.getInstance = singleshot(() => this._recentLiveFactory());
48956
49015
  /**
48957
49016
  * Handles active ping event.
48958
49017
  * Proxies call to the underlying storage adapter.
@@ -48962,7 +49021,7 @@ class RecentLiveAdapter {
48962
49021
  backtest.loggerService.info(RECENT_LIVE_ADAPTER_METHOD_NAME_HANDLE_ACTIVE_PING, {
48963
49022
  signalId: event.data.id,
48964
49023
  });
48965
- return await this._recentLiveUtils.handleActivePing(event);
49024
+ return await this.getInstance().handleActivePing(event);
48966
49025
  };
48967
49026
  /**
48968
49027
  * Retrieves the latest signal for the given context.
@@ -48983,7 +49042,7 @@ class RecentLiveAdapter {
48983
49042
  frameName,
48984
49043
  backtest: backtest$1,
48985
49044
  });
48986
- return await this._recentLiveUtils.getLatestSignal(symbol, strategyName, exchangeName, frameName, backtest$1, when);
49045
+ return await this.getInstance().getLatestSignal(symbol, strategyName, exchangeName, frameName, backtest$1, when);
48987
49046
  };
48988
49047
  /**
48989
49048
  * Returns the number of whole minutes elapsed since the latest signal's creation timestamp.
@@ -49007,7 +49066,7 @@ class RecentLiveAdapter {
49007
49066
  backtest: backtest$1,
49008
49067
  timestamp,
49009
49068
  });
49010
- const signal = await this._recentLiveUtils.getLatestSignal(symbol, strategyName, exchangeName, frameName, backtest$1, new Date(timestamp));
49069
+ const signal = await this.getInstance().getLatestSignal(symbol, strategyName, exchangeName, frameName, backtest$1, new Date(timestamp));
49011
49070
  if (!signal) {
49012
49071
  return null;
49013
49072
  }
@@ -49020,7 +49079,8 @@ class RecentLiveAdapter {
49020
49079
  */
49021
49080
  this.useRecentAdapter = (Ctor) => {
49022
49081
  backtest.loggerService.info(RECENT_LIVE_ADAPTER_METHOD_NAME_USE_ADAPTER);
49023
- this._recentLiveUtils = Reflect.construct(Ctor, []);
49082
+ this._recentLiveFactory = () => Reflect.construct(Ctor, []);
49083
+ this.getInstance.clear();
49024
49084
  };
49025
49085
  /**
49026
49086
  * Switches to persistent storage adapter (default).
@@ -49028,7 +49088,8 @@ class RecentLiveAdapter {
49028
49088
  */
49029
49089
  this.usePersist = () => {
49030
49090
  backtest.loggerService.info(RECENT_LIVE_ADAPTER_METHOD_NAME_USE_PERSIST);
49031
- this._recentLiveUtils = new RecentPersistLiveUtils();
49091
+ this._recentLiveFactory = () => new RecentPersistLiveUtils();
49092
+ this.getInstance.clear();
49032
49093
  };
49033
49094
  /**
49034
49095
  * Switches to in-memory storage adapter.
@@ -49036,14 +49097,17 @@ class RecentLiveAdapter {
49036
49097
  */
49037
49098
  this.useMemory = () => {
49038
49099
  backtest.loggerService.info(RECENT_LIVE_ADAPTER_METHOD_NAME_USE_MEMORY);
49039
- this._recentLiveUtils = new RecentMemoryLiveUtils();
49100
+ this._recentLiveFactory = () => new RecentMemoryLiveUtils();
49101
+ this.getInstance.clear();
49040
49102
  };
49041
49103
  /**
49042
- * Clears the cached utils instance by resetting to the default persistent adapter.
49104
+ * Clears the memoized utils instance.
49105
+ * Call this when process.cwd() changes between strategy iterations
49106
+ * so a new instance is created with the updated base path.
49043
49107
  */
49044
49108
  this.clear = () => {
49045
49109
  backtest.loggerService.info(RECENT_LIVE_ADAPTER_METHOD_NAME_CLEAR);
49046
- this._recentLiveUtils = new RecentPersistLiveUtils();
49110
+ this.getInstance.clear();
49047
49111
  };
49048
49112
  }
49049
49113
  }
@@ -54368,16 +54432,26 @@ class LogDummyUtils {
54368
54432
  */
54369
54433
  class LogAdapter {
54370
54434
  constructor() {
54371
- /** Internal log utils instance */
54372
- this._log = new LogMemoryUtils();
54435
+ /** Factory producing the active log utils instance */
54436
+ this._logFactory = () => new LogMemoryUtils();
54437
+ /**
54438
+ * Lazily constructs the log utils from the registered factory and memoizes
54439
+ * the result via `singleshot`.
54440
+ *
54441
+ * The instance is built on the first call and cached for all subsequent calls.
54442
+ * Reset via `clear()` so the next call rebuilds from the current factory
54443
+ * (e.g. when `process.cwd()` changes between strategy iterations).
54444
+ */
54445
+ this.getInstance = singleshot(() => this._logFactory());
54373
54446
  /**
54374
54447
  * Lists all stored log entries.
54375
54448
  * Proxies call to the underlying log adapter.
54376
54449
  * @returns Array of all log entries
54377
54450
  */
54378
54451
  this.getList = async () => {
54379
- if (this._log.getList) {
54380
- return await this._log.getList();
54452
+ const log = this.getInstance();
54453
+ if (log.getList) {
54454
+ return await log.getList();
54381
54455
  }
54382
54456
  return [];
54383
54457
  };
@@ -54388,8 +54462,9 @@ class LogAdapter {
54388
54462
  * @param args - Additional arguments
54389
54463
  */
54390
54464
  this.log = (topic, ...args) => {
54391
- if (this._log.log) {
54392
- this._log.log(topic, ...args);
54465
+ const log = this.getInstance();
54466
+ if (log.log) {
54467
+ log.log(topic, ...args);
54393
54468
  }
54394
54469
  };
54395
54470
  /**
@@ -54399,8 +54474,9 @@ class LogAdapter {
54399
54474
  * @param args - Additional arguments
54400
54475
  */
54401
54476
  this.debug = (topic, ...args) => {
54402
- if (this._log.debug) {
54403
- this._log.debug(topic, ...args);
54477
+ const log = this.getInstance();
54478
+ if (log.debug) {
54479
+ log.debug(topic, ...args);
54404
54480
  }
54405
54481
  };
54406
54482
  /**
@@ -54410,8 +54486,9 @@ class LogAdapter {
54410
54486
  * @param args - Additional arguments
54411
54487
  */
54412
54488
  this.info = (topic, ...args) => {
54413
- if (this._log.info) {
54414
- this._log.info(topic, ...args);
54489
+ const log = this.getInstance();
54490
+ if (log.info) {
54491
+ log.info(topic, ...args);
54415
54492
  }
54416
54493
  };
54417
54494
  /**
@@ -54421,8 +54498,9 @@ class LogAdapter {
54421
54498
  * @param args - Additional arguments
54422
54499
  */
54423
54500
  this.warn = (topic, ...args) => {
54424
- if (this._log.warn) {
54425
- this._log.warn(topic, ...args);
54501
+ const log = this.getInstance();
54502
+ if (log.warn) {
54503
+ log.warn(topic, ...args);
54426
54504
  }
54427
54505
  };
54428
54506
  /**
@@ -54432,7 +54510,8 @@ class LogAdapter {
54432
54510
  */
54433
54511
  this.useLogger = (Ctor) => {
54434
54512
  backtest.loggerService.info(LOG_ADAPTER_METHOD_NAME_USE_LOGGER);
54435
- this._log = Reflect.construct(Ctor, []);
54513
+ this._logFactory = () => Reflect.construct(Ctor, []);
54514
+ this.getInstance.clear();
54436
54515
  };
54437
54516
  /**
54438
54517
  * Switches to persistent log adapter.
@@ -54440,7 +54519,8 @@ class LogAdapter {
54440
54519
  */
54441
54520
  this.usePersist = () => {
54442
54521
  backtest.loggerService.info(LOG_ADAPTER_METHOD_NAME_USE_PERSIST);
54443
- this._log = new LogPersistUtils();
54522
+ this._logFactory = () => new LogPersistUtils();
54523
+ this.getInstance.clear();
54444
54524
  };
54445
54525
  /**
54446
54526
  * Switches to in-memory log adapter (default).
@@ -54448,7 +54528,8 @@ class LogAdapter {
54448
54528
  */
54449
54529
  this.useMemory = () => {
54450
54530
  backtest.loggerService.info(LOG_ADAPTER_METHOD_NAME_USE_MEMORY);
54451
- this._log = new LogMemoryUtils();
54531
+ this._logFactory = () => new LogMemoryUtils();
54532
+ this.getInstance.clear();
54452
54533
  };
54453
54534
  /**
54454
54535
  * Switches to dummy log adapter.
@@ -54456,7 +54537,8 @@ class LogAdapter {
54456
54537
  */
54457
54538
  this.useDummy = () => {
54458
54539
  backtest.loggerService.info(LOG_ADAPTER_METHOD_NAME_USE_DUMMY);
54459
- this._log = new LogDummyUtils();
54540
+ this._logFactory = () => new LogDummyUtils();
54541
+ this.getInstance.clear();
54460
54542
  };
54461
54543
  /**
54462
54544
  * Switches to JSONL file log adapter.
@@ -54466,18 +54548,22 @@ class LogAdapter {
54466
54548
  * @param fileName - Base file name without extension (default: "log")
54467
54549
  * @param dirName - Directory for the JSONL file (default: ./dump/log)
54468
54550
  */
54469
- this.useJsonl = (fileName = "log.jsonl", dirName = join(process.cwd(), "./dump/log")) => {
54551
+ this.useJsonl = (fileName = "log.jsonl", dirName) => {
54470
54552
  backtest.loggerService.info(LOG_ADAPTER_METHOD_NAME_USE_JSONL);
54471
- this._log = new LogJsonlUtils(fileName, dirName);
54553
+ this._logFactory = () => {
54554
+ const dir = dirName || join(process.cwd(), "./dump/log");
54555
+ return new LogJsonlUtils(fileName, dir);
54556
+ };
54557
+ this.getInstance.clear();
54472
54558
  };
54473
54559
  /**
54474
- * Clears the cached log instance by resetting to the default in-memory adapter.
54560
+ * Clears the memoized log instance.
54475
54561
  * Call this when process.cwd() changes between strategy iterations
54476
54562
  * so a new adapter instance is created with the updated base path.
54477
54563
  */
54478
54564
  this.clear = () => {
54479
54565
  backtest.loggerService.info(LOG_ADAPTER_METHOD_NAME_CLEAR);
54480
- this._log = new LogMemoryUtils();
54566
+ this.getInstance.clear();
54481
54567
  };
54482
54568
  }
54483
54569
  }
@@ -58369,15 +58455,23 @@ class StorageDummyLiveUtils {
58369
58455
  */
58370
58456
  class StorageBacktestAdapter {
58371
58457
  constructor() {
58372
- /** Internal storage utils instance */
58373
- this._signalBacktestUtils = new StorageMemoryBacktestUtils();
58458
+ /** Factory producing the active storage utils instance */
58459
+ this._signalBacktestFactory = () => new StorageMemoryBacktestUtils();
58460
+ /**
58461
+ * Lazily constructs the storage utils from the registered factory and memoizes
58462
+ * the result via `singleshot`.
58463
+ *
58464
+ * The instance is built on the first call and cached for all subsequent calls.
58465
+ * Reset via `clear()` so the next call rebuilds from the current factory.
58466
+ */
58467
+ this.getInstance = singleshot(() => this._signalBacktestFactory());
58374
58468
  /**
58375
58469
  * Handles signal opened event.
58376
58470
  * Proxies call to the underlying storage adapter.
58377
58471
  * @param tick - The opened signal tick data
58378
58472
  */
58379
58473
  this.handleOpened = async (tick) => {
58380
- return await this._signalBacktestUtils.handleOpened(tick);
58474
+ return await this.getInstance().handleOpened(tick);
58381
58475
  };
58382
58476
  /**
58383
58477
  * Handles signal closed event.
@@ -58385,7 +58479,7 @@ class StorageBacktestAdapter {
58385
58479
  * @param tick - The closed signal tick data
58386
58480
  */
58387
58481
  this.handleClosed = async (tick) => {
58388
- return await this._signalBacktestUtils.handleClosed(tick);
58482
+ return await this.getInstance().handleClosed(tick);
58389
58483
  };
58390
58484
  /**
58391
58485
  * Handles signal scheduled event.
@@ -58393,7 +58487,7 @@ class StorageBacktestAdapter {
58393
58487
  * @param tick - The scheduled signal tick data
58394
58488
  */
58395
58489
  this.handleScheduled = async (tick) => {
58396
- return await this._signalBacktestUtils.handleScheduled(tick);
58490
+ return await this.getInstance().handleScheduled(tick);
58397
58491
  };
58398
58492
  /**
58399
58493
  * Handles signal cancelled event.
@@ -58401,7 +58495,7 @@ class StorageBacktestAdapter {
58401
58495
  * @param tick - The cancelled signal tick data
58402
58496
  */
58403
58497
  this.handleCancelled = async (tick) => {
58404
- return await this._signalBacktestUtils.handleCancelled(tick);
58498
+ return await this.getInstance().handleCancelled(tick);
58405
58499
  };
58406
58500
  /**
58407
58501
  * Finds a signal by its ID.
@@ -58410,7 +58504,7 @@ class StorageBacktestAdapter {
58410
58504
  * @returns The signal row or null if not found
58411
58505
  */
58412
58506
  this.findById = async (id) => {
58413
- return await this._signalBacktestUtils.findById(id);
58507
+ return await this.getInstance().findById(id);
58414
58508
  };
58415
58509
  /**
58416
58510
  * Lists all stored signals.
@@ -58418,13 +58512,13 @@ class StorageBacktestAdapter {
58418
58512
  * @returns Array of all signal rows
58419
58513
  */
58420
58514
  this.list = async () => {
58421
- return await this._signalBacktestUtils.list();
58515
+ return await this.getInstance().list();
58422
58516
  };
58423
58517
  this.handleActivePing = async (event) => {
58424
- return await this._signalBacktestUtils.handleActivePing(event);
58518
+ return await this.getInstance().handleActivePing(event);
58425
58519
  };
58426
58520
  this.handleSchedulePing = async (event) => {
58427
- return await this._signalBacktestUtils.handleSchedulePing(event);
58521
+ return await this.getInstance().handleSchedulePing(event);
58428
58522
  };
58429
58523
  /**
58430
58524
  * Sets the storage adapter constructor.
@@ -58434,7 +58528,8 @@ class StorageBacktestAdapter {
58434
58528
  */
58435
58529
  this.useStorageAdapter = (Ctor) => {
58436
58530
  backtest.loggerService.info(STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_ADAPTER);
58437
- this._signalBacktestUtils = Reflect.construct(Ctor, []);
58531
+ this._signalBacktestFactory = () => Reflect.construct(Ctor, []);
58532
+ this.getInstance.clear();
58438
58533
  };
58439
58534
  /**
58440
58535
  * Switches to dummy storage adapter.
@@ -58442,7 +58537,8 @@ class StorageBacktestAdapter {
58442
58537
  */
58443
58538
  this.useDummy = () => {
58444
58539
  backtest.loggerService.info(STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_DUMMY);
58445
- this._signalBacktestUtils = new StorageDummyBacktestUtils();
58540
+ this._signalBacktestFactory = () => new StorageDummyBacktestUtils();
58541
+ this.getInstance.clear();
58446
58542
  };
58447
58543
  /**
58448
58544
  * Switches to persistent storage adapter (default).
@@ -58450,7 +58546,8 @@ class StorageBacktestAdapter {
58450
58546
  */
58451
58547
  this.usePersist = () => {
58452
58548
  backtest.loggerService.info(STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_PERSIST);
58453
- this._signalBacktestUtils = new StoragePersistBacktestUtils();
58549
+ this._signalBacktestFactory = () => new StoragePersistBacktestUtils();
58550
+ this.getInstance.clear();
58454
58551
  };
58455
58552
  /**
58456
58553
  * Switches to in-memory storage adapter.
@@ -58458,16 +58555,17 @@ class StorageBacktestAdapter {
58458
58555
  */
58459
58556
  this.useMemory = () => {
58460
58557
  backtest.loggerService.info(STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_MEMORY);
58461
- this._signalBacktestUtils = new StorageMemoryBacktestUtils();
58558
+ this._signalBacktestFactory = () => new StorageMemoryBacktestUtils();
58559
+ this.getInstance.clear();
58462
58560
  };
58463
58561
  /**
58464
- * Clears the cached utils instance by resetting to the default in-memory adapter.
58562
+ * Clears the memoized utils instance.
58465
58563
  * Call this when process.cwd() changes between strategy iterations
58466
58564
  * so a new instance is created with the updated base path.
58467
58565
  */
58468
58566
  this.clear = () => {
58469
58567
  backtest.loggerService.info(STORAGE_BACKTEST_ADAPTER_METHOD_NAME_CLEAR);
58470
- this._signalBacktestUtils = new StorageMemoryBacktestUtils();
58568
+ this.getInstance.clear();
58471
58569
  };
58472
58570
  }
58473
58571
  }
@@ -58482,15 +58580,23 @@ class StorageBacktestAdapter {
58482
58580
  */
58483
58581
  class StorageLiveAdapter {
58484
58582
  constructor() {
58485
- /** Internal storage utils instance */
58486
- this._signalLiveUtils = new StoragePersistLiveUtils();
58583
+ /** Factory producing the active storage utils instance */
58584
+ this._signalLiveFactory = () => new StoragePersistLiveUtils();
58585
+ /**
58586
+ * Lazily constructs the storage utils from the registered factory and memoizes
58587
+ * the result via `singleshot`.
58588
+ *
58589
+ * The instance is built on the first call and cached for all subsequent calls.
58590
+ * Reset via `clear()` so the next call rebuilds from the current factory.
58591
+ */
58592
+ this.getInstance = singleshot(() => this._signalLiveFactory());
58487
58593
  /**
58488
58594
  * Handles signal opened event.
58489
58595
  * Proxies call to the underlying storage adapter.
58490
58596
  * @param tick - The opened signal tick data
58491
58597
  */
58492
58598
  this.handleOpened = async (tick) => {
58493
- return await this._signalLiveUtils.handleOpened(tick);
58599
+ return await this.getInstance().handleOpened(tick);
58494
58600
  };
58495
58601
  /**
58496
58602
  * Handles signal closed event.
@@ -58498,7 +58604,7 @@ class StorageLiveAdapter {
58498
58604
  * @param tick - The closed signal tick data
58499
58605
  */
58500
58606
  this.handleClosed = async (tick) => {
58501
- return await this._signalLiveUtils.handleClosed(tick);
58607
+ return await this.getInstance().handleClosed(tick);
58502
58608
  };
58503
58609
  /**
58504
58610
  * Handles signal scheduled event.
@@ -58506,7 +58612,7 @@ class StorageLiveAdapter {
58506
58612
  * @param tick - The scheduled signal tick data
58507
58613
  */
58508
58614
  this.handleScheduled = async (tick) => {
58509
- return await this._signalLiveUtils.handleScheduled(tick);
58615
+ return await this.getInstance().handleScheduled(tick);
58510
58616
  };
58511
58617
  /**
58512
58618
  * Handles signal cancelled event.
@@ -58514,7 +58620,7 @@ class StorageLiveAdapter {
58514
58620
  * @param tick - The cancelled signal tick data
58515
58621
  */
58516
58622
  this.handleCancelled = async (tick) => {
58517
- return await this._signalLiveUtils.handleCancelled(tick);
58623
+ return await this.getInstance().handleCancelled(tick);
58518
58624
  };
58519
58625
  /**
58520
58626
  * Finds a signal by its ID.
@@ -58523,7 +58629,7 @@ class StorageLiveAdapter {
58523
58629
  * @returns The signal row or null if not found
58524
58630
  */
58525
58631
  this.findById = async (id) => {
58526
- return await this._signalLiveUtils.findById(id);
58632
+ return await this.getInstance().findById(id);
58527
58633
  };
58528
58634
  /**
58529
58635
  * Lists all stored signals.
@@ -58531,13 +58637,13 @@ class StorageLiveAdapter {
58531
58637
  * @returns Array of all signal rows
58532
58638
  */
58533
58639
  this.list = async () => {
58534
- return await this._signalLiveUtils.list();
58640
+ return await this.getInstance().list();
58535
58641
  };
58536
58642
  this.handleActivePing = async (event) => {
58537
- return await this._signalLiveUtils.handleActivePing(event);
58643
+ return await this.getInstance().handleActivePing(event);
58538
58644
  };
58539
58645
  this.handleSchedulePing = async (event) => {
58540
- return await this._signalLiveUtils.handleSchedulePing(event);
58646
+ return await this.getInstance().handleSchedulePing(event);
58541
58647
  };
58542
58648
  /**
58543
58649
  * Sets the storage adapter constructor.
@@ -58547,7 +58653,8 @@ class StorageLiveAdapter {
58547
58653
  */
58548
58654
  this.useStorageAdapter = (Ctor) => {
58549
58655
  backtest.loggerService.info(STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_ADAPTER);
58550
- this._signalLiveUtils = Reflect.construct(Ctor, []);
58656
+ this._signalLiveFactory = () => Reflect.construct(Ctor, []);
58657
+ this.getInstance.clear();
58551
58658
  };
58552
58659
  /**
58553
58660
  * Switches to dummy storage adapter.
@@ -58555,7 +58662,8 @@ class StorageLiveAdapter {
58555
58662
  */
58556
58663
  this.useDummy = () => {
58557
58664
  backtest.loggerService.info(STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_DUMMY);
58558
- this._signalLiveUtils = new StorageDummyLiveUtils();
58665
+ this._signalLiveFactory = () => new StorageDummyLiveUtils();
58666
+ this.getInstance.clear();
58559
58667
  };
58560
58668
  /**
58561
58669
  * Switches to persistent storage adapter (default).
@@ -58563,7 +58671,8 @@ class StorageLiveAdapter {
58563
58671
  */
58564
58672
  this.usePersist = () => {
58565
58673
  backtest.loggerService.info(STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_PERSIST);
58566
- this._signalLiveUtils = new StoragePersistLiveUtils();
58674
+ this._signalLiveFactory = () => new StoragePersistLiveUtils();
58675
+ this.getInstance.clear();
58567
58676
  };
58568
58677
  /**
58569
58678
  * Switches to in-memory storage adapter.
@@ -58571,16 +58680,17 @@ class StorageLiveAdapter {
58571
58680
  */
58572
58681
  this.useMemory = () => {
58573
58682
  backtest.loggerService.info(STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_MEMORY);
58574
- this._signalLiveUtils = new StorageMemoryLiveUtils();
58683
+ this._signalLiveFactory = () => new StorageMemoryLiveUtils();
58684
+ this.getInstance.clear();
58575
58685
  };
58576
58686
  /**
58577
- * Clears the cached utils instance by resetting to the default persistent adapter.
58687
+ * Clears the memoized utils instance.
58578
58688
  * Call this when process.cwd() changes between strategy iterations
58579
58689
  * so a new instance is created with the updated base path.
58580
58690
  */
58581
58691
  this.clear = () => {
58582
58692
  backtest.loggerService.info(STORAGE_LIVE_ADAPTER_METHOD_NAME_CLEAR);
58583
- this._signalLiveUtils = new StoragePersistLiveUtils();
58693
+ this.getInstance.clear();
58584
58694
  };
58585
58695
  }
58586
58696
  }
@@ -60696,18 +60806,26 @@ class NotificationPersistLiveUtils {
60696
60806
  */
60697
60807
  class NotificationBacktestAdapter {
60698
60808
  constructor() {
60699
- /** Internal notification utils instance */
60700
- this._notificationBacktestUtils = new NotificationMemoryBacktestUtils();
60809
+ /** Factory producing the active notification utils instance */
60810
+ this._notificationBacktestFactory = () => new NotificationMemoryBacktestUtils();
60811
+ /**
60812
+ * Lazily constructs the notification utils from the registered factory and
60813
+ * memoizes the result via `singleshot`.
60814
+ *
60815
+ * The instance is built on the first call and cached for all subsequent calls.
60816
+ * Reset via `clear()` so the next call rebuilds from the current factory.
60817
+ */
60818
+ this.getInstance = singleshot(() => this._notificationBacktestFactory());
60701
60819
  /**
60702
60820
  * Handles signal events.
60703
60821
  * Proxies call to the underlying notification adapter.
60704
60822
  * @param data - The strategy tick result data
60705
60823
  */
60706
60824
  this.handleSignal = async (data) => {
60707
- return await this._notificationBacktestUtils.handleSignal(data);
60825
+ return await this.getInstance().handleSignal(data);
60708
60826
  };
60709
60827
  this.handleSignalNotify = async (data) => {
60710
- return await this._notificationBacktestUtils.handleSignalNotify(data);
60828
+ return await this.getInstance().handleSignalNotify(data);
60711
60829
  };
60712
60830
  /**
60713
60831
  * Handles partial profit availability event.
@@ -60715,7 +60833,7 @@ class NotificationBacktestAdapter {
60715
60833
  * @param data - The partial profit contract data
60716
60834
  */
60717
60835
  this.handlePartialProfit = async (data) => {
60718
- return await this._notificationBacktestUtils.handlePartialProfit(data);
60836
+ return await this.getInstance().handlePartialProfit(data);
60719
60837
  };
60720
60838
  /**
60721
60839
  * Handles partial loss availability event.
@@ -60723,7 +60841,7 @@ class NotificationBacktestAdapter {
60723
60841
  * @param data - The partial loss contract data
60724
60842
  */
60725
60843
  this.handlePartialLoss = async (data) => {
60726
- return await this._notificationBacktestUtils.handlePartialLoss(data);
60844
+ return await this.getInstance().handlePartialLoss(data);
60727
60845
  };
60728
60846
  /**
60729
60847
  * Handles breakeven availability event.
@@ -60731,7 +60849,7 @@ class NotificationBacktestAdapter {
60731
60849
  * @param data - The breakeven contract data
60732
60850
  */
60733
60851
  this.handleBreakeven = async (data) => {
60734
- return await this._notificationBacktestUtils.handleBreakeven(data);
60852
+ return await this.getInstance().handleBreakeven(data);
60735
60853
  };
60736
60854
  /**
60737
60855
  * Handles strategy commit events.
@@ -60739,7 +60857,7 @@ class NotificationBacktestAdapter {
60739
60857
  * @param data - The strategy commit contract data
60740
60858
  */
60741
60859
  this.handleStrategyCommit = async (data) => {
60742
- return await this._notificationBacktestUtils.handleStrategyCommit(data);
60860
+ return await this.getInstance().handleStrategyCommit(data);
60743
60861
  };
60744
60862
  /**
60745
60863
  * Handles signal sync events (signal-open, signal-close).
@@ -60747,7 +60865,7 @@ class NotificationBacktestAdapter {
60747
60865
  * @param data - The signal sync contract data
60748
60866
  */
60749
60867
  this.handleSync = trycatch(async (data) => {
60750
- return await this._notificationBacktestUtils.handleSync(data);
60868
+ return await this.getInstance().handleSync(data);
60751
60869
  }, {
60752
60870
  defaultValue: null,
60753
60871
  });
@@ -60757,7 +60875,7 @@ class NotificationBacktestAdapter {
60757
60875
  * @param data - The risk contract data
60758
60876
  */
60759
60877
  this.handleRisk = async (data) => {
60760
- return await this._notificationBacktestUtils.handleRisk(data);
60878
+ return await this.getInstance().handleRisk(data);
60761
60879
  };
60762
60880
  /**
60763
60881
  * Handles error event.
@@ -60765,7 +60883,7 @@ class NotificationBacktestAdapter {
60765
60883
  * @param error - The error object
60766
60884
  */
60767
60885
  this.handleError = async (error) => {
60768
- return await this._notificationBacktestUtils.handleError(error);
60886
+ return await this.getInstance().handleError(error);
60769
60887
  };
60770
60888
  /**
60771
60889
  * Handles critical error event.
@@ -60773,7 +60891,7 @@ class NotificationBacktestAdapter {
60773
60891
  * @param error - The error object
60774
60892
  */
60775
60893
  this.handleCriticalError = async (error) => {
60776
- return await this._notificationBacktestUtils.handleCriticalError(error);
60894
+ return await this.getInstance().handleCriticalError(error);
60777
60895
  };
60778
60896
  /**
60779
60897
  * Handles validation error event.
@@ -60781,7 +60899,7 @@ class NotificationBacktestAdapter {
60781
60899
  * @param error - The error object
60782
60900
  */
60783
60901
  this.handleValidationError = async (error) => {
60784
- return await this._notificationBacktestUtils.handleValidationError(error);
60902
+ return await this.getInstance().handleValidationError(error);
60785
60903
  };
60786
60904
  /**
60787
60905
  * Gets all stored notifications.
@@ -60789,14 +60907,14 @@ class NotificationBacktestAdapter {
60789
60907
  * @returns Array of all notification models
60790
60908
  */
60791
60909
  this.getData = async () => {
60792
- return await this._notificationBacktestUtils.getData();
60910
+ return await this.getInstance().getData();
60793
60911
  };
60794
60912
  /**
60795
60913
  * Clears all stored notifications.
60796
60914
  * Proxies call to the underlying notification adapter.
60797
60915
  */
60798
60916
  this.dispose = async () => {
60799
- return await this._notificationBacktestUtils.dispose();
60917
+ return await this.getInstance().dispose();
60800
60918
  };
60801
60919
  /**
60802
60920
  * Sets the notification adapter constructor.
@@ -60806,7 +60924,8 @@ class NotificationBacktestAdapter {
60806
60924
  */
60807
60925
  this.useNotificationAdapter = (Ctor) => {
60808
60926
  backtest.loggerService.info(NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_ADAPTER);
60809
- this._notificationBacktestUtils = Reflect.construct(Ctor, []);
60927
+ this._notificationBacktestFactory = () => Reflect.construct(Ctor, []);
60928
+ this.getInstance.clear();
60810
60929
  };
60811
60930
  /**
60812
60931
  * Switches to dummy notification adapter.
@@ -60814,7 +60933,8 @@ class NotificationBacktestAdapter {
60814
60933
  */
60815
60934
  this.useDummy = () => {
60816
60935
  backtest.loggerService.info(NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_DUMMY);
60817
- this._notificationBacktestUtils = new NotificationDummyBacktestUtils();
60936
+ this._notificationBacktestFactory = () => new NotificationDummyBacktestUtils();
60937
+ this.getInstance.clear();
60818
60938
  };
60819
60939
  /**
60820
60940
  * Switches to in-memory notification adapter (default).
@@ -60822,7 +60942,8 @@ class NotificationBacktestAdapter {
60822
60942
  */
60823
60943
  this.useMemory = () => {
60824
60944
  backtest.loggerService.info(NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_MEMORY);
60825
- this._notificationBacktestUtils = new NotificationMemoryBacktestUtils();
60945
+ this._notificationBacktestFactory = () => new NotificationMemoryBacktestUtils();
60946
+ this.getInstance.clear();
60826
60947
  };
60827
60948
  /**
60828
60949
  * Switches to persistent notification adapter.
@@ -60830,16 +60951,17 @@ class NotificationBacktestAdapter {
60830
60951
  */
60831
60952
  this.usePersist = () => {
60832
60953
  backtest.loggerService.info(NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_PERSIST);
60833
- this._notificationBacktestUtils = new NotificationPersistBacktestUtils();
60954
+ this._notificationBacktestFactory = () => new NotificationPersistBacktestUtils();
60955
+ this.getInstance.clear();
60834
60956
  };
60835
60957
  /**
60836
- * Resets the cached utils instance to the default in-memory adapter.
60958
+ * Clears the memoized utils instance.
60837
60959
  * Call this when process.cwd() changes between strategy iterations
60838
60960
  * so a new instance is created with the updated base path.
60839
60961
  */
60840
60962
  this.clear = () => {
60841
60963
  backtest.loggerService.info(NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_CLEAR);
60842
- this._notificationBacktestUtils = new NotificationMemoryBacktestUtils();
60964
+ this.getInstance.clear();
60843
60965
  };
60844
60966
  }
60845
60967
  }
@@ -60854,18 +60976,26 @@ class NotificationBacktestAdapter {
60854
60976
  */
60855
60977
  class NotificationLiveAdapter {
60856
60978
  constructor() {
60857
- /** Internal notification utils instance */
60858
- this._notificationLiveUtils = new NotificationMemoryLiveUtils();
60979
+ /** Factory producing the active notification utils instance */
60980
+ this._notificationLiveFactory = () => new NotificationMemoryLiveUtils();
60981
+ /**
60982
+ * Lazily constructs the notification utils from the registered factory and
60983
+ * memoizes the result via `singleshot`.
60984
+ *
60985
+ * The instance is built on the first call and cached for all subsequent calls.
60986
+ * Reset via `clear()` so the next call rebuilds from the current factory.
60987
+ */
60988
+ this.getInstance = singleshot(() => this._notificationLiveFactory());
60859
60989
  /**
60860
60990
  * Handles signal events.
60861
60991
  * Proxies call to the underlying notification adapter.
60862
60992
  * @param data - The strategy tick result data
60863
60993
  */
60864
60994
  this.handleSignal = async (data) => {
60865
- return await this._notificationLiveUtils.handleSignal(data);
60995
+ return await this.getInstance().handleSignal(data);
60866
60996
  };
60867
60997
  this.handleSignalNotify = async (data) => {
60868
- return await this._notificationLiveUtils.handleSignalNotify(data);
60998
+ return await this.getInstance().handleSignalNotify(data);
60869
60999
  };
60870
61000
  /**
60871
61001
  * Handles partial profit availability event.
@@ -60873,7 +61003,7 @@ class NotificationLiveAdapter {
60873
61003
  * @param data - The partial profit contract data
60874
61004
  */
60875
61005
  this.handlePartialProfit = async (data) => {
60876
- return await this._notificationLiveUtils.handlePartialProfit(data);
61006
+ return await this.getInstance().handlePartialProfit(data);
60877
61007
  };
60878
61008
  /**
60879
61009
  * Handles partial loss availability event.
@@ -60881,7 +61011,7 @@ class NotificationLiveAdapter {
60881
61011
  * @param data - The partial loss contract data
60882
61012
  */
60883
61013
  this.handlePartialLoss = async (data) => {
60884
- return await this._notificationLiveUtils.handlePartialLoss(data);
61014
+ return await this.getInstance().handlePartialLoss(data);
60885
61015
  };
60886
61016
  /**
60887
61017
  * Handles breakeven availability event.
@@ -60889,7 +61019,7 @@ class NotificationLiveAdapter {
60889
61019
  * @param data - The breakeven contract data
60890
61020
  */
60891
61021
  this.handleBreakeven = async (data) => {
60892
- return await this._notificationLiveUtils.handleBreakeven(data);
61022
+ return await this.getInstance().handleBreakeven(data);
60893
61023
  };
60894
61024
  /**
60895
61025
  * Handles strategy commit events.
@@ -60897,7 +61027,7 @@ class NotificationLiveAdapter {
60897
61027
  * @param data - The strategy commit contract data
60898
61028
  */
60899
61029
  this.handleStrategyCommit = async (data) => {
60900
- return await this._notificationLiveUtils.handleStrategyCommit(data);
61030
+ return await this.getInstance().handleStrategyCommit(data);
60901
61031
  };
60902
61032
  /**
60903
61033
  * Handles signal sync events (signal-open, signal-close).
@@ -60905,7 +61035,7 @@ class NotificationLiveAdapter {
60905
61035
  * @param data - The signal sync contract data
60906
61036
  */
60907
61037
  this.handleSync = trycatch(async (data) => {
60908
- return await this._notificationLiveUtils.handleSync(data);
61038
+ return await this.getInstance().handleSync(data);
60909
61039
  }, {
60910
61040
  defaultValue: null,
60911
61041
  });
@@ -60915,7 +61045,7 @@ class NotificationLiveAdapter {
60915
61045
  * @param data - The risk contract data
60916
61046
  */
60917
61047
  this.handleRisk = async (data) => {
60918
- return await this._notificationLiveUtils.handleRisk(data);
61048
+ return await this.getInstance().handleRisk(data);
60919
61049
  };
60920
61050
  /**
60921
61051
  * Handles error event.
@@ -60923,7 +61053,7 @@ class NotificationLiveAdapter {
60923
61053
  * @param error - The error object
60924
61054
  */
60925
61055
  this.handleError = async (error) => {
60926
- return await this._notificationLiveUtils.handleError(error);
61056
+ return await this.getInstance().handleError(error);
60927
61057
  };
60928
61058
  /**
60929
61059
  * Handles critical error event.
@@ -60931,7 +61061,7 @@ class NotificationLiveAdapter {
60931
61061
  * @param error - The error object
60932
61062
  */
60933
61063
  this.handleCriticalError = async (error) => {
60934
- return await this._notificationLiveUtils.handleCriticalError(error);
61064
+ return await this.getInstance().handleCriticalError(error);
60935
61065
  };
60936
61066
  /**
60937
61067
  * Handles validation error event.
@@ -60939,7 +61069,7 @@ class NotificationLiveAdapter {
60939
61069
  * @param error - The error object
60940
61070
  */
60941
61071
  this.handleValidationError = async (error) => {
60942
- return await this._notificationLiveUtils.handleValidationError(error);
61072
+ return await this.getInstance().handleValidationError(error);
60943
61073
  };
60944
61074
  /**
60945
61075
  * Gets all stored notifications.
@@ -60947,14 +61077,14 @@ class NotificationLiveAdapter {
60947
61077
  * @returns Array of all notification models
60948
61078
  */
60949
61079
  this.getData = async () => {
60950
- return await this._notificationLiveUtils.getData();
61080
+ return await this.getInstance().getData();
60951
61081
  };
60952
61082
  /**
60953
61083
  * Clears all stored notifications.
60954
61084
  * Proxies call to the underlying notification adapter.
60955
61085
  */
60956
61086
  this.dispose = async () => {
60957
- return await this._notificationLiveUtils.dispose();
61087
+ return await this.getInstance().dispose();
60958
61088
  };
60959
61089
  /**
60960
61090
  * Sets the notification adapter constructor.
@@ -60964,7 +61094,8 @@ class NotificationLiveAdapter {
60964
61094
  */
60965
61095
  this.useNotificationAdapter = (Ctor) => {
60966
61096
  backtest.loggerService.info(NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_ADAPTER);
60967
- this._notificationLiveUtils = Reflect.construct(Ctor, []);
61097
+ this._notificationLiveFactory = () => Reflect.construct(Ctor, []);
61098
+ this.getInstance.clear();
60968
61099
  };
60969
61100
  /**
60970
61101
  * Switches to dummy notification adapter.
@@ -60972,7 +61103,8 @@ class NotificationLiveAdapter {
60972
61103
  */
60973
61104
  this.useDummy = () => {
60974
61105
  backtest.loggerService.info(NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_DUMMY);
60975
- this._notificationLiveUtils = new NotificationDummyLiveUtils();
61106
+ this._notificationLiveFactory = () => new NotificationDummyLiveUtils();
61107
+ this.getInstance.clear();
60976
61108
  };
60977
61109
  /**
60978
61110
  * Switches to in-memory notification adapter (default).
@@ -60980,7 +61112,8 @@ class NotificationLiveAdapter {
60980
61112
  */
60981
61113
  this.useMemory = () => {
60982
61114
  backtest.loggerService.info(NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_MEMORY);
60983
- this._notificationLiveUtils = new NotificationMemoryLiveUtils();
61115
+ this._notificationLiveFactory = () => new NotificationMemoryLiveUtils();
61116
+ this.getInstance.clear();
60984
61117
  };
60985
61118
  /**
60986
61119
  * Switches to persistent notification adapter.
@@ -60988,16 +61121,17 @@ class NotificationLiveAdapter {
60988
61121
  */
60989
61122
  this.usePersist = () => {
60990
61123
  backtest.loggerService.info(NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_PERSIST);
60991
- this._notificationLiveUtils = new NotificationPersistLiveUtils();
61124
+ this._notificationLiveFactory = () => new NotificationPersistLiveUtils();
61125
+ this.getInstance.clear();
60992
61126
  };
60993
61127
  /**
60994
- * Resets the cached utils instance to the default in-memory adapter.
61128
+ * Clears the memoized utils instance.
60995
61129
  * Call this when process.cwd() changes between strategy iterations
60996
61130
  * so a new instance is created with the updated base path.
60997
61131
  */
60998
61132
  this.clear = () => {
60999
61133
  backtest.loggerService.info(NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_CLEAR);
61000
- this._notificationLiveUtils = new NotificationMemoryLiveUtils();
61134
+ this.getInstance.clear();
61001
61135
  };
61002
61136
  }
61003
61137
  }