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.cjs CHANGED
@@ -908,26 +908,31 @@ const PERSIST_SIGNAL_UTILS_METHOD_NAME_READ_DATA = "PersistSignalUtils.readSigna
908
908
  const PERSIST_SIGNAL_UTILS_METHOD_NAME_WRITE_DATA = "PersistSignalUtils.writeSignalData";
909
909
  const PERSIST_SIGNAL_UTILS_METHOD_NAME_USE_JSON = "PersistSignalUtils.useJson";
910
910
  const PERSIST_SIGNAL_UTILS_METHOD_NAME_USE_DUMMY = "PersistSignalUtils.useDummy";
911
+ const PERSIST_SIGNAL_UTILS_METHOD_NAME_CLEAR = "PersistSignalUtils.clear";
911
912
  const PERSIST_SCHEDULE_UTILS_METHOD_NAME_USE_PERSIST_SCHEDULE_ADAPTER = "PersistScheduleUtils.usePersistScheduleAdapter";
912
913
  const PERSIST_SCHEDULE_UTILS_METHOD_NAME_READ_DATA = "PersistScheduleUtils.readScheduleData";
913
914
  const PERSIST_SCHEDULE_UTILS_METHOD_NAME_WRITE_DATA = "PersistScheduleUtils.writeScheduleData";
914
915
  const PERSIST_SCHEDULE_UTILS_METHOD_NAME_USE_JSON = "PersistScheduleUtils.useJson";
915
916
  const PERSIST_SCHEDULE_UTILS_METHOD_NAME_USE_DUMMY = "PersistScheduleUtils.useDummy";
917
+ const PERSIST_SCHEDULE_UTILS_METHOD_NAME_CLEAR = "PersistScheduleUtils.clear";
916
918
  const PERSIST_PARTIAL_UTILS_METHOD_NAME_USE_PERSIST_PARTIAL_ADAPTER = "PersistPartialUtils.usePersistPartialAdapter";
917
919
  const PERSIST_PARTIAL_UTILS_METHOD_NAME_READ_DATA = "PersistPartialUtils.readPartialData";
918
920
  const PERSIST_PARTIAL_UTILS_METHOD_NAME_WRITE_DATA = "PersistPartialUtils.writePartialData";
919
921
  const PERSIST_PARTIAL_UTILS_METHOD_NAME_USE_JSON = "PersistPartialUtils.useJson";
920
922
  const PERSIST_PARTIAL_UTILS_METHOD_NAME_USE_DUMMY = "PersistPartialUtils.useDummy";
923
+ const PERSIST_PARTIAL_UTILS_METHOD_NAME_CLEAR = "PersistPartialUtils.clear";
921
924
  const PERSIST_BREAKEVEN_UTILS_METHOD_NAME_USE_PERSIST_BREAKEVEN_ADAPTER = "PersistBreakevenUtils.usePersistBreakevenAdapter";
922
925
  const PERSIST_BREAKEVEN_UTILS_METHOD_NAME_READ_DATA = "PersistBreakevenUtils.readBreakevenData";
923
926
  const PERSIST_BREAKEVEN_UTILS_METHOD_NAME_WRITE_DATA = "PersistBreakevenUtils.writeBreakevenData";
924
927
  const PERSIST_BREAKEVEN_UTILS_METHOD_NAME_USE_JSON = "PersistBreakevenUtils.useJson";
925
928
  const PERSIST_BREAKEVEN_UTILS_METHOD_NAME_USE_DUMMY = "PersistBreakevenUtils.useDummy";
929
+ const PERSIST_BREAKEVEN_UTILS_METHOD_NAME_CLEAR = "PersistBreakevenUtils.clear";
926
930
  const PERSIST_RISK_UTILS_METHOD_NAME_USE_PERSIST_RISK_ADAPTER = "PersistRiskUtils.usePersistRiskAdapter";
927
931
  const PERSIST_RISK_UTILS_METHOD_NAME_READ_DATA = "PersistRiskUtils.readPositionData";
928
932
  const PERSIST_RISK_UTILS_METHOD_NAME_WRITE_DATA = "PersistRiskUtils.writePositionData";
929
933
  const PERSIST_RISK_UTILS_METHOD_NAME_USE_JSON = "PersistRiskUtils.useJson";
930
934
  const PERSIST_RISK_UTILS_METHOD_NAME_USE_DUMMY = "PersistRiskUtils.useDummy";
935
+ const PERSIST_RISK_UTILS_METHOD_NAME_CLEAR = "PersistRiskUtils.clear";
931
936
  const PERSIST_BASE_METHOD_NAME_CTOR = "PersistBase.CTOR";
932
937
  const PERSIST_BASE_METHOD_NAME_WAIT_FOR_INIT = "PersistBase.waitForInit";
933
938
  const PERSIST_BASE_METHOD_NAME_READ_VALUE = "PersistBase.readValue";
@@ -938,22 +943,27 @@ const PERSIST_STORAGE_UTILS_METHOD_NAME_READ_DATA = "PersistStorageUtils.readSto
938
943
  const PERSIST_STORAGE_UTILS_METHOD_NAME_WRITE_DATA = "PersistStorageUtils.writeStorageData";
939
944
  const PERSIST_STORAGE_UTILS_METHOD_NAME_USE_JSON = "PersistStorageUtils.useJson";
940
945
  const PERSIST_STORAGE_UTILS_METHOD_NAME_USE_DUMMY = "PersistStorageUtils.useDummy";
946
+ const PERSIST_STORAGE_UTILS_METHOD_NAME_CLEAR = "PersistStorageUtils.clear";
941
947
  const PERSIST_STORAGE_UTILS_METHOD_NAME_USE_PERSIST_STORAGE_ADAPTER = "PersistStorageUtils.usePersistStorageAdapter";
942
948
  const PERSIST_NOTIFICATION_UTILS_METHOD_NAME_READ_DATA = "PersistNotificationUtils.readNotificationData";
943
949
  const PERSIST_NOTIFICATION_UTILS_METHOD_NAME_WRITE_DATA = "PersistNotificationUtils.writeNotificationData";
944
950
  const PERSIST_NOTIFICATION_UTILS_METHOD_NAME_USE_JSON = "PersistNotificationUtils.useJson";
945
951
  const PERSIST_NOTIFICATION_UTILS_METHOD_NAME_USE_DUMMY = "PersistNotificationUtils.useDummy";
952
+ const PERSIST_NOTIFICATION_UTILS_METHOD_NAME_CLEAR = "PersistNotificationUtils.clear";
946
953
  const PERSIST_NOTIFICATION_UTILS_METHOD_NAME_USE_PERSIST_NOTIFICATION_ADAPTER = "PersistNotificationUtils.usePersistNotificationAdapter";
947
954
  const PERSIST_LOG_UTILS_METHOD_NAME_READ_DATA = "PersistLogUtils.readLogData";
948
955
  const PERSIST_LOG_UTILS_METHOD_NAME_WRITE_DATA = "PersistLogUtils.writeLogData";
949
956
  const PERSIST_LOG_UTILS_METHOD_NAME_USE_JSON = "PersistLogUtils.useJson";
950
957
  const PERSIST_LOG_UTILS_METHOD_NAME_USE_DUMMY = "PersistLogUtils.useDummy";
951
958
  const PERSIST_LOG_UTILS_METHOD_NAME_USE_PERSIST_LOG_ADAPTER = "PersistLogUtils.usePersistLogAdapter";
959
+ const PERSIST_LOG_UTILS_METHOD_NAME_CLEAR = "PersistLogUtils.clear";
952
960
  const PERSIST_MEASURE_UTILS_METHOD_NAME_READ_DATA = "PersistMeasureUtils.readMeasureData";
953
961
  const PERSIST_MEASURE_UTILS_METHOD_NAME_WRITE_DATA = "PersistMeasureUtils.writeMeasureData";
954
962
  const PERSIST_MEASURE_UTILS_METHOD_NAME_USE_JSON = "PersistMeasureUtils.useJson";
955
963
  const PERSIST_MEASURE_UTILS_METHOD_NAME_USE_DUMMY = "PersistMeasureUtils.useDummy";
964
+ const PERSIST_MEASURE_UTILS_METHOD_NAME_CLEAR = "PersistMeasureUtils.clear";
956
965
  const PERSIST_MEASURE_UTILS_METHOD_NAME_USE_PERSIST_MEASURE_ADAPTER = "PersistMeasureUtils.usePersistMeasureAdapter";
966
+ const PERSIST_CANDLE_UTILS_METHOD_NAME_CLEAR = "PersistCandleUtils.clear";
957
967
  const PERSIST_MEMORY_UTILS_METHOD_NAME_USE_PERSIST_MEMORY_ADAPTER = "PersistMemoryUtils.usePersistMemoryAdapter";
958
968
  const PERSIST_MEMORY_UTILS_METHOD_NAME_READ_DATA = "PersistMemoryUtils.readMemoryData";
959
969
  const PERSIST_MEMORY_UTILS_METHOD_NAME_WRITE_DATA = "PersistMemoryUtils.writeMemoryData";
@@ -961,6 +971,7 @@ const PERSIST_MEMORY_UTILS_METHOD_NAME_REMOVE_DATA = "PersistMemoryUtils.removeM
961
971
  const PERSIST_MEMORY_UTILS_METHOD_NAME_LIST_DATA = "PersistMemoryUtils.listMemoryData";
962
972
  const PERSIST_MEMORY_UTILS_METHOD_NAME_HAS_DATA = "PersistMemoryUtils.hasMemoryData";
963
973
  const PERSIST_MEMORY_UTILS_METHOD_NAME_CLEAR = "PersistMemoryUtils.clear";
974
+ const PERSIST_MEMORY_UTILS_METHOD_NAME_DISPOSE = "PersistMemoryUtils.dispose";
964
975
  const BASE_WAIT_FOR_INIT_FN_METHOD_NAME = "PersistBase.waitForInitFn";
965
976
  const BASE_UNLINK_RETRY_COUNT = 5;
966
977
  const BASE_UNLINK_RETRY_DELAY = 1000;
@@ -1246,6 +1257,15 @@ class PersistSignalUtils {
1246
1257
  bt.loggerService.info(PERSIST_SIGNAL_UTILS_METHOD_NAME_USE_PERSIST_SIGNAL_ADAPTER);
1247
1258
  this.PersistSignalFactory = Ctor;
1248
1259
  }
1260
+ /**
1261
+ * Clears the memoized storage cache.
1262
+ * Call this when process.cwd() changes between strategy iterations
1263
+ * so new storage instances are created with the updated base path.
1264
+ */
1265
+ clear() {
1266
+ bt.loggerService.log(PERSIST_SIGNAL_UTILS_METHOD_NAME_CLEAR);
1267
+ this.getStorage.clear();
1268
+ }
1249
1269
  /**
1250
1270
  * Switches to the default JSON persist adapter.
1251
1271
  * All future persistence writes will use JSON storage.
@@ -1359,6 +1379,15 @@ class PersistRiskUtils {
1359
1379
  bt.loggerService.info(PERSIST_RISK_UTILS_METHOD_NAME_USE_PERSIST_RISK_ADAPTER);
1360
1380
  this.PersistRiskFactory = Ctor;
1361
1381
  }
1382
+ /**
1383
+ * Clears the memoized storage cache.
1384
+ * Call this when process.cwd() changes between strategy iterations
1385
+ * so new storage instances are created with the updated base path.
1386
+ */
1387
+ clear() {
1388
+ bt.loggerService.log(PERSIST_RISK_UTILS_METHOD_NAME_CLEAR);
1389
+ this.getRiskStorage.clear();
1390
+ }
1362
1391
  /**
1363
1392
  * Switches to the default JSON persist adapter.
1364
1393
  * All future persistence writes will use JSON storage.
@@ -1472,6 +1501,15 @@ class PersistScheduleUtils {
1472
1501
  bt.loggerService.info(PERSIST_SCHEDULE_UTILS_METHOD_NAME_USE_PERSIST_SCHEDULE_ADAPTER);
1473
1502
  this.PersistScheduleFactory = Ctor;
1474
1503
  }
1504
+ /**
1505
+ * Clears the memoized storage cache.
1506
+ * Call this when process.cwd() changes between strategy iterations
1507
+ * so new storage instances are created with the updated base path.
1508
+ */
1509
+ clear() {
1510
+ bt.loggerService.log(PERSIST_SCHEDULE_UTILS_METHOD_NAME_CLEAR);
1511
+ this.getScheduleStorage.clear();
1512
+ }
1475
1513
  /**
1476
1514
  * Switches to the default JSON persist adapter.
1477
1515
  * All future persistence writes will use JSON storage.
@@ -1587,6 +1625,15 @@ class PersistPartialUtils {
1587
1625
  bt.loggerService.info(PERSIST_PARTIAL_UTILS_METHOD_NAME_USE_PERSIST_PARTIAL_ADAPTER);
1588
1626
  this.PersistPartialFactory = Ctor;
1589
1627
  }
1628
+ /**
1629
+ * Clears the memoized storage cache.
1630
+ * Call this when process.cwd() changes between strategy iterations
1631
+ * so new storage instances are created with the updated base path.
1632
+ */
1633
+ clear() {
1634
+ bt.loggerService.log(PERSIST_PARTIAL_UTILS_METHOD_NAME_CLEAR);
1635
+ this.getPartialStorage.clear();
1636
+ }
1590
1637
  /**
1591
1638
  * Switches to the default JSON persist adapter.
1592
1639
  * All future persistence writes will use JSON storage.
@@ -1737,6 +1784,15 @@ class PersistBreakevenUtils {
1737
1784
  bt.loggerService.info(PERSIST_BREAKEVEN_UTILS_METHOD_NAME_USE_PERSIST_BREAKEVEN_ADAPTER);
1738
1785
  this.PersistBreakevenFactory = Ctor;
1739
1786
  }
1787
+ /**
1788
+ * Clears the memoized storage cache.
1789
+ * Call this when process.cwd() changes between strategy iterations
1790
+ * so new storage instances are created with the updated base path.
1791
+ */
1792
+ clear() {
1793
+ bt.loggerService.log(PERSIST_BREAKEVEN_UTILS_METHOD_NAME_CLEAR);
1794
+ this.getBreakevenStorage.clear();
1795
+ }
1740
1796
  /**
1741
1797
  * Switches to the default JSON persist adapter.
1742
1798
  * All future persistence writes will use JSON storage.
@@ -1908,6 +1964,15 @@ class PersistCandleUtils {
1908
1964
  bt.loggerService.info("PersistCandleUtils.usePersistCandleAdapter");
1909
1965
  this.PersistCandlesFactory = Ctor;
1910
1966
  }
1967
+ /**
1968
+ * Clears the memoized storage cache.
1969
+ * Call this when process.cwd() changes between strategy iterations
1970
+ * so new storage instances are created with the updated base path.
1971
+ */
1972
+ clear() {
1973
+ bt.loggerService.log(PERSIST_CANDLE_UTILS_METHOD_NAME_CLEAR);
1974
+ this.getCandlesStorage.clear();
1975
+ }
1911
1976
  /**
1912
1977
  * Switches to the default JSON persist adapter.
1913
1978
  * All future persistence writes will use JSON storage.
@@ -2014,6 +2079,15 @@ class PersistStorageUtils {
2014
2079
  bt.loggerService.info(PERSIST_STORAGE_UTILS_METHOD_NAME_USE_PERSIST_STORAGE_ADAPTER);
2015
2080
  this.PersistStorageFactory = Ctor;
2016
2081
  }
2082
+ /**
2083
+ * Clears the memoized storage cache.
2084
+ * Call this when process.cwd() changes between strategy iterations
2085
+ * so new storage instances are created with the updated base path.
2086
+ */
2087
+ clear() {
2088
+ bt.loggerService.log(PERSIST_STORAGE_UTILS_METHOD_NAME_CLEAR);
2089
+ this.getStorage.clear();
2090
+ }
2017
2091
  /**
2018
2092
  * Switches to the default JSON persist adapter.
2019
2093
  * All future persistence writes will use JSON storage.
@@ -2109,6 +2183,15 @@ class PersistNotificationUtils {
2109
2183
  bt.loggerService.info(PERSIST_NOTIFICATION_UTILS_METHOD_NAME_USE_PERSIST_NOTIFICATION_ADAPTER);
2110
2184
  this.PersistNotificationFactory = Ctor;
2111
2185
  }
2186
+ /**
2187
+ * Clears the memoized storage cache.
2188
+ * Call this when process.cwd() changes between strategy iterations
2189
+ * so new storage instances are created with the updated base path.
2190
+ */
2191
+ clear() {
2192
+ bt.loggerService.log(PERSIST_NOTIFICATION_UTILS_METHOD_NAME_CLEAR);
2193
+ this.getNotificationStorage.clear();
2194
+ }
2112
2195
  /**
2113
2196
  * Switches to the default JSON persist adapter.
2114
2197
  * All future persistence writes will use JSON storage.
@@ -2209,6 +2292,15 @@ class PersistLogUtils {
2209
2292
  bt.loggerService.info(PERSIST_LOG_UTILS_METHOD_NAME_USE_PERSIST_LOG_ADAPTER);
2210
2293
  this.PersistLogFactory = Ctor;
2211
2294
  }
2295
+ /**
2296
+ * Clears the cached storage instance.
2297
+ * Call this when process.cwd() changes between strategy iterations
2298
+ * so a new storage instance is created with the updated base path.
2299
+ */
2300
+ clear() {
2301
+ bt.loggerService.log(PERSIST_LOG_UTILS_METHOD_NAME_CLEAR);
2302
+ this._logStorage = null;
2303
+ }
2212
2304
  /**
2213
2305
  * Switches to the default JSON persist adapter.
2214
2306
  * All future persistence writes will use JSON storage.
@@ -2297,6 +2389,15 @@ class PersistMeasureUtils {
2297
2389
  bt.loggerService.info(PERSIST_MEASURE_UTILS_METHOD_NAME_USE_PERSIST_MEASURE_ADAPTER);
2298
2390
  this.PersistMeasureFactory = Ctor;
2299
2391
  }
2392
+ /**
2393
+ * Clears the memoized storage cache.
2394
+ * Call this when process.cwd() changes between strategy iterations
2395
+ * so new storage instances are created with the updated base path.
2396
+ */
2397
+ clear() {
2398
+ bt.loggerService.log(PERSIST_MEASURE_UTILS_METHOD_NAME_CLEAR);
2399
+ this.getMeasureStorage.clear();
2400
+ }
2300
2401
  /**
2301
2402
  * Switches to the default JSON persist adapter.
2302
2403
  */
@@ -2440,16 +2541,24 @@ class PersistMemoryUtils {
2440
2541
  }
2441
2542
  };
2442
2543
  /**
2443
- * Dispose persist adapter to prevent memory leak
2544
+ * Clears the memoized storage cache.
2545
+ * Call this when process.cwd() changes between strategy iterations
2546
+ * so new storage instances are created with the updated base path.
2547
+ */
2548
+ this.clear = () => {
2549
+ bt.loggerService.info(PERSIST_MEMORY_UTILS_METHOD_NAME_CLEAR);
2550
+ this.getMemoryStorage.clear();
2551
+ };
2552
+ /**
2553
+ * Disposes of the memory adapter and releases any resources.
2554
+ * Call this when a signal is removed to clean up its associated storage.
2444
2555
  *
2445
2556
  * @param signalId - Signal identifier
2446
2557
  * @param bucketName - Bucket name
2558
+ * @returns void
2447
2559
  */
2448
- this.clear = (signalId, bucketName) => {
2449
- bt.loggerService.info(PERSIST_MEMORY_UTILS_METHOD_NAME_CLEAR, {
2450
- signalId,
2451
- bucketName,
2452
- });
2560
+ this.dispose = (signalId, bucketName) => {
2561
+ bt.loggerService.info(PERSIST_MEMORY_UTILS_METHOD_NAME_DISPOSE);
2453
2562
  const key = `${signalId}:${bucketName}`;
2454
2563
  this.getMemoryStorage.clear(key);
2455
2564
  };
@@ -19554,6 +19663,7 @@ const MARKDOWN_METHOD_NAME_WRITE_DATA = "MarkdownAdapter.writeData";
19554
19663
  const MARKDOWN_METHOD_NAME_USE_MD = "MarkdownAdapter.useMd";
19555
19664
  const MARKDOWN_METHOD_NAME_USE_JSONL = "MarkdownAdapter.useJsonl";
19556
19665
  const MARKDOWN_METHOD_NAME_USE_DUMMY = "MarkdownAdapter.useDummy";
19666
+ const MARKDOWN_METHOD_NAME_CLEAR = "MarkdownAdapter.clear";
19557
19667
  /** Symbol key for the singleshot waitForInit function on MarkdownFileBase instances. */
19558
19668
  const WAIT_FOR_INIT_SYMBOL$2 = Symbol("wait-for-init");
19559
19669
  /** Symbol key for the timeout-protected write function on MarkdownFileBase instances. */
@@ -20025,6 +20135,15 @@ class MarkdownAdapter extends MarkdownUtils {
20025
20135
  bt.loggerService.debug(MARKDOWN_METHOD_NAME_USE_JSONL);
20026
20136
  this.useMarkdownAdapter(MarkdownFileBase);
20027
20137
  }
20138
+ /**
20139
+ * Clears the memoized storage cache.
20140
+ * Call this when process.cwd() changes between strategy iterations
20141
+ * so new storage instances are created with the updated base path.
20142
+ */
20143
+ clear() {
20144
+ bt.loggerService.log(MARKDOWN_METHOD_NAME_CLEAR);
20145
+ this.getMarkdownStorage.clear();
20146
+ }
20028
20147
  /**
20029
20148
  * Switches to a dummy markdown adapter that discards all writes.
20030
20149
  * All future markdown writes will be no-ops.
@@ -26826,6 +26945,7 @@ const REPORT_UTILS_METHOD_NAME_ENABLE = "ReportUtils.enable";
26826
26945
  const REPORT_UTILS_METHOD_NAME_DISABLE = "ReportUtils.disable";
26827
26946
  const REPORT_UTILS_METHOD_NAME_USE_DUMMY = "ReportUtils.useDummy";
26828
26947
  const REPORT_UTILS_METHOD_NAME_USE_JSONL = "ReportUtils.useJsonl";
26948
+ const REPORT_UTILS_METHOD_NAME_CLEAR = "ReportUtils.clear";
26829
26949
  /** Symbol key for the singleshot waitForInit function on ReportBase instances. */
26830
26950
  const WAIT_FOR_INIT_SYMBOL$1 = Symbol("wait-for-init");
26831
26951
  /** Symbol key for the timeout-protected write function on ReportBase instances. */
@@ -27235,6 +27355,15 @@ class ReportAdapter extends ReportUtils {
27235
27355
  bt.loggerService.info(REPORT_UTILS_METHOD_NAME_USE_REPORT_ADAPTER);
27236
27356
  this.ReportFactory = Ctor;
27237
27357
  }
27358
+ /**
27359
+ * Clears the memoized storage cache.
27360
+ * Call this when process.cwd() changes between strategy iterations
27361
+ * so new storage instances are created with the updated base path.
27362
+ */
27363
+ clear() {
27364
+ bt.loggerService.log(REPORT_UTILS_METHOD_NAME_CLEAR);
27365
+ this.getReportStorage.clear();
27366
+ }
27238
27367
  /**
27239
27368
  * Switches to a dummy report adapter that discards all writes.
27240
27369
  * All future report writes will be no-ops.
@@ -33559,6 +33688,7 @@ const BROKER_METHOD_NAME_COMMIT_AVERAGE_BUY = "BrokerAdapter.commitAverageBuy";
33559
33688
  const BROKER_METHOD_NAME_USE_BROKER_ADAPTER = "BrokerAdapter.useBrokerAdapter";
33560
33689
  const BROKER_METHOD_NAME_ENABLE = "BrokerAdapter.enable";
33561
33690
  const BROKER_METHOD_NAME_DISABLE = "BrokerAdapter.disable";
33691
+ const BROKER_METHOD_NAME_CLEAR = "BrokerAdapter.clear";
33562
33692
  const BROKER_BASE_METHOD_NAME_WAIT_FOR_INIT = "BrokerBase.waitForInit";
33563
33693
  const BROKER_BASE_METHOD_NAME_ON_SIGNAL_OPEN = "BrokerBase.onSignalOpenCommit";
33564
33694
  const BROKER_BASE_METHOD_NAME_ON_SIGNAL_CLOSE = "BrokerBase.onSignalCloseCommit";
@@ -34158,6 +34288,16 @@ class BrokerAdapter {
34158
34288
  lastSubscription();
34159
34289
  }
34160
34290
  };
34291
+ /**
34292
+ * Clears the cached broker instance and resets the enable singleshot.
34293
+ * Call this when process.cwd() changes between strategy iterations
34294
+ * so a new broker instance is created with the updated base path.
34295
+ */
34296
+ this.clear = () => {
34297
+ bt.loggerService.info(BROKER_METHOD_NAME_CLEAR, {});
34298
+ this._brokerInstance = null;
34299
+ this.enable.clear();
34300
+ };
34161
34301
  }
34162
34302
  }
34163
34303
  /**
@@ -43451,6 +43591,7 @@ const MEMORY_ADAPTER_METHOD_NAME_READ = "MemoryAdapter.readMemory";
43451
43591
  const MEMORY_ADAPTER_METHOD_NAME_USE_LOCAL = "MemoryAdapter.useLocal";
43452
43592
  const MEMORY_ADAPTER_METHOD_NAME_USE_PERSIST = "MemoryAdapter.usePersist";
43453
43593
  const MEMORY_ADAPTER_METHOD_NAME_USE_DUMMY = "MemoryAdapter.useDummy";
43594
+ const MEMORY_ADAPTER_METHOD_NAME_CLEAR = "MemoryAdapter.clear";
43454
43595
  /**
43455
43596
  * In-memory BM25 search index backed instance.
43456
43597
  * All data lives in the process memory only - no disk persistence.
@@ -43673,7 +43814,7 @@ class MemoryPersistInstance {
43673
43814
  signalId: this.signalId,
43674
43815
  bucketName: this.bucketName,
43675
43816
  });
43676
- PersistMemoryAdapter.clear(this.signalId, this.bucketName);
43817
+ PersistMemoryAdapter.dispose(this.signalId, this.bucketName);
43677
43818
  }
43678
43819
  }
43679
43820
  /**
@@ -43911,6 +44052,15 @@ class MemoryAdapter {
43911
44052
  bt.loggerService.info(MEMORY_ADAPTER_METHOD_NAME_USE_DUMMY);
43912
44053
  this.MemoryFactory = MemoryDummyInstance;
43913
44054
  };
44055
+ /**
44056
+ * Clears the memoized instance cache.
44057
+ * Call this when process.cwd() changes between strategy iterations
44058
+ * so new instances are created with the updated base path.
44059
+ */
44060
+ this.clear = () => {
44061
+ bt.loggerService.info(MEMORY_ADAPTER_METHOD_NAME_CLEAR);
44062
+ this.getInstance.clear();
44063
+ };
43914
44064
  /**
43915
44065
  * Releases resources held by this adapter.
43916
44066
  * Delegates to disable() to unsubscribe from signal lifecycle events.
@@ -44198,6 +44348,7 @@ const DUMP_ADAPTER_METHOD_NAME_USE_MEMORY = "DumpAdapter.useMemory";
44198
44348
  const DUMP_ADAPTER_METHOD_NAME_USE_DUMMY = "DumpAdapter.useDummy";
44199
44349
  const DUMP_ADAPTER_METHOD_NAME_USE_BOTH = "DumpAdapter.useMarkdownMemoryBoth";
44200
44350
  const DUMP_ADAPTER_METHOD_NAME_USE_ADAPTER = "DumpAdapter.useDumpAdapter";
44351
+ const DUMP_ADAPTER_METHOD_NAME_CLEAR = "DumpAdapter.clear";
44201
44352
  /**
44202
44353
  * Renders a single MessageModel as a markdown section.
44203
44354
  * tool_calls are rendered as a fenced JSON block.
@@ -44955,6 +45106,15 @@ class DumpAdapter {
44955
45106
  bt.loggerService.info(DUMP_ADAPTER_METHOD_NAME_USE_ADAPTER);
44956
45107
  this.DumpFactory = Ctor;
44957
45108
  };
45109
+ /**
45110
+ * Clears the memoized instance cache.
45111
+ * Call this when process.cwd() changes between strategy iterations
45112
+ * so new instances are created with the updated base path.
45113
+ */
45114
+ this.clear = () => {
45115
+ bt.loggerService.info(DUMP_ADAPTER_METHOD_NAME_CLEAR);
45116
+ this.getInstance.clear();
45117
+ };
44958
45118
  }
44959
45119
  }
44960
45120
  const Dump = new DumpAdapter();
@@ -45275,6 +45435,7 @@ const LOG_ADAPTER_METHOD_NAME_USE_PERSIST = "LogAdapter.usePersist";
45275
45435
  const LOG_ADAPTER_METHOD_NAME_USE_MEMORY = "LogAdapter.useMemory";
45276
45436
  const LOG_ADAPTER_METHOD_NAME_USE_DUMMY = "LogAdapter.useDummy";
45277
45437
  const LOG_ADAPTER_METHOD_NAME_USE_JSONL = "LogAdapter.useJsonl";
45438
+ const LOG_ADAPTER_METHOD_NAME_CLEAR = "LogAdapter.clear";
45278
45439
  const LOG_JSONL_METHOD_NAME_LOG = "LogJsonlUtils.log";
45279
45440
  const LOG_JSONL_METHOD_NAME_DEBUG = "LogJsonlUtils.debug";
45280
45441
  const LOG_JSONL_METHOD_NAME_INFO = "LogJsonlUtils.info";
@@ -45896,6 +46057,15 @@ class LogAdapter {
45896
46057
  bt.loggerService.info(LOG_ADAPTER_METHOD_NAME_USE_JSONL);
45897
46058
  this._log = new LogJsonlUtils(fileName, dirName);
45898
46059
  };
46060
+ /**
46061
+ * Clears the cached log instance by resetting to the default in-memory adapter.
46062
+ * Call this when process.cwd() changes between strategy iterations
46063
+ * so a new adapter instance is created with the updated base path.
46064
+ */
46065
+ this.clear = () => {
46066
+ bt.loggerService.info(LOG_ADAPTER_METHOD_NAME_CLEAR);
46067
+ this._log = new LogMemoryUtils();
46068
+ };
45899
46069
  }
45900
46070
  }
45901
46071
  /**
@@ -47623,10 +47793,12 @@ const STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_ADAPTER = "StorageBacktestAdapter
47623
47793
  const STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_DUMMY = "StorageBacktestAdapter.useDummy";
47624
47794
  const STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_PERSIST = "StorageBacktestAdapter.usePersist";
47625
47795
  const STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_MEMORY = "StorageBacktestAdapter.useMemory";
47796
+ const STORAGE_BACKTEST_ADAPTER_METHOD_NAME_CLEAR = "StorageBacktestAdapter.clear";
47626
47797
  const STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_ADAPTER = "StorageLiveAdapter.useStorageAdapter";
47627
47798
  const STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_DUMMY = "StorageLiveAdapter.useDummy";
47628
47799
  const STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_PERSIST = "StorageLiveAdapter.usePersist";
47629
47800
  const STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_MEMORY = "StorageLiveAdapter.useMemory";
47801
+ const STORAGE_LIVE_ADAPTER_METHOD_NAME_CLEAR = "StorageLiveAdapter.clear";
47630
47802
  /**
47631
47803
  * Persistent storage adapter for backtest signals.
47632
47804
  *
@@ -48613,6 +48785,15 @@ class StorageBacktestAdapter {
48613
48785
  bt.loggerService.info(STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_MEMORY);
48614
48786
  this._signalBacktestUtils = new StorageMemoryBacktestUtils();
48615
48787
  };
48788
+ /**
48789
+ * Clears the cached utils instance by resetting to the default in-memory adapter.
48790
+ * Call this when process.cwd() changes between strategy iterations
48791
+ * so a new instance is created with the updated base path.
48792
+ */
48793
+ this.clear = () => {
48794
+ bt.loggerService.info(STORAGE_BACKTEST_ADAPTER_METHOD_NAME_CLEAR);
48795
+ this._signalBacktestUtils = new StorageMemoryBacktestUtils();
48796
+ };
48616
48797
  }
48617
48798
  }
48618
48799
  /**
@@ -48717,6 +48898,15 @@ class StorageLiveAdapter {
48717
48898
  bt.loggerService.info(STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_MEMORY);
48718
48899
  this._signalLiveUtils = new StorageMemoryLiveUtils();
48719
48900
  };
48901
+ /**
48902
+ * Clears the cached utils instance by resetting to the default persistent adapter.
48903
+ * Call this when process.cwd() changes between strategy iterations
48904
+ * so a new instance is created with the updated base path.
48905
+ */
48906
+ this.clear = () => {
48907
+ bt.loggerService.info(STORAGE_LIVE_ADAPTER_METHOD_NAME_CLEAR);
48908
+ this._signalLiveUtils = new StoragePersistLiveUtils();
48909
+ };
48720
48910
  }
48721
48911
  }
48722
48912
  /**
@@ -49537,7 +49727,7 @@ const NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_HANDLE_ERROR = "NotificationMemor
49537
49727
  const NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_HANDLE_CRITICAL_ERROR = "NotificationMemoryBacktestUtils.handleCriticalError";
49538
49728
  const NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_HANDLE_VALIDATION_ERROR = "NotificationMemoryBacktestUtils.handleValidationError";
49539
49729
  const NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_GET_DATA = "NotificationMemoryBacktestUtils.getData";
49540
- const NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_CLEAR = "NotificationMemoryBacktestUtils.clear";
49730
+ const NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_DISPOSE = "NotificationMemoryBacktestUtils.dispose";
49541
49731
  const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_HANDLE_SIGNAL = "NotificationMemoryLiveUtils.handleSignal";
49542
49732
  const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_HANDLE_PARTIAL_PROFIT = "NotificationMemoryLiveUtils.handlePartialProfit";
49543
49733
  const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_HANDLE_PARTIAL_LOSS = "NotificationMemoryLiveUtils.handlePartialLoss";
@@ -49549,19 +49739,21 @@ const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_HANDLE_ERROR = "NotificationMemoryLiv
49549
49739
  const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_HANDLE_CRITICAL_ERROR = "NotificationMemoryLiveUtils.handleCriticalError";
49550
49740
  const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_HANDLE_VALIDATION_ERROR = "NotificationMemoryLiveUtils.handleValidationError";
49551
49741
  const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_GET_DATA = "NotificationMemoryLiveUtils.getData";
49552
- const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_CLEAR = "NotificationMemoryLiveUtils.clear";
49742
+ const NOTIFICATION_MEMORY_LIVE_METHOD_NAME_DISPOSE = "NotificationMemoryLiveUtils.clear";
49553
49743
  const NOTIFICATION_ADAPTER_METHOD_NAME_ENABLE = "NotificationAdapter.enable";
49554
49744
  const NOTIFICATION_ADAPTER_METHOD_NAME_DISABLE = "NotificationAdapter.disable";
49555
49745
  const NOTIFICATION_ADAPTER_METHOD_NAME_GET_DATA_BACKTEST = "NotificationAdapter.getDataBacktest";
49556
- const NOTIFICATION_ADAPTER_METHOD_NAME_CLEAR_LIVE = "NotificationAdapter.clearLive";
49746
+ const NOTIFICATION_ADAPTER_METHOD_NAME_DISPOSE_LIVE = "NotificationAdapter.disposeLive";
49557
49747
  const NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_ADAPTER = "NotificationBacktestAdapter.useNotificationAdapter";
49558
49748
  const NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_DUMMY = "NotificationBacktestAdapter.useDummy";
49559
49749
  const NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_MEMORY = "NotificationBacktestAdapter.useMemory";
49560
49750
  const NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_PERSIST = "NotificationBacktestAdapter.usePersist";
49751
+ const NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_CLEAR = "NotificationBacktestAdapter.clear";
49561
49752
  const NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_ADAPTER = "NotificationLiveAdapter.useNotificationAdapter";
49562
49753
  const NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_DUMMY = "NotificationLiveAdapter.useDummy";
49563
49754
  const NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_MEMORY = "NotificationLiveAdapter.useMemory";
49564
49755
  const NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_PERSIST = "NotificationLiveAdapter.usePersist";
49756
+ const NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_CLEAR = "NotificationLiveAdapter.clear";
49565
49757
  const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_WAIT_FOR_INIT = "NotificationPersistBacktestUtils.waitForInit";
49566
49758
  const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_UPDATE_NOTIFICATIONS = "NotificationPersistBacktestUtils._updateNotifications";
49567
49759
  const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_HANDLE_SIGNAL = "NotificationPersistBacktestUtils.handleSignal";
@@ -49575,7 +49767,7 @@ const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_HANDLE_ERROR = "NotificationPers
49575
49767
  const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_HANDLE_CRITICAL_ERROR = "NotificationPersistBacktestUtils.handleCriticalError";
49576
49768
  const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_HANDLE_VALIDATION_ERROR = "NotificationPersistBacktestUtils.handleValidationError";
49577
49769
  const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_GET_DATA = "NotificationPersistBacktestUtils.getData";
49578
- const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_CLEAR = "NotificationPersistBacktestUtils.clear";
49770
+ const NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_DISPOSE = "NotificationPersistBacktestUtils.clear";
49579
49771
  const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_WAIT_FOR_INIT = "NotificationPersistLiveUtils.waitForInit";
49580
49772
  const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_UPDATE_NOTIFICATIONS = "NotificationPersistLiveUtils._updateNotifications";
49581
49773
  const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_HANDLE_SIGNAL = "NotificationPersistLiveUtils.handleSignal";
@@ -49589,7 +49781,7 @@ const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_HANDLE_ERROR = "NotificationPersistL
49589
49781
  const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_HANDLE_CRITICAL_ERROR = "NotificationPersistLiveUtils.handleCriticalError";
49590
49782
  const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_HANDLE_VALIDATION_ERROR = "NotificationPersistLiveUtils.handleValidationError";
49591
49783
  const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_GET_DATA = "NotificationPersistLiveUtils.getData";
49592
- const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_CLEAR = "NotificationPersistLiveUtils.clear";
49784
+ const NOTIFICATION_PERSIST_LIVE_METHOD_NAME_DISPOSE = "NotificationPersistLiveUtils.clear";
49593
49785
  /**
49594
49786
  * In-memory notification adapter for backtest signals.
49595
49787
  *
@@ -49732,8 +49924,8 @@ class NotificationMemoryBacktestUtils {
49732
49924
  /**
49733
49925
  * Clears all stored notifications.
49734
49926
  */
49735
- this.clear = async () => {
49736
- bt.loggerService.info(NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_CLEAR);
49927
+ this.dispose = async () => {
49928
+ bt.loggerService.info(NOTIFICATION_MEMORY_BACKTEST_METHOD_NAME_DISPOSE);
49737
49929
  this._notifications = [];
49738
49930
  };
49739
49931
  }
@@ -49822,7 +50014,7 @@ class NotificationDummyBacktestUtils {
49822
50014
  /**
49823
50015
  * No-op clear operation.
49824
50016
  */
49825
- this.clear = async () => {
50017
+ this.dispose = async () => {
49826
50018
  };
49827
50019
  }
49828
50020
  }
@@ -50002,8 +50194,8 @@ class NotificationPersistBacktestUtils {
50002
50194
  /**
50003
50195
  * Clears all stored notifications.
50004
50196
  */
50005
- this.clear = async () => {
50006
- bt.loggerService.info(NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_CLEAR);
50197
+ this.dispose = async () => {
50198
+ bt.loggerService.info(NOTIFICATION_PERSIST_BACKTEST_METHOD_NAME_DISPOSE);
50007
50199
  await this.waitForInit();
50008
50200
  this._notifications.clear();
50009
50201
  await this._updateNotifications();
@@ -50184,8 +50376,8 @@ class NotificationMemoryLiveUtils {
50184
50376
  /**
50185
50377
  * Clears all stored notifications.
50186
50378
  */
50187
- this.clear = async () => {
50188
- bt.loggerService.info(NOTIFICATION_MEMORY_LIVE_METHOD_NAME_CLEAR);
50379
+ this.dispose = async () => {
50380
+ bt.loggerService.info(NOTIFICATION_MEMORY_LIVE_METHOD_NAME_DISPOSE);
50189
50381
  this._notifications = [];
50190
50382
  };
50191
50383
  }
@@ -50274,7 +50466,7 @@ class NotificationDummyLiveUtils {
50274
50466
  /**
50275
50467
  * No-op clear operation.
50276
50468
  */
50277
- this.clear = async () => {
50469
+ this.dispose = async () => {
50278
50470
  };
50279
50471
  }
50280
50472
  }
@@ -50455,8 +50647,8 @@ class NotificationPersistLiveUtils {
50455
50647
  /**
50456
50648
  * Clears all stored notifications.
50457
50649
  */
50458
- this.clear = async () => {
50459
- bt.loggerService.info(NOTIFICATION_PERSIST_LIVE_METHOD_NAME_CLEAR);
50650
+ this.dispose = async () => {
50651
+ bt.loggerService.info(NOTIFICATION_PERSIST_LIVE_METHOD_NAME_DISPOSE);
50460
50652
  await this.waitForInit();
50461
50653
  this._notifications.clear();
50462
50654
  await this._updateNotifications();
@@ -50604,8 +50796,8 @@ class NotificationBacktestAdapter {
50604
50796
  * Clears all stored notifications.
50605
50797
  * Proxies call to the underlying notification adapter.
50606
50798
  */
50607
- this.clear = async () => {
50608
- return await this._notificationBacktestUtils.clear();
50799
+ this.dispose = async () => {
50800
+ return await this._notificationBacktestUtils.dispose();
50609
50801
  };
50610
50802
  /**
50611
50803
  * Sets the notification adapter constructor.
@@ -50641,6 +50833,15 @@ class NotificationBacktestAdapter {
50641
50833
  bt.loggerService.info(NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_PERSIST);
50642
50834
  this._notificationBacktestUtils = new NotificationPersistBacktestUtils();
50643
50835
  };
50836
+ /**
50837
+ * Resets the cached utils instance to the default in-memory adapter.
50838
+ * Call this when process.cwd() changes between strategy iterations
50839
+ * so a new instance is created with the updated base path.
50840
+ */
50841
+ this.clear = () => {
50842
+ bt.loggerService.info(NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_CLEAR);
50843
+ this._notificationBacktestUtils = new NotificationMemoryBacktestUtils();
50844
+ };
50644
50845
  }
50645
50846
  }
50646
50847
  /**
@@ -50750,8 +50951,8 @@ class NotificationLiveAdapter {
50750
50951
  * Clears all stored notifications.
50751
50952
  * Proxies call to the underlying notification adapter.
50752
50953
  */
50753
- this.clear = async () => {
50754
- return await this._notificationLiveUtils.clear();
50954
+ this.dispose = async () => {
50955
+ return await this._notificationLiveUtils.dispose();
50755
50956
  };
50756
50957
  /**
50757
50958
  * Sets the notification adapter constructor.
@@ -50787,6 +50988,15 @@ class NotificationLiveAdapter {
50787
50988
  bt.loggerService.info(NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_PERSIST);
50788
50989
  this._notificationLiveUtils = new NotificationPersistLiveUtils();
50789
50990
  };
50991
+ /**
50992
+ * Resets the cached utils instance to the default in-memory adapter.
50993
+ * Call this when process.cwd() changes between strategy iterations
50994
+ * so a new instance is created with the updated base path.
50995
+ */
50996
+ this.clear = () => {
50997
+ bt.loggerService.info(NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_CLEAR);
50998
+ this._notificationLiveUtils = new NotificationMemoryLiveUtils();
50999
+ };
50790
51000
  }
50791
51001
  }
50792
51002
  /**
@@ -50900,17 +51110,17 @@ class NotificationAdapter {
50900
51110
  *
50901
51111
  * @throws Error if NotificationAdapter is not enabled
50902
51112
  */
50903
- this.clear = async (isBacktest) => {
50904
- bt.loggerService.info(NOTIFICATION_ADAPTER_METHOD_NAME_CLEAR_LIVE, {
51113
+ this.dispose = async (isBacktest) => {
51114
+ bt.loggerService.info(NOTIFICATION_ADAPTER_METHOD_NAME_DISPOSE_LIVE, {
50905
51115
  backtest: isBacktest,
50906
51116
  });
50907
51117
  if (!this.enable.hasValue()) {
50908
51118
  throw new Error("NotificationAdapter is not enabled. Call enable() first.");
50909
51119
  }
50910
51120
  if (isBacktest) {
50911
- return await NotificationBacktest.clear();
51121
+ return await NotificationBacktest.dispose();
50912
51122
  }
50913
- return await NotificationLive.clear();
51123
+ return await NotificationLive.dispose();
50914
51124
  };
50915
51125
  }
50916
51126
  }
@@ -50930,12 +51140,14 @@ const NotificationLive = new NotificationLiveAdapter();
50930
51140
  */
50931
51141
  const NotificationBacktest = new NotificationBacktestAdapter();
50932
51142
 
50933
- const CACHE_METHOD_NAME_FLUSH = "CacheUtils.flush";
50934
- const CACHE_METHOD_NAME_CLEAR = "CacheInstance.clear";
50935
51143
  const CACHE_METHOD_NAME_RUN = "CacheInstance.run";
50936
- const CACHE_METHOD_NAME_GC = "CacheInstance.gc";
50937
51144
  const CACHE_METHOD_NAME_FN = "CacheUtils.fn";
51145
+ const CACHE_METHOD_NAME_FN_CLEAR = "CacheUtils.fn.clear";
51146
+ const CACHE_METHOD_NAME_FN_GC = "CacheUtils.fn.gc";
50938
51147
  const CACHE_METHOD_NAME_FILE = "CacheUtils.file";
51148
+ const CACHE_METHOD_NAME_FILE_CLEAR = "CacheUtils.file.clear";
51149
+ const CACHE_METHOD_NAME_DISPOSE = "CacheUtils.dispose";
51150
+ const CACHE_METHOD_NAME_CLEAR = "CacheUtils.clear";
50939
51151
  const CACHE_FILE_INSTANCE_METHOD_NAME_RUN = "CacheFileInstance.run";
50940
51152
  const MS_PER_MINUTE = 60000;
50941
51153
  const INTERVAL_MINUTES = {
@@ -51184,6 +51396,12 @@ class CacheFileInstance {
51184
51396
  static createIndex() {
51185
51397
  return CacheFileInstance._indexCounter++;
51186
51398
  }
51399
+ /**
51400
+ * Clears the index counter.
51401
+ */
51402
+ static clearCounter() {
51403
+ CacheFileInstance._indexCounter = 0;
51404
+ }
51187
51405
  /**
51188
51406
  * Creates a new CacheFileInstance.
51189
51407
  *
@@ -51317,6 +51535,26 @@ class CacheUtils {
51317
51535
  const instance = this._getFnInstance(run, context.interval, context.key);
51318
51536
  return instance.run(...args).value;
51319
51537
  };
51538
+ wrappedFn.clear = () => {
51539
+ bt.loggerService.info(CACHE_METHOD_NAME_FN_CLEAR);
51540
+ if (!MethodContextService.hasContext()) {
51541
+ bt.loggerService.warn(`${CACHE_METHOD_NAME_FN_CLEAR} called without method context, skipping`);
51542
+ return;
51543
+ }
51544
+ if (!ExecutionContextService.hasContext()) {
51545
+ bt.loggerService.warn(`${CACHE_METHOD_NAME_FN_CLEAR} called without execution context, skipping`);
51546
+ return;
51547
+ }
51548
+ this._getFnInstance.get(run)?.clear();
51549
+ };
51550
+ wrappedFn.gc = () => {
51551
+ bt.loggerService.info(CACHE_METHOD_NAME_FN_GC);
51552
+ if (!ExecutionContextService.hasContext()) {
51553
+ bt.loggerService.warn(`${CACHE_METHOD_NAME_FN_GC} called without execution context, skipping`);
51554
+ return;
51555
+ }
51556
+ return this._getFnInstance.get(run)?.gc();
51557
+ };
51320
51558
  return wrappedFn;
51321
51559
  };
51322
51560
  /**
@@ -51363,117 +51601,51 @@ class CacheUtils {
51363
51601
  const instance = this._getFileInstance(run, context.interval, context.name, context.key);
51364
51602
  return instance.run(...args);
51365
51603
  };
51604
+ wrappedFn.clear = () => {
51605
+ bt.loggerService.info(CACHE_METHOD_NAME_FILE_CLEAR);
51606
+ this._getFileInstance.clear(run);
51607
+ };
51366
51608
  return wrappedFn;
51367
51609
  };
51368
51610
  /**
51369
- * Flush (remove) cached CacheInstance for a specific function or all functions.
51370
- *
51371
- * This method removes CacheInstance objects from the internal memoization cache.
51372
- * When a CacheInstance is flushed, all cached results across all contexts
51373
- * (all strategy/exchange/mode combinations) for that function are discarded.
51611
+ * Dispose (remove) the memoized CacheInstance for a specific function.
51374
51612
  *
51375
- * Use cases:
51376
- * - Remove specific function's CacheInstance when implementation changes
51377
- * - Free memory by removing unused CacheInstances
51378
- * - Reset all CacheInstances when switching between different test scenarios
51379
- *
51380
- * Note: This is different from `clear()` which only removes cached values
51381
- * for the current context within an existing CacheInstance.
51613
+ * Removes the CacheInstance from the internal memoization cache, discarding all cached
51614
+ * results across all contexts (all strategy/exchange/mode combinations) for that function.
51615
+ * The next call to the wrapped function will create a fresh CacheInstance.
51382
51616
  *
51383
51617
  * @template T - Function type
51384
- * @param run - Optional function to flush CacheInstance for. If omitted, flushes all CacheInstances.
51618
+ * @param run - Function whose CacheInstance should be disposed.
51385
51619
  *
51386
51620
  * @example
51387
51621
  * ```typescript
51388
51622
  * const cachedFn = Cache.fn(calculateIndicator, { interval: "1h" });
51389
51623
  *
51390
- * // Flush CacheInstance for specific function
51391
- * Cache.flush(calculateIndicator);
51392
- *
51393
- * // Flush all CacheInstances
51394
- * Cache.flush();
51624
+ * // Dispose CacheInstance for a specific function
51625
+ * Cache.dispose(calculateIndicator);
51395
51626
  * ```
51396
51627
  */
51397
- this.flush = (run) => {
51398
- bt.loggerService.info(CACHE_METHOD_NAME_FLUSH, {
51628
+ this.dispose = (run) => {
51629
+ bt.loggerService.info(CACHE_METHOD_NAME_DISPOSE, {
51399
51630
  run,
51400
51631
  });
51401
- this._getFnInstance.clear(run);
51402
- };
51403
- /**
51404
- * Clear cached value for current execution context of a specific function.
51405
- *
51406
- * Removes the cached entry for the current strategy/exchange/mode combination
51407
- * from the specified function's CacheInstance. The next call to the wrapped function
51408
- * will recompute the value for that context.
51409
- *
51410
- * This only clears the cache for the current execution context, not all contexts.
51411
- * Use `flush()` to remove the entire CacheInstance across all contexts.
51412
- *
51413
- * Requires active execution context (strategy, exchange, backtest mode) and method context.
51414
- *
51415
- * @template T - Function type
51416
- * @param run - Function whose cache should be cleared for current context
51417
- *
51418
- * @example
51419
- * ```typescript
51420
- * const cachedFn = Cache.fn(calculateIndicator, { interval: "1h" });
51421
- *
51422
- * // Within strategy execution context
51423
- * const result1 = cachedFn("BTCUSDT", 14); // Computed
51424
- * const result2 = cachedFn("BTCUSDT", 14); // Cached
51425
- *
51426
- * Cache.clear(calculateIndicator); // Clear cache for current context only
51427
- *
51428
- * const result3 = cachedFn("BTCUSDT", 14); // Recomputed for this context
51429
- * // Other contexts (different strategies/exchanges) remain cached
51430
- * ```
51431
- */
51432
- this.clear = (run) => {
51433
- bt.loggerService.info(CACHE_METHOD_NAME_CLEAR, {
51434
- run,
51435
- });
51436
- if (!MethodContextService.hasContext()) {
51437
- console.warn(`${CACHE_METHOD_NAME_CLEAR} called without method context, skipping clear`);
51438
- return;
51439
- }
51440
- if (!ExecutionContextService.hasContext()) {
51441
- console.warn(`${CACHE_METHOD_NAME_CLEAR} called without execution context, skipping clear`);
51442
- return;
51632
+ {
51633
+ this._getFnInstance.clear(run);
51634
+ this._getFileInstance.clear(run);
51443
51635
  }
51444
- this._getFnInstance.get(run).clear();
51445
51636
  };
51446
51637
  /**
51447
- * Garbage collect expired cache entries for a specific function.
51448
- *
51449
- * Removes all cached entries whose interval has expired (not aligned with current time).
51450
- * Call this periodically to free memory from stale cache entries.
51451
- *
51452
- * Requires active execution context to get current time.
51453
- *
51454
- * @template T - Function type
51455
- * @param run - Function whose expired cache entries should be removed
51456
- * @returns Number of entries removed
51457
- *
51458
- * @example
51459
- * ```typescript
51460
- * const cachedFn = Cache.fn(calculateIndicator, { interval: "1h" });
51461
- *
51462
- * cachedFn("BTCUSDT", 14); // Cached at 10:00
51463
- * cachedFn("ETHUSDT", 14); // Cached at 10:00
51464
- * // Time passes to 11:00
51465
- * const removed = Cache.gc(calculateIndicator); // Returns 2
51466
- * ```
51638
+ * Clears all memoized CacheInstance and CacheFileInstance objects.
51639
+ * Call this when process.cwd() changes between strategy iterations
51640
+ * so new instances are created with the updated base path.
51467
51641
  */
51468
- this.gc = (run) => {
51469
- bt.loggerService.info(CACHE_METHOD_NAME_GC, {
51470
- run,
51471
- });
51472
- if (!ExecutionContextService.hasContext()) {
51473
- console.warn(`${CACHE_METHOD_NAME_GC} called without execution context, skipping garbage collection`);
51474
- return;
51642
+ this.clear = () => {
51643
+ bt.loggerService.info(CACHE_METHOD_NAME_CLEAR);
51644
+ {
51645
+ this._getFnInstance.clear();
51646
+ this._getFileInstance.clear();
51475
51647
  }
51476
- return this._getFnInstance.get(run).gc();
51648
+ CacheFileInstance.clearCounter();
51477
51649
  };
51478
51650
  }
51479
51651
  }