backtest-kit 6.2.0 → 6.4.0

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
@@ -888,26 +888,31 @@ const PERSIST_SIGNAL_UTILS_METHOD_NAME_READ_DATA = "PersistSignalUtils.readSigna
888
888
  const PERSIST_SIGNAL_UTILS_METHOD_NAME_WRITE_DATA = "PersistSignalUtils.writeSignalData";
889
889
  const PERSIST_SIGNAL_UTILS_METHOD_NAME_USE_JSON = "PersistSignalUtils.useJson";
890
890
  const PERSIST_SIGNAL_UTILS_METHOD_NAME_USE_DUMMY = "PersistSignalUtils.useDummy";
891
+ const PERSIST_SIGNAL_UTILS_METHOD_NAME_CLEAR = "PersistSignalUtils.clear";
891
892
  const PERSIST_SCHEDULE_UTILS_METHOD_NAME_USE_PERSIST_SCHEDULE_ADAPTER = "PersistScheduleUtils.usePersistScheduleAdapter";
892
893
  const PERSIST_SCHEDULE_UTILS_METHOD_NAME_READ_DATA = "PersistScheduleUtils.readScheduleData";
893
894
  const PERSIST_SCHEDULE_UTILS_METHOD_NAME_WRITE_DATA = "PersistScheduleUtils.writeScheduleData";
894
895
  const PERSIST_SCHEDULE_UTILS_METHOD_NAME_USE_JSON = "PersistScheduleUtils.useJson";
895
896
  const PERSIST_SCHEDULE_UTILS_METHOD_NAME_USE_DUMMY = "PersistScheduleUtils.useDummy";
897
+ const PERSIST_SCHEDULE_UTILS_METHOD_NAME_CLEAR = "PersistScheduleUtils.clear";
896
898
  const PERSIST_PARTIAL_UTILS_METHOD_NAME_USE_PERSIST_PARTIAL_ADAPTER = "PersistPartialUtils.usePersistPartialAdapter";
897
899
  const PERSIST_PARTIAL_UTILS_METHOD_NAME_READ_DATA = "PersistPartialUtils.readPartialData";
898
900
  const PERSIST_PARTIAL_UTILS_METHOD_NAME_WRITE_DATA = "PersistPartialUtils.writePartialData";
899
901
  const PERSIST_PARTIAL_UTILS_METHOD_NAME_USE_JSON = "PersistPartialUtils.useJson";
900
902
  const PERSIST_PARTIAL_UTILS_METHOD_NAME_USE_DUMMY = "PersistPartialUtils.useDummy";
903
+ const PERSIST_PARTIAL_UTILS_METHOD_NAME_CLEAR = "PersistPartialUtils.clear";
901
904
  const PERSIST_BREAKEVEN_UTILS_METHOD_NAME_USE_PERSIST_BREAKEVEN_ADAPTER = "PersistBreakevenUtils.usePersistBreakevenAdapter";
902
905
  const PERSIST_BREAKEVEN_UTILS_METHOD_NAME_READ_DATA = "PersistBreakevenUtils.readBreakevenData";
903
906
  const PERSIST_BREAKEVEN_UTILS_METHOD_NAME_WRITE_DATA = "PersistBreakevenUtils.writeBreakevenData";
904
907
  const PERSIST_BREAKEVEN_UTILS_METHOD_NAME_USE_JSON = "PersistBreakevenUtils.useJson";
905
908
  const PERSIST_BREAKEVEN_UTILS_METHOD_NAME_USE_DUMMY = "PersistBreakevenUtils.useDummy";
909
+ const PERSIST_BREAKEVEN_UTILS_METHOD_NAME_CLEAR = "PersistBreakevenUtils.clear";
906
910
  const PERSIST_RISK_UTILS_METHOD_NAME_USE_PERSIST_RISK_ADAPTER = "PersistRiskUtils.usePersistRiskAdapter";
907
911
  const PERSIST_RISK_UTILS_METHOD_NAME_READ_DATA = "PersistRiskUtils.readPositionData";
908
912
  const PERSIST_RISK_UTILS_METHOD_NAME_WRITE_DATA = "PersistRiskUtils.writePositionData";
909
913
  const PERSIST_RISK_UTILS_METHOD_NAME_USE_JSON = "PersistRiskUtils.useJson";
910
914
  const PERSIST_RISK_UTILS_METHOD_NAME_USE_DUMMY = "PersistRiskUtils.useDummy";
915
+ const PERSIST_RISK_UTILS_METHOD_NAME_CLEAR = "PersistRiskUtils.clear";
911
916
  const PERSIST_BASE_METHOD_NAME_CTOR = "PersistBase.CTOR";
912
917
  const PERSIST_BASE_METHOD_NAME_WAIT_FOR_INIT = "PersistBase.waitForInit";
913
918
  const PERSIST_BASE_METHOD_NAME_READ_VALUE = "PersistBase.readValue";
@@ -918,22 +923,27 @@ const PERSIST_STORAGE_UTILS_METHOD_NAME_READ_DATA = "PersistStorageUtils.readSto
918
923
  const PERSIST_STORAGE_UTILS_METHOD_NAME_WRITE_DATA = "PersistStorageUtils.writeStorageData";
919
924
  const PERSIST_STORAGE_UTILS_METHOD_NAME_USE_JSON = "PersistStorageUtils.useJson";
920
925
  const PERSIST_STORAGE_UTILS_METHOD_NAME_USE_DUMMY = "PersistStorageUtils.useDummy";
926
+ const PERSIST_STORAGE_UTILS_METHOD_NAME_CLEAR = "PersistStorageUtils.clear";
921
927
  const PERSIST_STORAGE_UTILS_METHOD_NAME_USE_PERSIST_STORAGE_ADAPTER = "PersistStorageUtils.usePersistStorageAdapter";
922
928
  const PERSIST_NOTIFICATION_UTILS_METHOD_NAME_READ_DATA = "PersistNotificationUtils.readNotificationData";
923
929
  const PERSIST_NOTIFICATION_UTILS_METHOD_NAME_WRITE_DATA = "PersistNotificationUtils.writeNotificationData";
924
930
  const PERSIST_NOTIFICATION_UTILS_METHOD_NAME_USE_JSON = "PersistNotificationUtils.useJson";
925
931
  const PERSIST_NOTIFICATION_UTILS_METHOD_NAME_USE_DUMMY = "PersistNotificationUtils.useDummy";
932
+ const PERSIST_NOTIFICATION_UTILS_METHOD_NAME_CLEAR = "PersistNotificationUtils.clear";
926
933
  const PERSIST_NOTIFICATION_UTILS_METHOD_NAME_USE_PERSIST_NOTIFICATION_ADAPTER = "PersistNotificationUtils.usePersistNotificationAdapter";
927
934
  const PERSIST_LOG_UTILS_METHOD_NAME_READ_DATA = "PersistLogUtils.readLogData";
928
935
  const PERSIST_LOG_UTILS_METHOD_NAME_WRITE_DATA = "PersistLogUtils.writeLogData";
929
936
  const PERSIST_LOG_UTILS_METHOD_NAME_USE_JSON = "PersistLogUtils.useJson";
930
937
  const PERSIST_LOG_UTILS_METHOD_NAME_USE_DUMMY = "PersistLogUtils.useDummy";
931
938
  const PERSIST_LOG_UTILS_METHOD_NAME_USE_PERSIST_LOG_ADAPTER = "PersistLogUtils.usePersistLogAdapter";
939
+ const PERSIST_LOG_UTILS_METHOD_NAME_CLEAR = "PersistLogUtils.clear";
932
940
  const PERSIST_MEASURE_UTILS_METHOD_NAME_READ_DATA = "PersistMeasureUtils.readMeasureData";
933
941
  const PERSIST_MEASURE_UTILS_METHOD_NAME_WRITE_DATA = "PersistMeasureUtils.writeMeasureData";
934
942
  const PERSIST_MEASURE_UTILS_METHOD_NAME_USE_JSON = "PersistMeasureUtils.useJson";
935
943
  const PERSIST_MEASURE_UTILS_METHOD_NAME_USE_DUMMY = "PersistMeasureUtils.useDummy";
944
+ const PERSIST_MEASURE_UTILS_METHOD_NAME_CLEAR = "PersistMeasureUtils.clear";
936
945
  const PERSIST_MEASURE_UTILS_METHOD_NAME_USE_PERSIST_MEASURE_ADAPTER = "PersistMeasureUtils.usePersistMeasureAdapter";
946
+ const PERSIST_CANDLE_UTILS_METHOD_NAME_CLEAR = "PersistCandleUtils.clear";
937
947
  const PERSIST_MEMORY_UTILS_METHOD_NAME_USE_PERSIST_MEMORY_ADAPTER = "PersistMemoryUtils.usePersistMemoryAdapter";
938
948
  const PERSIST_MEMORY_UTILS_METHOD_NAME_READ_DATA = "PersistMemoryUtils.readMemoryData";
939
949
  const PERSIST_MEMORY_UTILS_METHOD_NAME_WRITE_DATA = "PersistMemoryUtils.writeMemoryData";
@@ -941,6 +951,7 @@ const PERSIST_MEMORY_UTILS_METHOD_NAME_REMOVE_DATA = "PersistMemoryUtils.removeM
941
951
  const PERSIST_MEMORY_UTILS_METHOD_NAME_LIST_DATA = "PersistMemoryUtils.listMemoryData";
942
952
  const PERSIST_MEMORY_UTILS_METHOD_NAME_HAS_DATA = "PersistMemoryUtils.hasMemoryData";
943
953
  const PERSIST_MEMORY_UTILS_METHOD_NAME_CLEAR = "PersistMemoryUtils.clear";
954
+ const PERSIST_MEMORY_UTILS_METHOD_NAME_DISPOSE = "PersistMemoryUtils.dispose";
944
955
  const BASE_WAIT_FOR_INIT_FN_METHOD_NAME = "PersistBase.waitForInitFn";
945
956
  const BASE_UNLINK_RETRY_COUNT = 5;
946
957
  const BASE_UNLINK_RETRY_DELAY = 1000;
@@ -1226,6 +1237,15 @@ class PersistSignalUtils {
1226
1237
  bt.loggerService.info(PERSIST_SIGNAL_UTILS_METHOD_NAME_USE_PERSIST_SIGNAL_ADAPTER);
1227
1238
  this.PersistSignalFactory = Ctor;
1228
1239
  }
1240
+ /**
1241
+ * Clears the memoized storage cache.
1242
+ * Call this when process.cwd() changes between strategy iterations
1243
+ * so new storage instances are created with the updated base path.
1244
+ */
1245
+ clear() {
1246
+ bt.loggerService.log(PERSIST_SIGNAL_UTILS_METHOD_NAME_CLEAR);
1247
+ this.getStorage.clear();
1248
+ }
1229
1249
  /**
1230
1250
  * Switches to the default JSON persist adapter.
1231
1251
  * All future persistence writes will use JSON storage.
@@ -1339,6 +1359,15 @@ class PersistRiskUtils {
1339
1359
  bt.loggerService.info(PERSIST_RISK_UTILS_METHOD_NAME_USE_PERSIST_RISK_ADAPTER);
1340
1360
  this.PersistRiskFactory = Ctor;
1341
1361
  }
1362
+ /**
1363
+ * Clears the memoized storage cache.
1364
+ * Call this when process.cwd() changes between strategy iterations
1365
+ * so new storage instances are created with the updated base path.
1366
+ */
1367
+ clear() {
1368
+ bt.loggerService.log(PERSIST_RISK_UTILS_METHOD_NAME_CLEAR);
1369
+ this.getRiskStorage.clear();
1370
+ }
1342
1371
  /**
1343
1372
  * Switches to the default JSON persist adapter.
1344
1373
  * All future persistence writes will use JSON storage.
@@ -1452,6 +1481,15 @@ class PersistScheduleUtils {
1452
1481
  bt.loggerService.info(PERSIST_SCHEDULE_UTILS_METHOD_NAME_USE_PERSIST_SCHEDULE_ADAPTER);
1453
1482
  this.PersistScheduleFactory = Ctor;
1454
1483
  }
1484
+ /**
1485
+ * Clears the memoized storage cache.
1486
+ * Call this when process.cwd() changes between strategy iterations
1487
+ * so new storage instances are created with the updated base path.
1488
+ */
1489
+ clear() {
1490
+ bt.loggerService.log(PERSIST_SCHEDULE_UTILS_METHOD_NAME_CLEAR);
1491
+ this.getScheduleStorage.clear();
1492
+ }
1455
1493
  /**
1456
1494
  * Switches to the default JSON persist adapter.
1457
1495
  * All future persistence writes will use JSON storage.
@@ -1567,6 +1605,15 @@ class PersistPartialUtils {
1567
1605
  bt.loggerService.info(PERSIST_PARTIAL_UTILS_METHOD_NAME_USE_PERSIST_PARTIAL_ADAPTER);
1568
1606
  this.PersistPartialFactory = Ctor;
1569
1607
  }
1608
+ /**
1609
+ * Clears the memoized storage cache.
1610
+ * Call this when process.cwd() changes between strategy iterations
1611
+ * so new storage instances are created with the updated base path.
1612
+ */
1613
+ clear() {
1614
+ bt.loggerService.log(PERSIST_PARTIAL_UTILS_METHOD_NAME_CLEAR);
1615
+ this.getPartialStorage.clear();
1616
+ }
1570
1617
  /**
1571
1618
  * Switches to the default JSON persist adapter.
1572
1619
  * All future persistence writes will use JSON storage.
@@ -1717,6 +1764,15 @@ class PersistBreakevenUtils {
1717
1764
  bt.loggerService.info(PERSIST_BREAKEVEN_UTILS_METHOD_NAME_USE_PERSIST_BREAKEVEN_ADAPTER);
1718
1765
  this.PersistBreakevenFactory = Ctor;
1719
1766
  }
1767
+ /**
1768
+ * Clears the memoized storage cache.
1769
+ * Call this when process.cwd() changes between strategy iterations
1770
+ * so new storage instances are created with the updated base path.
1771
+ */
1772
+ clear() {
1773
+ bt.loggerService.log(PERSIST_BREAKEVEN_UTILS_METHOD_NAME_CLEAR);
1774
+ this.getBreakevenStorage.clear();
1775
+ }
1720
1776
  /**
1721
1777
  * Switches to the default JSON persist adapter.
1722
1778
  * All future persistence writes will use JSON storage.
@@ -1888,6 +1944,15 @@ class PersistCandleUtils {
1888
1944
  bt.loggerService.info("PersistCandleUtils.usePersistCandleAdapter");
1889
1945
  this.PersistCandlesFactory = Ctor;
1890
1946
  }
1947
+ /**
1948
+ * Clears the memoized storage cache.
1949
+ * Call this when process.cwd() changes between strategy iterations
1950
+ * so new storage instances are created with the updated base path.
1951
+ */
1952
+ clear() {
1953
+ bt.loggerService.log(PERSIST_CANDLE_UTILS_METHOD_NAME_CLEAR);
1954
+ this.getCandlesStorage.clear();
1955
+ }
1891
1956
  /**
1892
1957
  * Switches to the default JSON persist adapter.
1893
1958
  * All future persistence writes will use JSON storage.
@@ -1994,6 +2059,15 @@ class PersistStorageUtils {
1994
2059
  bt.loggerService.info(PERSIST_STORAGE_UTILS_METHOD_NAME_USE_PERSIST_STORAGE_ADAPTER);
1995
2060
  this.PersistStorageFactory = Ctor;
1996
2061
  }
2062
+ /**
2063
+ * Clears the memoized storage cache.
2064
+ * Call this when process.cwd() changes between strategy iterations
2065
+ * so new storage instances are created with the updated base path.
2066
+ */
2067
+ clear() {
2068
+ bt.loggerService.log(PERSIST_STORAGE_UTILS_METHOD_NAME_CLEAR);
2069
+ this.getStorage.clear();
2070
+ }
1997
2071
  /**
1998
2072
  * Switches to the default JSON persist adapter.
1999
2073
  * All future persistence writes will use JSON storage.
@@ -2089,6 +2163,15 @@ class PersistNotificationUtils {
2089
2163
  bt.loggerService.info(PERSIST_NOTIFICATION_UTILS_METHOD_NAME_USE_PERSIST_NOTIFICATION_ADAPTER);
2090
2164
  this.PersistNotificationFactory = Ctor;
2091
2165
  }
2166
+ /**
2167
+ * Clears the memoized storage cache.
2168
+ * Call this when process.cwd() changes between strategy iterations
2169
+ * so new storage instances are created with the updated base path.
2170
+ */
2171
+ clear() {
2172
+ bt.loggerService.log(PERSIST_NOTIFICATION_UTILS_METHOD_NAME_CLEAR);
2173
+ this.getNotificationStorage.clear();
2174
+ }
2092
2175
  /**
2093
2176
  * Switches to the default JSON persist adapter.
2094
2177
  * All future persistence writes will use JSON storage.
@@ -2189,6 +2272,15 @@ class PersistLogUtils {
2189
2272
  bt.loggerService.info(PERSIST_LOG_UTILS_METHOD_NAME_USE_PERSIST_LOG_ADAPTER);
2190
2273
  this.PersistLogFactory = Ctor;
2191
2274
  }
2275
+ /**
2276
+ * Clears the cached storage instance.
2277
+ * Call this when process.cwd() changes between strategy iterations
2278
+ * so a new storage instance is created with the updated base path.
2279
+ */
2280
+ clear() {
2281
+ bt.loggerService.log(PERSIST_LOG_UTILS_METHOD_NAME_CLEAR);
2282
+ this._logStorage = null;
2283
+ }
2192
2284
  /**
2193
2285
  * Switches to the default JSON persist adapter.
2194
2286
  * All future persistence writes will use JSON storage.
@@ -2277,6 +2369,15 @@ class PersistMeasureUtils {
2277
2369
  bt.loggerService.info(PERSIST_MEASURE_UTILS_METHOD_NAME_USE_PERSIST_MEASURE_ADAPTER);
2278
2370
  this.PersistMeasureFactory = Ctor;
2279
2371
  }
2372
+ /**
2373
+ * Clears the memoized storage cache.
2374
+ * Call this when process.cwd() changes between strategy iterations
2375
+ * so new storage instances are created with the updated base path.
2376
+ */
2377
+ clear() {
2378
+ bt.loggerService.log(PERSIST_MEASURE_UTILS_METHOD_NAME_CLEAR);
2379
+ this.getMeasureStorage.clear();
2380
+ }
2280
2381
  /**
2281
2382
  * Switches to the default JSON persist adapter.
2282
2383
  */
@@ -2420,16 +2521,24 @@ class PersistMemoryUtils {
2420
2521
  }
2421
2522
  };
2422
2523
  /**
2423
- * Dispose persist adapter to prevent memory leak
2524
+ * Clears the memoized storage cache.
2525
+ * Call this when process.cwd() changes between strategy iterations
2526
+ * so new storage instances are created with the updated base path.
2527
+ */
2528
+ this.clear = () => {
2529
+ bt.loggerService.info(PERSIST_MEMORY_UTILS_METHOD_NAME_CLEAR);
2530
+ this.getMemoryStorage.clear();
2531
+ };
2532
+ /**
2533
+ * Disposes of the memory adapter and releases any resources.
2534
+ * Call this when a signal is removed to clean up its associated storage.
2424
2535
  *
2425
2536
  * @param signalId - Signal identifier
2426
2537
  * @param bucketName - Bucket name
2538
+ * @returns void
2427
2539
  */
2428
- this.clear = (signalId, bucketName) => {
2429
- bt.loggerService.info(PERSIST_MEMORY_UTILS_METHOD_NAME_CLEAR, {
2430
- signalId,
2431
- bucketName,
2432
- });
2540
+ this.dispose = (signalId, bucketName) => {
2541
+ bt.loggerService.info(PERSIST_MEMORY_UTILS_METHOD_NAME_DISPOSE);
2433
2542
  const key = `${signalId}:${bucketName}`;
2434
2543
  this.getMemoryStorage.clear(key);
2435
2544
  };
@@ -19534,6 +19643,7 @@ const MARKDOWN_METHOD_NAME_WRITE_DATA = "MarkdownAdapter.writeData";
19534
19643
  const MARKDOWN_METHOD_NAME_USE_MD = "MarkdownAdapter.useMd";
19535
19644
  const MARKDOWN_METHOD_NAME_USE_JSONL = "MarkdownAdapter.useJsonl";
19536
19645
  const MARKDOWN_METHOD_NAME_USE_DUMMY = "MarkdownAdapter.useDummy";
19646
+ const MARKDOWN_METHOD_NAME_CLEAR = "MarkdownAdapter.clear";
19537
19647
  /** Symbol key for the singleshot waitForInit function on MarkdownFileBase instances. */
19538
19648
  const WAIT_FOR_INIT_SYMBOL$2 = Symbol("wait-for-init");
19539
19649
  /** Symbol key for the timeout-protected write function on MarkdownFileBase instances. */
@@ -20005,6 +20115,15 @@ class MarkdownAdapter extends MarkdownUtils {
20005
20115
  bt.loggerService.debug(MARKDOWN_METHOD_NAME_USE_JSONL);
20006
20116
  this.useMarkdownAdapter(MarkdownFileBase);
20007
20117
  }
20118
+ /**
20119
+ * Clears the memoized storage cache.
20120
+ * Call this when process.cwd() changes between strategy iterations
20121
+ * so new storage instances are created with the updated base path.
20122
+ */
20123
+ clear() {
20124
+ bt.loggerService.log(MARKDOWN_METHOD_NAME_CLEAR);
20125
+ this.getMarkdownStorage.clear();
20126
+ }
20008
20127
  /**
20009
20128
  * Switches to a dummy markdown adapter that discards all writes.
20010
20129
  * All future markdown writes will be no-ops.
@@ -26806,6 +26925,7 @@ const REPORT_UTILS_METHOD_NAME_ENABLE = "ReportUtils.enable";
26806
26925
  const REPORT_UTILS_METHOD_NAME_DISABLE = "ReportUtils.disable";
26807
26926
  const REPORT_UTILS_METHOD_NAME_USE_DUMMY = "ReportUtils.useDummy";
26808
26927
  const REPORT_UTILS_METHOD_NAME_USE_JSONL = "ReportUtils.useJsonl";
26928
+ const REPORT_UTILS_METHOD_NAME_CLEAR = "ReportUtils.clear";
26809
26929
  /** Symbol key for the singleshot waitForInit function on ReportBase instances. */
26810
26930
  const WAIT_FOR_INIT_SYMBOL$1 = Symbol("wait-for-init");
26811
26931
  /** Symbol key for the timeout-protected write function on ReportBase instances. */
@@ -27215,6 +27335,15 @@ class ReportAdapter extends ReportUtils {
27215
27335
  bt.loggerService.info(REPORT_UTILS_METHOD_NAME_USE_REPORT_ADAPTER);
27216
27336
  this.ReportFactory = Ctor;
27217
27337
  }
27338
+ /**
27339
+ * Clears the memoized storage cache.
27340
+ * Call this when process.cwd() changes between strategy iterations
27341
+ * so new storage instances are created with the updated base path.
27342
+ */
27343
+ clear() {
27344
+ bt.loggerService.log(REPORT_UTILS_METHOD_NAME_CLEAR);
27345
+ this.getReportStorage.clear();
27346
+ }
27218
27347
  /**
27219
27348
  * Switches to a dummy report adapter that discards all writes.
27220
27349
  * All future report writes will be no-ops.
@@ -33539,6 +33668,7 @@ const BROKER_METHOD_NAME_COMMIT_AVERAGE_BUY = "BrokerAdapter.commitAverageBuy";
33539
33668
  const BROKER_METHOD_NAME_USE_BROKER_ADAPTER = "BrokerAdapter.useBrokerAdapter";
33540
33669
  const BROKER_METHOD_NAME_ENABLE = "BrokerAdapter.enable";
33541
33670
  const BROKER_METHOD_NAME_DISABLE = "BrokerAdapter.disable";
33671
+ const BROKER_METHOD_NAME_CLEAR = "BrokerAdapter.clear";
33542
33672
  const BROKER_BASE_METHOD_NAME_WAIT_FOR_INIT = "BrokerBase.waitForInit";
33543
33673
  const BROKER_BASE_METHOD_NAME_ON_SIGNAL_OPEN = "BrokerBase.onSignalOpenCommit";
33544
33674
  const BROKER_BASE_METHOD_NAME_ON_SIGNAL_CLOSE = "BrokerBase.onSignalCloseCommit";
@@ -34138,6 +34268,16 @@ class BrokerAdapter {
34138
34268
  lastSubscription();
34139
34269
  }
34140
34270
  };
34271
+ /**
34272
+ * Clears the cached broker instance and resets the enable singleshot.
34273
+ * Call this when process.cwd() changes between strategy iterations
34274
+ * so a new broker instance is created with the updated base path.
34275
+ */
34276
+ this.clear = () => {
34277
+ bt.loggerService.info(BROKER_METHOD_NAME_CLEAR, {});
34278
+ this._brokerInstance = null;
34279
+ this.enable.clear();
34280
+ };
34141
34281
  }
34142
34282
  }
34143
34283
  /**
@@ -43431,6 +43571,7 @@ const MEMORY_ADAPTER_METHOD_NAME_READ = "MemoryAdapter.readMemory";
43431
43571
  const MEMORY_ADAPTER_METHOD_NAME_USE_LOCAL = "MemoryAdapter.useLocal";
43432
43572
  const MEMORY_ADAPTER_METHOD_NAME_USE_PERSIST = "MemoryAdapter.usePersist";
43433
43573
  const MEMORY_ADAPTER_METHOD_NAME_USE_DUMMY = "MemoryAdapter.useDummy";
43574
+ const MEMORY_ADAPTER_METHOD_NAME_CLEAR = "MemoryAdapter.clear";
43434
43575
  /**
43435
43576
  * In-memory BM25 search index backed instance.
43436
43577
  * All data lives in the process memory only - no disk persistence.
@@ -43653,7 +43794,7 @@ class MemoryPersistInstance {
43653
43794
  signalId: this.signalId,
43654
43795
  bucketName: this.bucketName,
43655
43796
  });
43656
- PersistMemoryAdapter.clear(this.signalId, this.bucketName);
43797
+ PersistMemoryAdapter.dispose(this.signalId, this.bucketName);
43657
43798
  }
43658
43799
  }
43659
43800
  /**
@@ -43891,6 +44032,15 @@ class MemoryAdapter {
43891
44032
  bt.loggerService.info(MEMORY_ADAPTER_METHOD_NAME_USE_DUMMY);
43892
44033
  this.MemoryFactory = MemoryDummyInstance;
43893
44034
  };
44035
+ /**
44036
+ * Clears the memoized instance cache.
44037
+ * Call this when process.cwd() changes between strategy iterations
44038
+ * so new instances are created with the updated base path.
44039
+ */
44040
+ this.clear = () => {
44041
+ bt.loggerService.info(MEMORY_ADAPTER_METHOD_NAME_CLEAR);
44042
+ this.getInstance.clear();
44043
+ };
43894
44044
  /**
43895
44045
  * Releases resources held by this adapter.
43896
44046
  * Delegates to disable() to unsubscribe from signal lifecycle events.
@@ -44178,6 +44328,7 @@ const DUMP_ADAPTER_METHOD_NAME_USE_MEMORY = "DumpAdapter.useMemory";
44178
44328
  const DUMP_ADAPTER_METHOD_NAME_USE_DUMMY = "DumpAdapter.useDummy";
44179
44329
  const DUMP_ADAPTER_METHOD_NAME_USE_BOTH = "DumpAdapter.useMarkdownMemoryBoth";
44180
44330
  const DUMP_ADAPTER_METHOD_NAME_USE_ADAPTER = "DumpAdapter.useDumpAdapter";
44331
+ const DUMP_ADAPTER_METHOD_NAME_CLEAR = "DumpAdapter.clear";
44181
44332
  /**
44182
44333
  * Renders a single MessageModel as a markdown section.
44183
44334
  * tool_calls are rendered as a fenced JSON block.
@@ -44935,6 +45086,15 @@ class DumpAdapter {
44935
45086
  bt.loggerService.info(DUMP_ADAPTER_METHOD_NAME_USE_ADAPTER);
44936
45087
  this.DumpFactory = Ctor;
44937
45088
  };
45089
+ /**
45090
+ * Clears the memoized instance cache.
45091
+ * Call this when process.cwd() changes between strategy iterations
45092
+ * so new instances are created with the updated base path.
45093
+ */
45094
+ this.clear = () => {
45095
+ bt.loggerService.info(DUMP_ADAPTER_METHOD_NAME_CLEAR);
45096
+ this.getInstance.clear();
45097
+ };
44938
45098
  }
44939
45099
  }
44940
45100
  const Dump = new DumpAdapter();
@@ -45255,6 +45415,7 @@ const LOG_ADAPTER_METHOD_NAME_USE_PERSIST = "LogAdapter.usePersist";
45255
45415
  const LOG_ADAPTER_METHOD_NAME_USE_MEMORY = "LogAdapter.useMemory";
45256
45416
  const LOG_ADAPTER_METHOD_NAME_USE_DUMMY = "LogAdapter.useDummy";
45257
45417
  const LOG_ADAPTER_METHOD_NAME_USE_JSONL = "LogAdapter.useJsonl";
45418
+ const LOG_ADAPTER_METHOD_NAME_CLEAR = "LogAdapter.clear";
45258
45419
  const LOG_JSONL_METHOD_NAME_LOG = "LogJsonlUtils.log";
45259
45420
  const LOG_JSONL_METHOD_NAME_DEBUG = "LogJsonlUtils.debug";
45260
45421
  const LOG_JSONL_METHOD_NAME_INFO = "LogJsonlUtils.info";
@@ -45876,6 +46037,15 @@ class LogAdapter {
45876
46037
  bt.loggerService.info(LOG_ADAPTER_METHOD_NAME_USE_JSONL);
45877
46038
  this._log = new LogJsonlUtils(fileName, dirName);
45878
46039
  };
46040
+ /**
46041
+ * Clears the cached log instance by resetting to the default in-memory adapter.
46042
+ * Call this when process.cwd() changes between strategy iterations
46043
+ * so a new adapter instance is created with the updated base path.
46044
+ */
46045
+ this.clear = () => {
46046
+ bt.loggerService.info(LOG_ADAPTER_METHOD_NAME_CLEAR);
46047
+ this._log = new LogMemoryUtils();
46048
+ };
45879
46049
  }
45880
46050
  }
45881
46051
  /**
@@ -47603,10 +47773,12 @@ const STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_ADAPTER = "StorageBacktestAdapter
47603
47773
  const STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_DUMMY = "StorageBacktestAdapter.useDummy";
47604
47774
  const STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_PERSIST = "StorageBacktestAdapter.usePersist";
47605
47775
  const STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_MEMORY = "StorageBacktestAdapter.useMemory";
47776
+ const STORAGE_BACKTEST_ADAPTER_METHOD_NAME_CLEAR = "StorageBacktestAdapter.clear";
47606
47777
  const STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_ADAPTER = "StorageLiveAdapter.useStorageAdapter";
47607
47778
  const STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_DUMMY = "StorageLiveAdapter.useDummy";
47608
47779
  const STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_PERSIST = "StorageLiveAdapter.usePersist";
47609
47780
  const STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_MEMORY = "StorageLiveAdapter.useMemory";
47781
+ const STORAGE_LIVE_ADAPTER_METHOD_NAME_CLEAR = "StorageLiveAdapter.clear";
47610
47782
  /**
47611
47783
  * Persistent storage adapter for backtest signals.
47612
47784
  *
@@ -48593,6 +48765,15 @@ class StorageBacktestAdapter {
48593
48765
  bt.loggerService.info(STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_MEMORY);
48594
48766
  this._signalBacktestUtils = new StorageMemoryBacktestUtils();
48595
48767
  };
48768
+ /**
48769
+ * Clears the cached utils instance by resetting to the default in-memory adapter.
48770
+ * Call this when process.cwd() changes between strategy iterations
48771
+ * so a new instance is created with the updated base path.
48772
+ */
48773
+ this.clear = () => {
48774
+ bt.loggerService.info(STORAGE_BACKTEST_ADAPTER_METHOD_NAME_CLEAR);
48775
+ this._signalBacktestUtils = new StorageMemoryBacktestUtils();
48776
+ };
48596
48777
  }
48597
48778
  }
48598
48779
  /**
@@ -48697,6 +48878,15 @@ class StorageLiveAdapter {
48697
48878
  bt.loggerService.info(STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_MEMORY);
48698
48879
  this._signalLiveUtils = new StorageMemoryLiveUtils();
48699
48880
  };
48881
+ /**
48882
+ * Clears the cached utils instance by resetting to the default persistent adapter.
48883
+ * Call this when process.cwd() changes between strategy iterations
48884
+ * so a new instance is created with the updated base path.
48885
+ */
48886
+ this.clear = () => {
48887
+ bt.loggerService.info(STORAGE_LIVE_ADAPTER_METHOD_NAME_CLEAR);
48888
+ this._signalLiveUtils = new StoragePersistLiveUtils();
48889
+ };
48700
48890
  }
48701
48891
  }
48702
48892
  /**
@@ -49517,7 +49707,7 @@ const NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_HANDLE_ERROR = "NotificationMemor
49517
49707
  const NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_HANDLE_CRITICAL_ERROR = "NotificationMemoryBacktestUtils.handleCriticalError";
49518
49708
  const NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_HANDLE_VALIDATION_ERROR = "NotificationMemoryBacktestUtils.handleValidationError";
49519
49709
  const NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_GET_DATA = "NotificationMemoryBacktestUtils.getData";
49520
- const NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_CLEAR = "NotificationMemoryBacktestUtils.clear";
49710
+ const NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_DISPOSE = "NotificationMemoryBacktestUtils.dispose";
49521
49711
  const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_HANDLE_SIGNAL = "NotificationMemoryLiveUtils.handleSignal";
49522
49712
  const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_HANDLE_PARTIAL_PROFIT = "NotificationMemoryLiveUtils.handlePartialProfit";
49523
49713
  const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_HANDLE_PARTIAL_LOSS = "NotificationMemoryLiveUtils.handlePartialLoss";
@@ -49529,19 +49719,21 @@ const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_HANDLE_ERROR = "NotificationMemoryLiv
49529
49719
  const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_HANDLE_CRITICAL_ERROR = "NotificationMemoryLiveUtils.handleCriticalError";
49530
49720
  const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_HANDLE_VALIDATION_ERROR = "NotificationMemoryLiveUtils.handleValidationError";
49531
49721
  const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_GET_DATA = "NotificationMemoryLiveUtils.getData";
49532
- const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_CLEAR = "NotificationMemoryLiveUtils.clear";
49722
+ const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_DISPOSE = "NotificationMemoryLiveUtils.clear";
49533
49723
  const NOTIFICATION_ADAPTER_METHOD_NAME_ENABLE = "NotificationAdapter.enable";
49534
49724
  const NOTIFICATION_ADAPTER_METHOD_NAME_DISABLE = "NotificationAdapter.disable";
49535
49725
  const NOTIFICATION_ADAPTER_METHOD_NAME_GET_DATA_BACKTEST = "NotificationAdapter.getDataBacktest";
49536
- const NOTIFICATION_ADAPTER_METHOD_NAME_CLEAR_LIVE = "NotificationAdapter.clearLive";
49726
+ const NOTIFICATION_ADAPTER_METHOD_NAME_DISPOSE_LIVE = "NotificationAdapter.disposeLive";
49537
49727
  const NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_ADAPTER = "NotificationBacktestAdapter.useNotificationAdapter";
49538
49728
  const NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_DUMMY = "NotificationBacktestAdapter.useDummy";
49539
49729
  const NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_MEMORY = "NotificationBacktestAdapter.useMemory";
49540
49730
  const NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_PERSIST = "NotificationBacktestAdapter.usePersist";
49731
+ const NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_CLEAR = "NotificationBacktestAdapter.clear";
49541
49732
  const NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_ADAPTER = "NotificationLiveAdapter.useNotificationAdapter";
49542
49733
  const NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_DUMMY = "NotificationLiveAdapter.useDummy";
49543
49734
  const NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_MEMORY = "NotificationLiveAdapter.useMemory";
49544
49735
  const NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_PERSIST = "NotificationLiveAdapter.usePersist";
49736
+ const NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_CLEAR = "NotificationLiveAdapter.clear";
49545
49737
  const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_WAIT_FOR_INIT = "NotificationPersistBacktestUtils.waitForInit";
49546
49738
  const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_UPDATE_NOTIFICATIONS = "NotificationPersistBacktestUtils._updateNotifications";
49547
49739
  const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_HANDLE_SIGNAL = "NotificationPersistBacktestUtils.handleSignal";
@@ -49555,7 +49747,7 @@ const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_HANDLE_ERROR = "NotificationPers
49555
49747
  const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_HANDLE_CRITICAL_ERROR = "NotificationPersistBacktestUtils.handleCriticalError";
49556
49748
  const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_HANDLE_VALIDATION_ERROR = "NotificationPersistBacktestUtils.handleValidationError";
49557
49749
  const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_GET_DATA = "NotificationPersistBacktestUtils.getData";
49558
- const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_CLEAR = "NotificationPersistBacktestUtils.clear";
49750
+ const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_DISPOSE = "NotificationPersistBacktestUtils.clear";
49559
49751
  const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_WAIT_FOR_INIT = "NotificationPersistLiveUtils.waitForInit";
49560
49752
  const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_UPDATE_NOTIFICATIONS = "NotificationPersistLiveUtils._updateNotifications";
49561
49753
  const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_HANDLE_SIGNAL = "NotificationPersistLiveUtils.handleSignal";
@@ -49569,7 +49761,7 @@ const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_HANDLE_ERROR = "NotificationPersistL
49569
49761
  const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_HANDLE_CRITICAL_ERROR = "NotificationPersistLiveUtils.handleCriticalError";
49570
49762
  const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_HANDLE_VALIDATION_ERROR = "NotificationPersistLiveUtils.handleValidationError";
49571
49763
  const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_GET_DATA = "NotificationPersistLiveUtils.getData";
49572
- const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_CLEAR = "NotificationPersistLiveUtils.clear";
49764
+ const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_DISPOSE = "NotificationPersistLiveUtils.clear";
49573
49765
  /**
49574
49766
  * In-memory notification adapter for backtest signals.
49575
49767
  *
@@ -49712,8 +49904,8 @@ class NotificationMemoryBacktestUtils {
49712
49904
  /**
49713
49905
  * Clears all stored notifications.
49714
49906
  */
49715
- this.clear = async () => {
49716
- bt.loggerService.info(NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_CLEAR);
49907
+ this.dispose = async () => {
49908
+ bt.loggerService.info(NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_DISPOSE);
49717
49909
  this._notifications = [];
49718
49910
  };
49719
49911
  }
@@ -49802,7 +49994,7 @@ class NotificationDummyBacktestUtils {
49802
49994
  /**
49803
49995
  * No-op clear operation.
49804
49996
  */
49805
- this.clear = async () => {
49997
+ this.dispose = async () => {
49806
49998
  };
49807
49999
  }
49808
50000
  }
@@ -49982,8 +50174,8 @@ class NotificationPersistBacktestUtils {
49982
50174
  /**
49983
50175
  * Clears all stored notifications.
49984
50176
  */
49985
- this.clear = async () => {
49986
- bt.loggerService.info(NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_CLEAR);
50177
+ this.dispose = async () => {
50178
+ bt.loggerService.info(NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_DISPOSE);
49987
50179
  await this.waitForInit();
49988
50180
  this._notifications.clear();
49989
50181
  await this._updateNotifications();
@@ -50164,8 +50356,8 @@ class NotificationMemoryLiveUtils {
50164
50356
  /**
50165
50357
  * Clears all stored notifications.
50166
50358
  */
50167
- this.clear = async () => {
50168
- bt.loggerService.info(NOTIFICATION_MEMORY_LIVE_METHOD_NAME_CLEAR);
50359
+ this.dispose = async () => {
50360
+ bt.loggerService.info(NOTIFICATION_MEMORY_LIVE_METHOD_NAME_DISPOSE);
50169
50361
  this._notifications = [];
50170
50362
  };
50171
50363
  }
@@ -50254,7 +50446,7 @@ class NotificationDummyLiveUtils {
50254
50446
  /**
50255
50447
  * No-op clear operation.
50256
50448
  */
50257
- this.clear = async () => {
50449
+ this.dispose = async () => {
50258
50450
  };
50259
50451
  }
50260
50452
  }
@@ -50435,8 +50627,8 @@ class NotificationPersistLiveUtils {
50435
50627
  /**
50436
50628
  * Clears all stored notifications.
50437
50629
  */
50438
- this.clear = async () => {
50439
- bt.loggerService.info(NOTIFICATION_PERSIST_LIVE_METHOD_NAME_CLEAR);
50630
+ this.dispose = async () => {
50631
+ bt.loggerService.info(NOTIFICATION_PERSIST_LIVE_METHOD_NAME_DISPOSE);
50440
50632
  await this.waitForInit();
50441
50633
  this._notifications.clear();
50442
50634
  await this._updateNotifications();
@@ -50584,8 +50776,8 @@ class NotificationBacktestAdapter {
50584
50776
  * Clears all stored notifications.
50585
50777
  * Proxies call to the underlying notification adapter.
50586
50778
  */
50587
- this.clear = async () => {
50588
- return await this._notificationBacktestUtils.clear();
50779
+ this.dispose = async () => {
50780
+ return await this._notificationBacktestUtils.dispose();
50589
50781
  };
50590
50782
  /**
50591
50783
  * Sets the notification adapter constructor.
@@ -50621,6 +50813,15 @@ class NotificationBacktestAdapter {
50621
50813
  bt.loggerService.info(NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_PERSIST);
50622
50814
  this._notificationBacktestUtils = new NotificationPersistBacktestUtils();
50623
50815
  };
50816
+ /**
50817
+ * Resets the cached utils instance to the default in-memory adapter.
50818
+ * Call this when process.cwd() changes between strategy iterations
50819
+ * so a new instance is created with the updated base path.
50820
+ */
50821
+ this.clear = () => {
50822
+ bt.loggerService.info(NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_CLEAR);
50823
+ this._notificationBacktestUtils = new NotificationMemoryBacktestUtils();
50824
+ };
50624
50825
  }
50625
50826
  }
50626
50827
  /**
@@ -50730,8 +50931,8 @@ class NotificationLiveAdapter {
50730
50931
  * Clears all stored notifications.
50731
50932
  * Proxies call to the underlying notification adapter.
50732
50933
  */
50733
- this.clear = async () => {
50734
- return await this._notificationLiveUtils.clear();
50934
+ this.dispose = async () => {
50935
+ return await this._notificationLiveUtils.dispose();
50735
50936
  };
50736
50937
  /**
50737
50938
  * Sets the notification adapter constructor.
@@ -50767,6 +50968,15 @@ class NotificationLiveAdapter {
50767
50968
  bt.loggerService.info(NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_PERSIST);
50768
50969
  this._notificationLiveUtils = new NotificationPersistLiveUtils();
50769
50970
  };
50971
+ /**
50972
+ * Resets the cached utils instance to the default in-memory adapter.
50973
+ * Call this when process.cwd() changes between strategy iterations
50974
+ * so a new instance is created with the updated base path.
50975
+ */
50976
+ this.clear = () => {
50977
+ bt.loggerService.info(NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_CLEAR);
50978
+ this._notificationLiveUtils = new NotificationMemoryLiveUtils();
50979
+ };
50770
50980
  }
50771
50981
  }
50772
50982
  /**
@@ -50880,17 +51090,17 @@ class NotificationAdapter {
50880
51090
  *
50881
51091
  * @throws Error if NotificationAdapter is not enabled
50882
51092
  */
50883
- this.clear = async (isBacktest) => {
50884
- bt.loggerService.info(NOTIFICATION_ADAPTER_METHOD_NAME_CLEAR_LIVE, {
51093
+ this.dispose = async (isBacktest) => {
51094
+ bt.loggerService.info(NOTIFICATION_ADAPTER_METHOD_NAME_DISPOSE_LIVE, {
50885
51095
  backtest: isBacktest,
50886
51096
  });
50887
51097
  if (!this.enable.hasValue()) {
50888
51098
  throw new Error("NotificationAdapter is not enabled. Call enable() first.");
50889
51099
  }
50890
51100
  if (isBacktest) {
50891
- return await NotificationBacktest.clear();
51101
+ return await NotificationBacktest.dispose();
50892
51102
  }
50893
- return await NotificationLive.clear();
51103
+ return await NotificationLive.dispose();
50894
51104
  };
50895
51105
  }
50896
51106
  }
@@ -50910,12 +51120,14 @@ const NotificationLive = new NotificationLiveAdapter();
50910
51120
  */
50911
51121
  const NotificationBacktest = new NotificationBacktestAdapter();
50912
51122
 
50913
- const CACHE_METHOD_NAME_FLUSH = "CacheUtils.flush";
50914
- const CACHE_METHOD_NAME_CLEAR = "CacheInstance.clear";
50915
51123
  const CACHE_METHOD_NAME_RUN = "CacheInstance.run";
50916
- const CACHE_METHOD_NAME_GC = "CacheInstance.gc";
50917
51124
  const CACHE_METHOD_NAME_FN = "CacheUtils.fn";
51125
+ const CACHE_METHOD_NAME_FN_CLEAR = "CacheUtils.fn.clear";
51126
+ const CACHE_METHOD_NAME_FN_GC = "CacheUtils.fn.gc";
50918
51127
  const CACHE_METHOD_NAME_FILE = "CacheUtils.file";
51128
+ const CACHE_METHOD_NAME_FILE_CLEAR = "CacheUtils.file.clear";
51129
+ const CACHE_METHOD_NAME_DISPOSE = "CacheUtils.dispose";
51130
+ const CACHE_METHOD_NAME_CLEAR = "CacheUtils.clear";
50919
51131
  const CACHE_FILE_INSTANCE_METHOD_NAME_RUN = "CacheFileInstance.run";
50920
51132
  const MS_PER_MINUTE = 60000;
50921
51133
  const INTERVAL_MINUTES = {
@@ -51164,6 +51376,12 @@ class CacheFileInstance {
51164
51376
  static createIndex() {
51165
51377
  return CacheFileInstance._indexCounter++;
51166
51378
  }
51379
+ /**
51380
+ * Clears the index counter.
51381
+ */
51382
+ static clearCounter() {
51383
+ CacheFileInstance._indexCounter = 0;
51384
+ }
51167
51385
  /**
51168
51386
  * Creates a new CacheFileInstance.
51169
51387
  *
@@ -51297,6 +51515,26 @@ class CacheUtils {
51297
51515
  const instance = this._getFnInstance(run, context.interval, context.key);
51298
51516
  return instance.run(...args).value;
51299
51517
  };
51518
+ wrappedFn.clear = () => {
51519
+ bt.loggerService.info(CACHE_METHOD_NAME_FN_CLEAR);
51520
+ if (!MethodContextService.hasContext()) {
51521
+ bt.loggerService.warn(`${CACHE_METHOD_NAME_FN_CLEAR} called without method context, skipping`);
51522
+ return;
51523
+ }
51524
+ if (!ExecutionContextService.hasContext()) {
51525
+ bt.loggerService.warn(`${CACHE_METHOD_NAME_FN_CLEAR} called without execution context, skipping`);
51526
+ return;
51527
+ }
51528
+ this._getFnInstance.get(run)?.clear();
51529
+ };
51530
+ wrappedFn.gc = () => {
51531
+ bt.loggerService.info(CACHE_METHOD_NAME_FN_GC);
51532
+ if (!ExecutionContextService.hasContext()) {
51533
+ bt.loggerService.warn(`${CACHE_METHOD_NAME_FN_GC} called without execution context, skipping`);
51534
+ return;
51535
+ }
51536
+ return this._getFnInstance.get(run)?.gc();
51537
+ };
51300
51538
  return wrappedFn;
51301
51539
  };
51302
51540
  /**
@@ -51343,117 +51581,51 @@ class CacheUtils {
51343
51581
  const instance = this._getFileInstance(run, context.interval, context.name, context.key);
51344
51582
  return instance.run(...args);
51345
51583
  };
51584
+ wrappedFn.clear = () => {
51585
+ bt.loggerService.info(CACHE_METHOD_NAME_FILE_CLEAR);
51586
+ this._getFileInstance.clear(run);
51587
+ };
51346
51588
  return wrappedFn;
51347
51589
  };
51348
51590
  /**
51349
- * Flush (remove) cached CacheInstance for a specific function or all functions.
51350
- *
51351
- * This method removes CacheInstance objects from the internal memoization cache.
51352
- * When a CacheInstance is flushed, all cached results across all contexts
51353
- * (all strategy/exchange/mode combinations) for that function are discarded.
51591
+ * Dispose (remove) the memoized CacheInstance for a specific function.
51354
51592
  *
51355
- * Use cases:
51356
- * - Remove specific function's CacheInstance when implementation changes
51357
- * - Free memory by removing unused CacheInstances
51358
- * - Reset all CacheInstances when switching between different test scenarios
51359
- *
51360
- * Note: This is different from `clear()` which only removes cached values
51361
- * for the current context within an existing CacheInstance.
51593
+ * Removes the CacheInstance from the internal memoization cache, discarding all cached
51594
+ * results across all contexts (all strategy/exchange/mode combinations) for that function.
51595
+ * The next call to the wrapped function will create a fresh CacheInstance.
51362
51596
  *
51363
51597
  * @template T - Function type
51364
- * @param run - Optional function to flush CacheInstance for. If omitted, flushes all CacheInstances.
51598
+ * @param run - Function whose CacheInstance should be disposed.
51365
51599
  *
51366
51600
  * @example
51367
51601
  * ```typescript
51368
51602
  * const cachedFn = Cache.fn(calculateIndicator, { interval: "1h" });
51369
51603
  *
51370
- * // Flush CacheInstance for specific function
51371
- * Cache.flush(calculateIndicator);
51372
- *
51373
- * // Flush all CacheInstances
51374
- * Cache.flush();
51604
+ * // Dispose CacheInstance for a specific function
51605
+ * Cache.dispose(calculateIndicator);
51375
51606
  * ```
51376
51607
  */
51377
- this.flush = (run) => {
51378
- bt.loggerService.info(CACHE_METHOD_NAME_FLUSH, {
51608
+ this.dispose = (run) => {
51609
+ bt.loggerService.info(CACHE_METHOD_NAME_DISPOSE, {
51379
51610
  run,
51380
51611
  });
51381
- this._getFnInstance.clear(run);
51382
- };
51383
- /**
51384
- * Clear cached value for current execution context of a specific function.
51385
- *
51386
- * Removes the cached entry for the current strategy/exchange/mode combination
51387
- * from the specified function's CacheInstance. The next call to the wrapped function
51388
- * will recompute the value for that context.
51389
- *
51390
- * This only clears the cache for the current execution context, not all contexts.
51391
- * Use `flush()` to remove the entire CacheInstance across all contexts.
51392
- *
51393
- * Requires active execution context (strategy, exchange, backtest mode) and method context.
51394
- *
51395
- * @template T - Function type
51396
- * @param run - Function whose cache should be cleared for current context
51397
- *
51398
- * @example
51399
- * ```typescript
51400
- * const cachedFn = Cache.fn(calculateIndicator, { interval: "1h" });
51401
- *
51402
- * // Within strategy execution context
51403
- * const result1 = cachedFn("BTCUSDT", 14); // Computed
51404
- * const result2 = cachedFn("BTCUSDT", 14); // Cached
51405
- *
51406
- * Cache.clear(calculateIndicator); // Clear cache for current context only
51407
- *
51408
- * const result3 = cachedFn("BTCUSDT", 14); // Recomputed for this context
51409
- * // Other contexts (different strategies/exchanges) remain cached
51410
- * ```
51411
- */
51412
- this.clear = (run) => {
51413
- bt.loggerService.info(CACHE_METHOD_NAME_CLEAR, {
51414
- run,
51415
- });
51416
- if (!MethodContextService.hasContext()) {
51417
- console.warn(`${CACHE_METHOD_NAME_CLEAR} called without method context, skipping clear`);
51418
- return;
51419
- }
51420
- if (!ExecutionContextService.hasContext()) {
51421
- console.warn(`${CACHE_METHOD_NAME_CLEAR} called without execution context, skipping clear`);
51422
- return;
51612
+ {
51613
+ this._getFnInstance.clear(run);
51614
+ this._getFileInstance.clear(run);
51423
51615
  }
51424
- this._getFnInstance.get(run).clear();
51425
51616
  };
51426
51617
  /**
51427
- * Garbage collect expired cache entries for a specific function.
51428
- *
51429
- * Removes all cached entries whose interval has expired (not aligned with current time).
51430
- * Call this periodically to free memory from stale cache entries.
51431
- *
51432
- * Requires active execution context to get current time.
51433
- *
51434
- * @template T - Function type
51435
- * @param run - Function whose expired cache entries should be removed
51436
- * @returns Number of entries removed
51437
- *
51438
- * @example
51439
- * ```typescript
51440
- * const cachedFn = Cache.fn(calculateIndicator, { interval: "1h" });
51441
- *
51442
- * cachedFn("BTCUSDT", 14); // Cached at 10:00
51443
- * cachedFn("ETHUSDT", 14); // Cached at 10:00
51444
- * // Time passes to 11:00
51445
- * const removed = Cache.gc(calculateIndicator); // Returns 2
51446
- * ```
51618
+ * Clears all memoized CacheInstance and CacheFileInstance objects.
51619
+ * Call this when process.cwd() changes between strategy iterations
51620
+ * so new instances are created with the updated base path.
51447
51621
  */
51448
- this.gc = (run) => {
51449
- bt.loggerService.info(CACHE_METHOD_NAME_GC, {
51450
- run,
51451
- });
51452
- if (!ExecutionContextService.hasContext()) {
51453
- console.warn(`${CACHE_METHOD_NAME_GC} called without execution context, skipping garbage collection`);
51454
- return;
51622
+ this.clear = () => {
51623
+ bt.loggerService.info(CACHE_METHOD_NAME_CLEAR);
51624
+ {
51625
+ this._getFnInstance.clear();
51626
+ this._getFileInstance.clear();
51455
51627
  }
51456
- return this._getFnInstance.get(run).gc();
51628
+ CacheFileInstance.clearCounter();
51457
51629
  };
51458
51630
  }
51459
51631
  }