backtest-kit 9.0.1 → 9.0.2

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
@@ -3581,7 +3581,7 @@ class PersistMemoryInstance {
3581
3581
  * @param memoryId - Memory entry identifier
3582
3582
  * @returns Promise that resolves when write is complete
3583
3583
  */
3584
- async writeMemoryData(data, memoryId) {
3584
+ async writeMemoryData(data, memoryId, _when) {
3585
3585
  await this._storage.writeValue(memoryId, data);
3586
3586
  }
3587
3587
  /**
@@ -3646,7 +3646,7 @@ class PersistMemoryDummyInstance {
3646
3646
  * No-op write (discards entry).
3647
3647
  * @returns Promise that resolves immediately
3648
3648
  */
3649
- async writeMemoryData(_data, _memoryId) { }
3649
+ async writeMemoryData(_data, _memoryId, _when) { }
3650
3650
  /**
3651
3651
  * No-op remove.
3652
3652
  * @returns Promise that resolves immediately
@@ -3739,19 +3739,20 @@ class PersistMemoryUtils {
3739
3739
  * Writes a memory entry for the given context.
3740
3740
  * Lazily initializes the instance on first access.
3741
3741
  *
3742
- * @param data - Entry data to persist
3742
+ * @param data - Entry data to persist (already carries `data.when`)
3743
3743
  * @param signalId - Signal identifier
3744
3744
  * @param bucketName - Bucket name
3745
3745
  * @param memoryId - Memory entry identifier
3746
+ * @param when - Logical timestamp this entry belongs to (duplicates `data.when` for API consistency)
3746
3747
  * @returns Promise that resolves when write is complete
3747
3748
  */
3748
- this.writeMemoryData = async (data, signalId, bucketName, memoryId) => {
3749
+ this.writeMemoryData = async (data, signalId, bucketName, memoryId, when) => {
3749
3750
  LOGGER_SERVICE$7.info(PERSIST_MEMORY_UTILS_METHOD_NAME_WRITE_DATA, { signalId, bucketName, memoryId });
3750
3751
  const key = `${signalId}:${bucketName}`;
3751
3752
  const isInitial = !this.getMemoryStorage.has(key);
3752
3753
  const instance = this.getMemoryStorage(signalId, bucketName);
3753
3754
  await instance.waitForInit(isInitial);
3754
- return instance.writeMemoryData(data, memoryId);
3755
+ return instance.writeMemoryData(data, memoryId, when);
3755
3756
  };
3756
3757
  /**
3757
3758
  * Soft-deletes a memory entry for the given context.
@@ -3915,7 +3916,7 @@ class PersistRecentInstance {
3915
3916
  * @param signalRow - Recent signal data to persist
3916
3917
  * @returns Promise that resolves when write is complete
3917
3918
  */
3918
- async writeRecentData(signalRow) {
3919
+ async writeRecentData(signalRow, _when) {
3919
3920
  await this._storage.writeValue(this.symbol, signalRow);
3920
3921
  }
3921
3922
  }
@@ -3943,7 +3944,7 @@ class PersistRecentDummyInstance {
3943
3944
  * No-op write (discards recent signal).
3944
3945
  * @returns Promise that resolves immediately
3945
3946
  */
3946
- async writeRecentData(_signalRow) { }
3947
+ async writeRecentData(_signalRow, _when) { }
3947
3948
  }
3948
3949
  /**
3949
3950
  * Utility class for managing recent signal persistence.
@@ -3990,21 +3991,22 @@ class PersistRecentUtils {
3990
3991
  * Writes the latest recent signal for the given context.
3991
3992
  * Lazily initializes the instance on first access.
3992
3993
  *
3993
- * @param signalRow - Recent signal data to persist
3994
+ * @param signalRow - Recent signal data to persist (already carries `signalRow.timestamp`)
3994
3995
  * @param symbol - Trading pair symbol
3995
3996
  * @param strategyName - Strategy identifier
3996
3997
  * @param exchangeName - Exchange identifier
3997
3998
  * @param frameName - Frame identifier (may be empty)
3998
3999
  * @param backtest - True for backtest mode, false for live mode
4000
+ * @param when - Logical timestamp this signal belongs to (duplicates `signalRow.timestamp` for API consistency)
3999
4001
  * @returns Promise that resolves when write is complete
4000
4002
  */
4001
- this.writeRecentData = async (signalRow, symbol, strategyName, exchangeName, frameName, backtest) => {
4003
+ this.writeRecentData = async (signalRow, symbol, strategyName, exchangeName, frameName, backtest, when) => {
4002
4004
  LOGGER_SERVICE$7.info(PERSIST_RECENT_UTILS_METHOD_NAME_WRITE_DATA);
4003
4005
  const key = this.createKey(symbol, strategyName, exchangeName, frameName, backtest);
4004
4006
  const isInitial = !this.getStorage.has(key);
4005
4007
  const instance = this.getStorage(symbol, strategyName, exchangeName, frameName, backtest);
4006
4008
  await instance.waitForInit(isInitial);
4007
- return instance.writeRecentData(signalRow);
4009
+ return instance.writeRecentData(signalRow, when);
4008
4010
  };
4009
4011
  }
4010
4012
  /**
@@ -4118,7 +4120,7 @@ class PersistStateInstance {
4118
4120
  * @param data - State data to persist
4119
4121
  * @returns Promise that resolves when write is complete
4120
4122
  */
4121
- async writeStateData(data) {
4123
+ async writeStateData(data, _when) {
4122
4124
  await this._storage.writeValue(this.bucketName, data);
4123
4125
  }
4124
4126
  /**
@@ -4151,7 +4153,7 @@ class PersistStateDummyInstance {
4151
4153
  * No-op write (discards state).
4152
4154
  * @returns Promise that resolves immediately
4153
4155
  */
4154
- async writeStateData(_data) { }
4156
+ async writeStateData(_data, _when) { }
4155
4157
  /**
4156
4158
  * No-op dispose.
4157
4159
  */
@@ -4216,18 +4218,19 @@ class PersistStateUtils {
4216
4218
  * Writes state for the given context.
4217
4219
  * Lazily initializes the instance on first access.
4218
4220
  *
4219
- * @param data - State data to persist
4221
+ * @param data - State data to persist (already carries `data.when`)
4220
4222
  * @param signalId - Signal identifier
4221
4223
  * @param bucketName - Bucket name
4224
+ * @param when - Logical timestamp this value belongs to (duplicates `data.when` for API consistency)
4222
4225
  * @returns Promise that resolves when write is complete
4223
4226
  */
4224
- this.writeStateData = async (data, signalId, bucketName) => {
4227
+ this.writeStateData = async (data, signalId, bucketName, when) => {
4225
4228
  LOGGER_SERVICE$7.info(PERSIST_STATE_UTILS_METHOD_NAME_WRITE_DATA, { signalId, bucketName });
4226
4229
  const key = `${signalId}:${bucketName}`;
4227
4230
  const isInitial = !this.getStateStorage.has(key);
4228
4231
  const instance = this.getStateStorage(signalId, bucketName);
4229
4232
  await instance.waitForInit(isInitial);
4230
- return instance.writeStateData(data);
4233
+ return instance.writeStateData(data, when);
4231
4234
  };
4232
4235
  /**
4233
4236
  * Switches to PersistStateDummyInstance (all operations are no-ops).
@@ -4337,7 +4340,7 @@ class PersistSessionInstance {
4337
4340
  * @param data - Session data to persist
4338
4341
  * @returns Promise that resolves when write is complete
4339
4342
  */
4340
- async writeSessionData(data) {
4343
+ async writeSessionData(data, _when) {
4341
4344
  await this._storage.writeValue(this.frameName, data);
4342
4345
  }
4343
4346
  /**
@@ -4370,7 +4373,7 @@ class PersistSessionDummyInstance {
4370
4373
  * No-op write (discards session data).
4371
4374
  * @returns Promise that resolves immediately
4372
4375
  */
4373
- async writeSessionData(_data) { }
4376
+ async writeSessionData(_data, _when) { }
4374
4377
  /**
4375
4378
  * No-op dispose.
4376
4379
  */
@@ -4438,19 +4441,20 @@ class PersistSessionUtils {
4438
4441
  * Writes session data for the given context.
4439
4442
  * Lazily initializes the instance on first access.
4440
4443
  *
4441
- * @param data - Session data to persist
4444
+ * @param data - Session data to persist (already carries `data.when`)
4442
4445
  * @param strategyName - Strategy identifier
4443
4446
  * @param exchangeName - Exchange identifier
4444
4447
  * @param frameName - Frame identifier
4448
+ * @param when - Logical timestamp this value belongs to (duplicates `data.when` for API consistency)
4445
4449
  * @returns Promise that resolves when write is complete
4446
4450
  */
4447
- this.writeSessionData = async (data, strategyName, exchangeName, frameName) => {
4451
+ this.writeSessionData = async (data, strategyName, exchangeName, frameName, when) => {
4448
4452
  LOGGER_SERVICE$7.info(PERSIST_SESSION_UTILS_METHOD_NAME_WRITE_DATA, { strategyName, exchangeName, frameName });
4449
4453
  const key = `${strategyName}:${exchangeName}:${frameName}`;
4450
4454
  const isInitial = !this.getSessionStorage.has(key);
4451
4455
  const instance = this.getSessionStorage(strategyName, exchangeName, frameName);
4452
4456
  await instance.waitForInit(isInitial);
4453
- return instance.writeSessionData(data);
4457
+ return instance.writeSessionData(data, when);
4454
4458
  };
4455
4459
  /**
4456
4460
  * Switches to PersistSessionDummyInstance (all operations are no-ops).
@@ -48520,7 +48524,7 @@ class RecentPersistBacktestUtils {
48520
48524
  backtest.loggerService.info(RECENT_PERSIST_BACKTEST_METHOD_NAME_HANDLE_ACTIVE_PING, {
48521
48525
  signalId: event.data.id,
48522
48526
  });
48523
- await PersistRecentAdapter.writeRecentData(event.data, event.symbol, event.strategyName, event.exchangeName, event.data.frameName, event.backtest);
48527
+ await PersistRecentAdapter.writeRecentData(event.data, event.symbol, event.strategyName, event.exchangeName, event.data.frameName, event.backtest, new Date(event.data.timestamp));
48524
48528
  };
48525
48529
  /**
48526
48530
  * Retrieves the latest persisted signal for the given context.
@@ -48657,7 +48661,7 @@ class RecentPersistLiveUtils {
48657
48661
  backtest.loggerService.info(RECENT_PERSIST_LIVE_METHOD_NAME_HANDLE_ACTIVE_PING, {
48658
48662
  signalId: event.data.id,
48659
48663
  });
48660
- await PersistRecentAdapter.writeRecentData(event.data, event.symbol, event.strategyName, event.exchangeName, event.data.frameName, event.backtest);
48664
+ await PersistRecentAdapter.writeRecentData(event.data, event.symbol, event.strategyName, event.exchangeName, event.data.frameName, event.backtest, new Date(event.data.timestamp));
48661
48665
  };
48662
48666
  /**
48663
48667
  * Retrieves the latest persisted signal for the given context.
@@ -49312,7 +49316,7 @@ class StatePersistInstance {
49312
49316
  }
49313
49317
  this._when = when.getTime();
49314
49318
  const id = CREATE_KEY_FN$6(this.signalId, this.bucketName);
49315
- await PersistStateAdapter.writeStateData({ id, data: this._value, when: this._when }, this.signalId, this.bucketName);
49319
+ await PersistStateAdapter.writeStateData({ id, data: this._value, when: this._when }, this.signalId, this.bucketName, when);
49316
49320
  return this._value;
49317
49321
  });
49318
49322
  }
@@ -50121,7 +50125,7 @@ class SessionPersistInstance {
50121
50125
  this._data = value;
50122
50126
  this._when = when.getTime();
50123
50127
  const id = CREATE_KEY_FN$5(this.symbol, this.strategyName, this.exchangeName, this.frameName, this.backtest);
50124
- await PersistSessionAdapter.writeSessionData({ id, data: value, when: this._when }, this.strategyName, this.exchangeName, this.frameName);
50128
+ await PersistSessionAdapter.writeSessionData({ id, data: value, when: this._when }, this.strategyName, this.exchangeName, this.frameName, when);
50125
50129
  };
50126
50130
  }
50127
50131
  /** Releases resources held by this instance. */
@@ -50905,7 +50909,7 @@ class MemoryPersistInstance {
50905
50909
  });
50906
50910
  const priority = Date.now();
50907
50911
  const whenMs = when.getTime();
50908
- await PersistMemoryAdapter.writeMemoryData({ data: value, priority, removed: false, index, when: whenMs }, this.signalId, this.bucketName, memoryId);
50912
+ await PersistMemoryAdapter.writeMemoryData({ data: value, priority, removed: false, index, when: whenMs }, this.signalId, this.bucketName, memoryId, when);
50909
50913
  this._index.upsert({
50910
50914
  id: memoryId,
50911
50915
  content: value,
package/build/index.mjs CHANGED
@@ -3561,7 +3561,7 @@ class PersistMemoryInstance {
3561
3561
  * @param memoryId - Memory entry identifier
3562
3562
  * @returns Promise that resolves when write is complete
3563
3563
  */
3564
- async writeMemoryData(data, memoryId) {
3564
+ async writeMemoryData(data, memoryId, _when) {
3565
3565
  await this._storage.writeValue(memoryId, data);
3566
3566
  }
3567
3567
  /**
@@ -3626,7 +3626,7 @@ class PersistMemoryDummyInstance {
3626
3626
  * No-op write (discards entry).
3627
3627
  * @returns Promise that resolves immediately
3628
3628
  */
3629
- async writeMemoryData(_data, _memoryId) { }
3629
+ async writeMemoryData(_data, _memoryId, _when) { }
3630
3630
  /**
3631
3631
  * No-op remove.
3632
3632
  * @returns Promise that resolves immediately
@@ -3719,19 +3719,20 @@ class PersistMemoryUtils {
3719
3719
  * Writes a memory entry for the given context.
3720
3720
  * Lazily initializes the instance on first access.
3721
3721
  *
3722
- * @param data - Entry data to persist
3722
+ * @param data - Entry data to persist (already carries `data.when`)
3723
3723
  * @param signalId - Signal identifier
3724
3724
  * @param bucketName - Bucket name
3725
3725
  * @param memoryId - Memory entry identifier
3726
+ * @param when - Logical timestamp this entry belongs to (duplicates `data.when` for API consistency)
3726
3727
  * @returns Promise that resolves when write is complete
3727
3728
  */
3728
- this.writeMemoryData = async (data, signalId, bucketName, memoryId) => {
3729
+ this.writeMemoryData = async (data, signalId, bucketName, memoryId, when) => {
3729
3730
  LOGGER_SERVICE$7.info(PERSIST_MEMORY_UTILS_METHOD_NAME_WRITE_DATA, { signalId, bucketName, memoryId });
3730
3731
  const key = `${signalId}:${bucketName}`;
3731
3732
  const isInitial = !this.getMemoryStorage.has(key);
3732
3733
  const instance = this.getMemoryStorage(signalId, bucketName);
3733
3734
  await instance.waitForInit(isInitial);
3734
- return instance.writeMemoryData(data, memoryId);
3735
+ return instance.writeMemoryData(data, memoryId, when);
3735
3736
  };
3736
3737
  /**
3737
3738
  * Soft-deletes a memory entry for the given context.
@@ -3895,7 +3896,7 @@ class PersistRecentInstance {
3895
3896
  * @param signalRow - Recent signal data to persist
3896
3897
  * @returns Promise that resolves when write is complete
3897
3898
  */
3898
- async writeRecentData(signalRow) {
3899
+ async writeRecentData(signalRow, _when) {
3899
3900
  await this._storage.writeValue(this.symbol, signalRow);
3900
3901
  }
3901
3902
  }
@@ -3923,7 +3924,7 @@ class PersistRecentDummyInstance {
3923
3924
  * No-op write (discards recent signal).
3924
3925
  * @returns Promise that resolves immediately
3925
3926
  */
3926
- async writeRecentData(_signalRow) { }
3927
+ async writeRecentData(_signalRow, _when) { }
3927
3928
  }
3928
3929
  /**
3929
3930
  * Utility class for managing recent signal persistence.
@@ -3970,21 +3971,22 @@ class PersistRecentUtils {
3970
3971
  * Writes the latest recent signal for the given context.
3971
3972
  * Lazily initializes the instance on first access.
3972
3973
  *
3973
- * @param signalRow - Recent signal data to persist
3974
+ * @param signalRow - Recent signal data to persist (already carries `signalRow.timestamp`)
3974
3975
  * @param symbol - Trading pair symbol
3975
3976
  * @param strategyName - Strategy identifier
3976
3977
  * @param exchangeName - Exchange identifier
3977
3978
  * @param frameName - Frame identifier (may be empty)
3978
3979
  * @param backtest - True for backtest mode, false for live mode
3980
+ * @param when - Logical timestamp this signal belongs to (duplicates `signalRow.timestamp` for API consistency)
3979
3981
  * @returns Promise that resolves when write is complete
3980
3982
  */
3981
- this.writeRecentData = async (signalRow, symbol, strategyName, exchangeName, frameName, backtest) => {
3983
+ this.writeRecentData = async (signalRow, symbol, strategyName, exchangeName, frameName, backtest, when) => {
3982
3984
  LOGGER_SERVICE$7.info(PERSIST_RECENT_UTILS_METHOD_NAME_WRITE_DATA);
3983
3985
  const key = this.createKey(symbol, strategyName, exchangeName, frameName, backtest);
3984
3986
  const isInitial = !this.getStorage.has(key);
3985
3987
  const instance = this.getStorage(symbol, strategyName, exchangeName, frameName, backtest);
3986
3988
  await instance.waitForInit(isInitial);
3987
- return instance.writeRecentData(signalRow);
3989
+ return instance.writeRecentData(signalRow, when);
3988
3990
  };
3989
3991
  }
3990
3992
  /**
@@ -4098,7 +4100,7 @@ class PersistStateInstance {
4098
4100
  * @param data - State data to persist
4099
4101
  * @returns Promise that resolves when write is complete
4100
4102
  */
4101
- async writeStateData(data) {
4103
+ async writeStateData(data, _when) {
4102
4104
  await this._storage.writeValue(this.bucketName, data);
4103
4105
  }
4104
4106
  /**
@@ -4131,7 +4133,7 @@ class PersistStateDummyInstance {
4131
4133
  * No-op write (discards state).
4132
4134
  * @returns Promise that resolves immediately
4133
4135
  */
4134
- async writeStateData(_data) { }
4136
+ async writeStateData(_data, _when) { }
4135
4137
  /**
4136
4138
  * No-op dispose.
4137
4139
  */
@@ -4196,18 +4198,19 @@ class PersistStateUtils {
4196
4198
  * Writes state for the given context.
4197
4199
  * Lazily initializes the instance on first access.
4198
4200
  *
4199
- * @param data - State data to persist
4201
+ * @param data - State data to persist (already carries `data.when`)
4200
4202
  * @param signalId - Signal identifier
4201
4203
  * @param bucketName - Bucket name
4204
+ * @param when - Logical timestamp this value belongs to (duplicates `data.when` for API consistency)
4202
4205
  * @returns Promise that resolves when write is complete
4203
4206
  */
4204
- this.writeStateData = async (data, signalId, bucketName) => {
4207
+ this.writeStateData = async (data, signalId, bucketName, when) => {
4205
4208
  LOGGER_SERVICE$7.info(PERSIST_STATE_UTILS_METHOD_NAME_WRITE_DATA, { signalId, bucketName });
4206
4209
  const key = `${signalId}:${bucketName}`;
4207
4210
  const isInitial = !this.getStateStorage.has(key);
4208
4211
  const instance = this.getStateStorage(signalId, bucketName);
4209
4212
  await instance.waitForInit(isInitial);
4210
- return instance.writeStateData(data);
4213
+ return instance.writeStateData(data, when);
4211
4214
  };
4212
4215
  /**
4213
4216
  * Switches to PersistStateDummyInstance (all operations are no-ops).
@@ -4317,7 +4320,7 @@ class PersistSessionInstance {
4317
4320
  * @param data - Session data to persist
4318
4321
  * @returns Promise that resolves when write is complete
4319
4322
  */
4320
- async writeSessionData(data) {
4323
+ async writeSessionData(data, _when) {
4321
4324
  await this._storage.writeValue(this.frameName, data);
4322
4325
  }
4323
4326
  /**
@@ -4350,7 +4353,7 @@ class PersistSessionDummyInstance {
4350
4353
  * No-op write (discards session data).
4351
4354
  * @returns Promise that resolves immediately
4352
4355
  */
4353
- async writeSessionData(_data) { }
4356
+ async writeSessionData(_data, _when) { }
4354
4357
  /**
4355
4358
  * No-op dispose.
4356
4359
  */
@@ -4418,19 +4421,20 @@ class PersistSessionUtils {
4418
4421
  * Writes session data for the given context.
4419
4422
  * Lazily initializes the instance on first access.
4420
4423
  *
4421
- * @param data - Session data to persist
4424
+ * @param data - Session data to persist (already carries `data.when`)
4422
4425
  * @param strategyName - Strategy identifier
4423
4426
  * @param exchangeName - Exchange identifier
4424
4427
  * @param frameName - Frame identifier
4428
+ * @param when - Logical timestamp this value belongs to (duplicates `data.when` for API consistency)
4425
4429
  * @returns Promise that resolves when write is complete
4426
4430
  */
4427
- this.writeSessionData = async (data, strategyName, exchangeName, frameName) => {
4431
+ this.writeSessionData = async (data, strategyName, exchangeName, frameName, when) => {
4428
4432
  LOGGER_SERVICE$7.info(PERSIST_SESSION_UTILS_METHOD_NAME_WRITE_DATA, { strategyName, exchangeName, frameName });
4429
4433
  const key = `${strategyName}:${exchangeName}:${frameName}`;
4430
4434
  const isInitial = !this.getSessionStorage.has(key);
4431
4435
  const instance = this.getSessionStorage(strategyName, exchangeName, frameName);
4432
4436
  await instance.waitForInit(isInitial);
4433
- return instance.writeSessionData(data);
4437
+ return instance.writeSessionData(data, when);
4434
4438
  };
4435
4439
  /**
4436
4440
  * Switches to PersistSessionDummyInstance (all operations are no-ops).
@@ -48500,7 +48504,7 @@ class RecentPersistBacktestUtils {
48500
48504
  backtest.loggerService.info(RECENT_PERSIST_BACKTEST_METHOD_NAME_HANDLE_ACTIVE_PING, {
48501
48505
  signalId: event.data.id,
48502
48506
  });
48503
- await PersistRecentAdapter.writeRecentData(event.data, event.symbol, event.strategyName, event.exchangeName, event.data.frameName, event.backtest);
48507
+ await PersistRecentAdapter.writeRecentData(event.data, event.symbol, event.strategyName, event.exchangeName, event.data.frameName, event.backtest, new Date(event.data.timestamp));
48504
48508
  };
48505
48509
  /**
48506
48510
  * Retrieves the latest persisted signal for the given context.
@@ -48637,7 +48641,7 @@ class RecentPersistLiveUtils {
48637
48641
  backtest.loggerService.info(RECENT_PERSIST_LIVE_METHOD_NAME_HANDLE_ACTIVE_PING, {
48638
48642
  signalId: event.data.id,
48639
48643
  });
48640
- await PersistRecentAdapter.writeRecentData(event.data, event.symbol, event.strategyName, event.exchangeName, event.data.frameName, event.backtest);
48644
+ await PersistRecentAdapter.writeRecentData(event.data, event.symbol, event.strategyName, event.exchangeName, event.data.frameName, event.backtest, new Date(event.data.timestamp));
48641
48645
  };
48642
48646
  /**
48643
48647
  * Retrieves the latest persisted signal for the given context.
@@ -49292,7 +49296,7 @@ class StatePersistInstance {
49292
49296
  }
49293
49297
  this._when = when.getTime();
49294
49298
  const id = CREATE_KEY_FN$6(this.signalId, this.bucketName);
49295
- await PersistStateAdapter.writeStateData({ id, data: this._value, when: this._when }, this.signalId, this.bucketName);
49299
+ await PersistStateAdapter.writeStateData({ id, data: this._value, when: this._when }, this.signalId, this.bucketName, when);
49296
49300
  return this._value;
49297
49301
  });
49298
49302
  }
@@ -50101,7 +50105,7 @@ class SessionPersistInstance {
50101
50105
  this._data = value;
50102
50106
  this._when = when.getTime();
50103
50107
  const id = CREATE_KEY_FN$5(this.symbol, this.strategyName, this.exchangeName, this.frameName, this.backtest);
50104
- await PersistSessionAdapter.writeSessionData({ id, data: value, when: this._when }, this.strategyName, this.exchangeName, this.frameName);
50108
+ await PersistSessionAdapter.writeSessionData({ id, data: value, when: this._when }, this.strategyName, this.exchangeName, this.frameName, when);
50105
50109
  };
50106
50110
  }
50107
50111
  /** Releases resources held by this instance. */
@@ -50885,7 +50889,7 @@ class MemoryPersistInstance {
50885
50889
  });
50886
50890
  const priority = Date.now();
50887
50891
  const whenMs = when.getTime();
50888
- await PersistMemoryAdapter.writeMemoryData({ data: value, priority, removed: false, index, when: whenMs }, this.signalId, this.bucketName, memoryId);
50892
+ await PersistMemoryAdapter.writeMemoryData({ data: value, priority, removed: false, index, when: whenMs }, this.signalId, this.bucketName, memoryId, when);
50889
50893
  this._index.upsert({
50890
50894
  id: memoryId,
50891
50895
  content: value,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backtest-kit",
3
- "version": "9.0.1",
3
+ "version": "9.0.2",
4
4
  "description": "A TypeScript library for trading system backtest",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
package/types.d.ts CHANGED
@@ -14964,11 +14964,12 @@ interface IPersistMemoryInstance {
14964
14964
  /**
14965
14965
  * Write a memory entry.
14966
14966
  *
14967
- * @param data - Entry data to persist
14967
+ * @param data - Entry data to persist (already carries `data.when`)
14968
14968
  * @param memoryId - Memory entry identifier
14969
+ * @param when - Logical timestamp this entry belongs to (duplicates `data.when` for API consistency)
14969
14970
  * @returns Promise that resolves when write is complete
14970
14971
  */
14971
- writeMemoryData(data: MemoryData, memoryId: string): Promise<void>;
14972
+ writeMemoryData(data: MemoryData, memoryId: string, when: Date): Promise<void>;
14972
14973
  /**
14973
14974
  * Soft-delete a memory entry. File stays on disk; subsequent reads return null.
14974
14975
  *
@@ -15049,7 +15050,7 @@ declare class PersistMemoryInstance implements IPersistMemoryInstance {
15049
15050
  * @param memoryId - Memory entry identifier
15050
15051
  * @returns Promise that resolves when write is complete
15051
15052
  */
15052
- writeMemoryData(data: MemoryData, memoryId: string): Promise<void>;
15053
+ writeMemoryData(data: MemoryData, memoryId: string, _when: Date): Promise<void>;
15053
15054
  /**
15054
15055
  * Soft-deletes a memory entry by writing `removed: true` flag.
15055
15056
  *
@@ -15142,13 +15143,14 @@ declare class PersistMemoryUtils {
15142
15143
  * Writes a memory entry for the given context.
15143
15144
  * Lazily initializes the instance on first access.
15144
15145
  *
15145
- * @param data - Entry data to persist
15146
+ * @param data - Entry data to persist (already carries `data.when`)
15146
15147
  * @param signalId - Signal identifier
15147
15148
  * @param bucketName - Bucket name
15148
15149
  * @param memoryId - Memory entry identifier
15150
+ * @param when - Logical timestamp this entry belongs to (duplicates `data.when` for API consistency)
15149
15151
  * @returns Promise that resolves when write is complete
15150
15152
  */
15151
- writeMemoryData: (data: MemoryData, signalId: string, bucketName: string, memoryId: string) => Promise<void>;
15153
+ writeMemoryData: (data: MemoryData, signalId: string, bucketName: string, memoryId: string, when: Date) => Promise<void>;
15152
15154
  /**
15153
15155
  * Soft-deletes a memory entry for the given context.
15154
15156
  * Lazily initializes the instance on first access.
@@ -15241,10 +15243,11 @@ interface IPersistRecentInstance {
15241
15243
  /**
15242
15244
  * Write the latest recent signal for this context.
15243
15245
  *
15244
- * @param signalRow - Recent signal data to persist
15246
+ * @param signalRow - Recent signal data to persist (already carries `signalRow.timestamp`)
15247
+ * @param when - Logical timestamp this signal belongs to (duplicates `signalRow.timestamp` for API consistency)
15245
15248
  * @returns Promise that resolves when write is complete
15246
15249
  */
15247
- writeRecentData(signalRow: IPublicSignalRow): Promise<void>;
15250
+ writeRecentData(signalRow: IPublicSignalRow, when: Date): Promise<void>;
15248
15251
  }
15249
15252
  /**
15250
15253
  * Default file-based implementation of IPersistRecentInstance.
@@ -15299,7 +15302,7 @@ declare class PersistRecentInstance implements IPersistRecentInstance {
15299
15302
  * @param signalRow - Recent signal data to persist
15300
15303
  * @returns Promise that resolves when write is complete
15301
15304
  */
15302
- writeRecentData(signalRow: IPublicSignalRow): Promise<void>;
15305
+ writeRecentData(signalRow: IPublicSignalRow, _when: Date): Promise<void>;
15303
15306
  }
15304
15307
  /**
15305
15308
  * Constructor type for IPersistRecentInstance.
@@ -15362,15 +15365,16 @@ declare class PersistRecentUtils {
15362
15365
  * Writes the latest recent signal for the given context.
15363
15366
  * Lazily initializes the instance on first access.
15364
15367
  *
15365
- * @param signalRow - Recent signal data to persist
15368
+ * @param signalRow - Recent signal data to persist (already carries `signalRow.timestamp`)
15366
15369
  * @param symbol - Trading pair symbol
15367
15370
  * @param strategyName - Strategy identifier
15368
15371
  * @param exchangeName - Exchange identifier
15369
15372
  * @param frameName - Frame identifier (may be empty)
15370
15373
  * @param backtest - True for backtest mode, false for live mode
15374
+ * @param when - Logical timestamp this signal belongs to (duplicates `signalRow.timestamp` for API consistency)
15371
15375
  * @returns Promise that resolves when write is complete
15372
15376
  */
15373
- writeRecentData: (signalRow: IPublicSignalRow, symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<void>;
15377
+ writeRecentData: (signalRow: IPublicSignalRow, symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, when: Date) => Promise<void>;
15374
15378
  /**
15375
15379
  * Clears the memoized instance cache.
15376
15380
  * Call when process.cwd() changes between strategy iterations.
@@ -15424,10 +15428,11 @@ interface IPersistStateInstance {
15424
15428
  /**
15425
15429
  * Write state for this context.
15426
15430
  *
15427
- * @param data - State data to persist
15431
+ * @param data - State data to persist (already carries `data.when`)
15432
+ * @param when - Logical timestamp this value belongs to (duplicates `data.when` for API consistency)
15428
15433
  * @returns Promise that resolves when write is complete
15429
15434
  */
15430
- writeStateData(data: StateData): Promise<void>;
15435
+ writeStateData(data: StateData, when: Date): Promise<void>;
15431
15436
  /**
15432
15437
  * Release any resources held by this instance.
15433
15438
  * Default implementations may treat this as a no-op.
@@ -15481,7 +15486,7 @@ declare class PersistStateInstance implements IPersistStateInstance {
15481
15486
  * @param data - State data to persist
15482
15487
  * @returns Promise that resolves when write is complete
15483
15488
  */
15484
- writeStateData(data: StateData): Promise<void>;
15489
+ writeStateData(data: StateData, _when: Date): Promise<void>;
15485
15490
  /**
15486
15491
  * No-op for the default file-based implementation.
15487
15492
  * Resource cleanup (memo cache invalidation) is handled by PersistStateUtils.dispose().
@@ -15545,12 +15550,13 @@ declare class PersistStateUtils {
15545
15550
  * Writes state for the given context.
15546
15551
  * Lazily initializes the instance on first access.
15547
15552
  *
15548
- * @param data - State data to persist
15553
+ * @param data - State data to persist (already carries `data.when`)
15549
15554
  * @param signalId - Signal identifier
15550
15555
  * @param bucketName - Bucket name
15556
+ * @param when - Logical timestamp this value belongs to (duplicates `data.when` for API consistency)
15551
15557
  * @returns Promise that resolves when write is complete
15552
15558
  */
15553
- writeStateData: (data: StateData, signalId: string, bucketName: string) => Promise<void>;
15559
+ writeStateData: (data: StateData, signalId: string, bucketName: string, when: Date) => Promise<void>;
15554
15560
  /**
15555
15561
  * Switches to PersistStateDummyInstance (all operations are no-ops).
15556
15562
  */
@@ -15612,10 +15618,11 @@ interface IPersistSessionInstance {
15612
15618
  /**
15613
15619
  * Write session data for this context.
15614
15620
  *
15615
- * @param data - Session data to persist
15621
+ * @param data - Session data to persist (already carries `data.when`)
15622
+ * @param when - Logical timestamp this value belongs to (duplicates `data.when` for API consistency)
15616
15623
  * @returns Promise that resolves when write is complete
15617
15624
  */
15618
- writeSessionData(data: SessionData): Promise<void>;
15625
+ writeSessionData(data: SessionData, when: Date): Promise<void>;
15619
15626
  /**
15620
15627
  * Release any resources held by this instance.
15621
15628
  * Default implementations may treat this as a no-op.
@@ -15671,7 +15678,7 @@ declare class PersistSessionInstance implements IPersistSessionInstance {
15671
15678
  * @param data - Session data to persist
15672
15679
  * @returns Promise that resolves when write is complete
15673
15680
  */
15674
- writeSessionData(data: SessionData): Promise<void>;
15681
+ writeSessionData(data: SessionData, _when: Date): Promise<void>;
15675
15682
  /**
15676
15683
  * No-op for the default file-based implementation.
15677
15684
  * Resource cleanup (memo cache invalidation) is handled by PersistSessionUtils.dispose().
@@ -15738,13 +15745,14 @@ declare class PersistSessionUtils {
15738
15745
  * Writes session data for the given context.
15739
15746
  * Lazily initializes the instance on first access.
15740
15747
  *
15741
- * @param data - Session data to persist
15748
+ * @param data - Session data to persist (already carries `data.when`)
15742
15749
  * @param strategyName - Strategy identifier
15743
15750
  * @param exchangeName - Exchange identifier
15744
15751
  * @param frameName - Frame identifier
15752
+ * @param when - Logical timestamp this value belongs to (duplicates `data.when` for API consistency)
15745
15753
  * @returns Promise that resolves when write is complete
15746
15754
  */
15747
- writeSessionData: (data: SessionData, strategyName: string, exchangeName: string, frameName: string) => Promise<void>;
15755
+ writeSessionData: (data: SessionData, strategyName: string, exchangeName: string, frameName: string, when: Date) => Promise<void>;
15748
15756
  /**
15749
15757
  * Switches to PersistSessionDummyInstance (all operations are no-ops).
15750
15758
  */