backtest-kit 2.0.6 → 2.0.7

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
@@ -753,7 +753,7 @@ class ClientExchange {
753
753
  limit,
754
754
  });
755
755
  const step = INTERVAL_MINUTES$4[interval];
756
- const adjust = step * limit - step;
756
+ const adjust = step * limit;
757
757
  if (!adjust) {
758
758
  throw new Error(`ClientExchange unknown time adjust for interval=${interval}`);
759
759
  }
@@ -780,7 +780,8 @@ class ClientExchange {
780
780
  // Filter candles to strictly match the requested range
781
781
  const whenTimestamp = this.params.execution.context.when.getTime();
782
782
  const sinceTimestamp = since.getTime();
783
- const filteredData = allData.filter((candle) => candle.timestamp >= sinceTimestamp && candle.timestamp <= whenTimestamp);
783
+ const stepMs = step * 60 * 1000;
784
+ const filteredData = allData.filter((candle) => candle.timestamp >= sinceTimestamp && candle.timestamp < whenTimestamp + stepMs);
784
785
  // Apply distinct by timestamp to remove duplicates
785
786
  const uniqueData = Array.from(new Map(filteredData.map((candle) => [candle.timestamp, candle])).values());
786
787
  if (filteredData.length !== uniqueData.length) {
@@ -842,14 +843,18 @@ class ClientExchange {
842
843
  }
843
844
  // Filter candles to strictly match the requested range
844
845
  const sinceTimestamp = since.getTime();
845
- const filteredData = allData.filter((candle) => candle.timestamp >= sinceTimestamp && candle.timestamp <= endTime);
846
+ const filteredData = allData.filter((candle) => candle.timestamp >= sinceTimestamp && candle.timestamp < endTime);
846
847
  // Apply distinct by timestamp to remove duplicates
847
848
  const uniqueData = Array.from(new Map(filteredData.map((candle) => [candle.timestamp, candle])).values());
848
849
  if (filteredData.length !== uniqueData.length) {
849
- this.params.logger.warn(`ClientExchange getNextCandles: Removed ${filteredData.length - uniqueData.length} duplicate candles by timestamp`);
850
+ const msg = `ClientExchange getNextCandles: Removed ${filteredData.length - uniqueData.length} duplicate candles by timestamp`;
851
+ this.params.logger.warn(msg);
852
+ console.warn(msg);
850
853
  }
851
854
  if (uniqueData.length < limit) {
852
- this.params.logger.warn(`ClientExchange getNextCandles: Expected ${limit} candles, got ${uniqueData.length}`);
855
+ const msg = `ClientExchange getNextCandles: Expected ${limit} candles, got ${uniqueData.length}`;
856
+ this.params.logger.warn(msg);
857
+ console.warn(msg);
853
858
  }
854
859
  await CALL_CANDLE_DATA_CALLBACKS_FN(this, symbol, interval, since, limit, uniqueData);
855
860
  return uniqueData;
@@ -10521,7 +10526,7 @@ class BacktestLogicPrivateService {
10521
10526
  // Запрашиваем minuteEstimatedTime + буфер свечей одним запросом
10522
10527
  const bufferMinutes = GLOBAL_CONFIG.CC_AVG_PRICE_CANDLES_COUNT - 1;
10523
10528
  const bufferStartTime = new Date(when.getTime() - bufferMinutes * 60 * 1000);
10524
- const totalCandles = signal.minuteEstimatedTime + bufferMinutes;
10529
+ const totalCandles = signal.minuteEstimatedTime + GLOBAL_CONFIG.CC_AVG_PRICE_CANDLES_COUNT;
10525
10530
  let candles;
10526
10531
  try {
10527
10532
  candles = await this.exchangeCoreService.getNextCandles(symbol, "1m", totalCandles, bufferStartTime, true);
@@ -30074,7 +30079,7 @@ class ExchangeInstance {
30074
30079
  });
30075
30080
  const getCandles = this._methods.getCandles;
30076
30081
  const step = INTERVAL_MINUTES$1[interval];
30077
- const adjust = step * limit - step;
30082
+ const adjust = step * limit;
30078
30083
  if (!adjust) {
30079
30084
  throw new Error(`ExchangeInstance unknown time adjust for interval=${interval}`);
30080
30085
  }
@@ -30102,9 +30107,10 @@ class ExchangeInstance {
30102
30107
  allData = await getCandles(symbol, interval, since, limit, isBacktest);
30103
30108
  }
30104
30109
  // Filter candles to strictly match the requested range
30105
- const whenTimestamp = when.getTime();
30106
30110
  const sinceTimestamp = since.getTime();
30107
- const filteredData = allData.filter((candle) => candle.timestamp >= sinceTimestamp && candle.timestamp <= whenTimestamp);
30111
+ const whenTimestamp = when.getTime();
30112
+ const stepMs = step * 60 * 1000;
30113
+ const filteredData = allData.filter((candle) => candle.timestamp >= sinceTimestamp && candle.timestamp < whenTimestamp + stepMs);
30108
30114
  // Apply distinct by timestamp to remove duplicates
30109
30115
  const uniqueData = Array.from(new Map(filteredData.map((candle) => [candle.timestamp, candle])).values());
30110
30116
  if (filteredData.length !== uniqueData.length) {
package/build/index.mjs CHANGED
@@ -733,7 +733,7 @@ class ClientExchange {
733
733
  limit,
734
734
  });
735
735
  const step = INTERVAL_MINUTES$4[interval];
736
- const adjust = step * limit - step;
736
+ const adjust = step * limit;
737
737
  if (!adjust) {
738
738
  throw new Error(`ClientExchange unknown time adjust for interval=${interval}`);
739
739
  }
@@ -760,7 +760,8 @@ class ClientExchange {
760
760
  // Filter candles to strictly match the requested range
761
761
  const whenTimestamp = this.params.execution.context.when.getTime();
762
762
  const sinceTimestamp = since.getTime();
763
- const filteredData = allData.filter((candle) => candle.timestamp >= sinceTimestamp && candle.timestamp <= whenTimestamp);
763
+ const stepMs = step * 60 * 1000;
764
+ const filteredData = allData.filter((candle) => candle.timestamp >= sinceTimestamp && candle.timestamp < whenTimestamp + stepMs);
764
765
  // Apply distinct by timestamp to remove duplicates
765
766
  const uniqueData = Array.from(new Map(filteredData.map((candle) => [candle.timestamp, candle])).values());
766
767
  if (filteredData.length !== uniqueData.length) {
@@ -822,14 +823,18 @@ class ClientExchange {
822
823
  }
823
824
  // Filter candles to strictly match the requested range
824
825
  const sinceTimestamp = since.getTime();
825
- const filteredData = allData.filter((candle) => candle.timestamp >= sinceTimestamp && candle.timestamp <= endTime);
826
+ const filteredData = allData.filter((candle) => candle.timestamp >= sinceTimestamp && candle.timestamp < endTime);
826
827
  // Apply distinct by timestamp to remove duplicates
827
828
  const uniqueData = Array.from(new Map(filteredData.map((candle) => [candle.timestamp, candle])).values());
828
829
  if (filteredData.length !== uniqueData.length) {
829
- this.params.logger.warn(`ClientExchange getNextCandles: Removed ${filteredData.length - uniqueData.length} duplicate candles by timestamp`);
830
+ const msg = `ClientExchange getNextCandles: Removed ${filteredData.length - uniqueData.length} duplicate candles by timestamp`;
831
+ this.params.logger.warn(msg);
832
+ console.warn(msg);
830
833
  }
831
834
  if (uniqueData.length < limit) {
832
- this.params.logger.warn(`ClientExchange getNextCandles: Expected ${limit} candles, got ${uniqueData.length}`);
835
+ const msg = `ClientExchange getNextCandles: Expected ${limit} candles, got ${uniqueData.length}`;
836
+ this.params.logger.warn(msg);
837
+ console.warn(msg);
833
838
  }
834
839
  await CALL_CANDLE_DATA_CALLBACKS_FN(this, symbol, interval, since, limit, uniqueData);
835
840
  return uniqueData;
@@ -10501,7 +10506,7 @@ class BacktestLogicPrivateService {
10501
10506
  // Запрашиваем minuteEstimatedTime + буфер свечей одним запросом
10502
10507
  const bufferMinutes = GLOBAL_CONFIG.CC_AVG_PRICE_CANDLES_COUNT - 1;
10503
10508
  const bufferStartTime = new Date(when.getTime() - bufferMinutes * 60 * 1000);
10504
- const totalCandles = signal.minuteEstimatedTime + bufferMinutes;
10509
+ const totalCandles = signal.minuteEstimatedTime + GLOBAL_CONFIG.CC_AVG_PRICE_CANDLES_COUNT;
10505
10510
  let candles;
10506
10511
  try {
10507
10512
  candles = await this.exchangeCoreService.getNextCandles(symbol, "1m", totalCandles, bufferStartTime, true);
@@ -30054,7 +30059,7 @@ class ExchangeInstance {
30054
30059
  });
30055
30060
  const getCandles = this._methods.getCandles;
30056
30061
  const step = INTERVAL_MINUTES$1[interval];
30057
- const adjust = step * limit - step;
30062
+ const adjust = step * limit;
30058
30063
  if (!adjust) {
30059
30064
  throw new Error(`ExchangeInstance unknown time adjust for interval=${interval}`);
30060
30065
  }
@@ -30082,9 +30087,10 @@ class ExchangeInstance {
30082
30087
  allData = await getCandles(symbol, interval, since, limit, isBacktest);
30083
30088
  }
30084
30089
  // Filter candles to strictly match the requested range
30085
- const whenTimestamp = when.getTime();
30086
30090
  const sinceTimestamp = since.getTime();
30087
- const filteredData = allData.filter((candle) => candle.timestamp >= sinceTimestamp && candle.timestamp <= whenTimestamp);
30091
+ const whenTimestamp = when.getTime();
30092
+ const stepMs = step * 60 * 1000;
30093
+ const filteredData = allData.filter((candle) => candle.timestamp >= sinceTimestamp && candle.timestamp < whenTimestamp + stepMs);
30088
30094
  // Apply distinct by timestamp to remove duplicates
30089
30095
  const uniqueData = Array.from(new Map(filteredData.map((candle) => [candle.timestamp, candle])).values());
30090
30096
  if (filteredData.length !== uniqueData.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backtest-kit",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "A TypeScript library for trading system backtest",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",