backtest-kit 1.5.14 → 1.5.15

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
@@ -590,6 +590,14 @@ class ClientExchange {
590
590
  const vwap = sumPriceVolume / totalVolume;
591
591
  return vwap;
592
592
  }
593
+ /**
594
+ * Formats quantity according to exchange-specific rules for the given symbol.
595
+ * Applies proper decimal precision and rounding based on symbol's lot size filters.
596
+ *
597
+ * @param symbol - Trading pair symbol
598
+ * @param quantity - Raw quantity to format
599
+ * @returns Promise resolving to formatted quantity as string
600
+ */
593
601
  async formatQuantity(symbol, quantity) {
594
602
  this.params.logger.debug("binanceService formatQuantity", {
595
603
  symbol,
@@ -597,6 +605,14 @@ class ClientExchange {
597
605
  });
598
606
  return await this.params.formatQuantity(symbol, quantity);
599
607
  }
608
+ /**
609
+ * Formats price according to exchange-specific rules for the given symbol.
610
+ * Applies proper decimal precision and rounding based on symbol's price filters.
611
+ *
612
+ * @param symbol - Trading pair symbol
613
+ * @param price - Raw price to format
614
+ * @returns Promise resolving to formatted price as string
615
+ */
600
616
  async formatPrice(symbol, price) {
601
617
  this.params.logger.debug("binanceService formatPrice", {
602
618
  symbol,
@@ -6533,14 +6549,11 @@ let ReportStorage$3 = class ReportStorage {
6533
6549
  }
6534
6550
  }
6535
6551
  /**
6536
- * Updates or adds an active event to the storage.
6537
- * Replaces the previous event with the same signalId.
6552
+ * Adds an active event to the storage.
6538
6553
  *
6539
6554
  * @param data - Active tick result
6540
6555
  */
6541
6556
  addActiveEvent(data) {
6542
- // Find existing event with the same signalId
6543
- const existingIndex = this._eventList.findIndex((event) => event.signalId === data.signal.id);
6544
6557
  const newEvent = {
6545
6558
  timestamp: Date.now(),
6546
6559
  action: "active",
@@ -6555,29 +6568,20 @@ let ReportStorage$3 = class ReportStorage {
6555
6568
  percentTp: data.percentTp,
6556
6569
  percentSl: data.percentSl,
6557
6570
  };
6558
- // Replace existing event or add new one
6559
- if (existingIndex !== -1) {
6560
- this._eventList[existingIndex] = newEvent;
6561
- }
6562
- else {
6563
- this._eventList.push(newEvent);
6564
- // Trim queue if exceeded MAX_EVENTS
6565
- if (this._eventList.length > MAX_EVENTS$3) {
6566
- this._eventList.shift();
6567
- }
6571
+ this._eventList.push(newEvent);
6572
+ // Trim queue if exceeded MAX_EVENTS
6573
+ if (this._eventList.length > MAX_EVENTS$3) {
6574
+ this._eventList.shift();
6568
6575
  }
6569
6576
  }
6570
6577
  /**
6571
- * Updates or adds a closed event to the storage.
6572
- * Replaces the previous event with the same signalId.
6578
+ * Adds a closed event to the storage.
6573
6579
  *
6574
6580
  * @param data - Closed tick result
6575
6581
  */
6576
6582
  addClosedEvent(data) {
6577
6583
  const durationMs = data.closeTimestamp - data.signal.pendingAt;
6578
6584
  const durationMin = Math.round(durationMs / 60000);
6579
- // Find existing event with the same signalId
6580
- const existingIndex = this._eventList.findIndex((event) => event.signalId === data.signal.id);
6581
6585
  const newEvent = {
6582
6586
  timestamp: data.closeTimestamp,
6583
6587
  action: "closed",
@@ -6593,16 +6597,10 @@ let ReportStorage$3 = class ReportStorage {
6593
6597
  closeReason: data.closeReason,
6594
6598
  duration: durationMin,
6595
6599
  };
6596
- // Replace existing event or add new one
6597
- if (existingIndex !== -1) {
6598
- this._eventList[existingIndex] = newEvent;
6599
- }
6600
- else {
6601
- this._eventList.push(newEvent);
6602
- // Trim queue if exceeded MAX_EVENTS
6603
- if (this._eventList.length > MAX_EVENTS$3) {
6604
- this._eventList.shift();
6605
- }
6600
+ this._eventList.push(newEvent);
6601
+ // Trim queue if exceeded MAX_EVENTS
6602
+ if (this._eventList.length > MAX_EVENTS$3) {
6603
+ this._eventList.shift();
6606
6604
  }
6607
6605
  }
6608
6606
  /**
@@ -7037,16 +7035,13 @@ let ReportStorage$2 = class ReportStorage {
7037
7035
  }
7038
7036
  }
7039
7037
  /**
7040
- * Updates or adds a cancelled event to the storage.
7041
- * Replaces the previous event with the same signalId.
7038
+ * Adds a cancelled event to the storage.
7042
7039
  *
7043
7040
  * @param data - Cancelled tick result
7044
7041
  */
7045
7042
  addCancelledEvent(data) {
7046
7043
  const durationMs = data.closeTimestamp - data.signal.scheduledAt;
7047
7044
  const durationMin = Math.round(durationMs / 60000);
7048
- // Find existing event with the same signalId
7049
- const existingIndex = this._eventList.findIndex((event) => event.signalId === data.signal.id);
7050
7045
  const newEvent = {
7051
7046
  timestamp: data.closeTimestamp,
7052
7047
  action: "cancelled",
@@ -7061,16 +7056,10 @@ let ReportStorage$2 = class ReportStorage {
7061
7056
  closeTimestamp: data.closeTimestamp,
7062
7057
  duration: durationMin,
7063
7058
  };
7064
- // Replace existing event or add new one
7065
- if (existingIndex !== -1) {
7066
- this._eventList[existingIndex] = newEvent;
7067
- }
7068
- else {
7069
- this._eventList.push(newEvent);
7070
- // Trim queue if exceeded MAX_EVENTS
7071
- if (this._eventList.length > MAX_EVENTS$2) {
7072
- this._eventList.shift();
7073
- }
7059
+ this._eventList.push(newEvent);
7060
+ // Trim queue if exceeded MAX_EVENTS
7061
+ if (this._eventList.length > MAX_EVENTS$2) {
7062
+ this._eventList.shift();
7074
7063
  }
7075
7064
  }
7076
7065
  /**
package/build/index.mjs CHANGED
@@ -588,6 +588,14 @@ class ClientExchange {
588
588
  const vwap = sumPriceVolume / totalVolume;
589
589
  return vwap;
590
590
  }
591
+ /**
592
+ * Formats quantity according to exchange-specific rules for the given symbol.
593
+ * Applies proper decimal precision and rounding based on symbol's lot size filters.
594
+ *
595
+ * @param symbol - Trading pair symbol
596
+ * @param quantity - Raw quantity to format
597
+ * @returns Promise resolving to formatted quantity as string
598
+ */
591
599
  async formatQuantity(symbol, quantity) {
592
600
  this.params.logger.debug("binanceService formatQuantity", {
593
601
  symbol,
@@ -595,6 +603,14 @@ class ClientExchange {
595
603
  });
596
604
  return await this.params.formatQuantity(symbol, quantity);
597
605
  }
606
+ /**
607
+ * Formats price according to exchange-specific rules for the given symbol.
608
+ * Applies proper decimal precision and rounding based on symbol's price filters.
609
+ *
610
+ * @param symbol - Trading pair symbol
611
+ * @param price - Raw price to format
612
+ * @returns Promise resolving to formatted price as string
613
+ */
598
614
  async formatPrice(symbol, price) {
599
615
  this.params.logger.debug("binanceService formatPrice", {
600
616
  symbol,
@@ -6531,14 +6547,11 @@ let ReportStorage$3 = class ReportStorage {
6531
6547
  }
6532
6548
  }
6533
6549
  /**
6534
- * Updates or adds an active event to the storage.
6535
- * Replaces the previous event with the same signalId.
6550
+ * Adds an active event to the storage.
6536
6551
  *
6537
6552
  * @param data - Active tick result
6538
6553
  */
6539
6554
  addActiveEvent(data) {
6540
- // Find existing event with the same signalId
6541
- const existingIndex = this._eventList.findIndex((event) => event.signalId === data.signal.id);
6542
6555
  const newEvent = {
6543
6556
  timestamp: Date.now(),
6544
6557
  action: "active",
@@ -6553,29 +6566,20 @@ let ReportStorage$3 = class ReportStorage {
6553
6566
  percentTp: data.percentTp,
6554
6567
  percentSl: data.percentSl,
6555
6568
  };
6556
- // Replace existing event or add new one
6557
- if (existingIndex !== -1) {
6558
- this._eventList[existingIndex] = newEvent;
6559
- }
6560
- else {
6561
- this._eventList.push(newEvent);
6562
- // Trim queue if exceeded MAX_EVENTS
6563
- if (this._eventList.length > MAX_EVENTS$3) {
6564
- this._eventList.shift();
6565
- }
6569
+ this._eventList.push(newEvent);
6570
+ // Trim queue if exceeded MAX_EVENTS
6571
+ if (this._eventList.length > MAX_EVENTS$3) {
6572
+ this._eventList.shift();
6566
6573
  }
6567
6574
  }
6568
6575
  /**
6569
- * Updates or adds a closed event to the storage.
6570
- * Replaces the previous event with the same signalId.
6576
+ * Adds a closed event to the storage.
6571
6577
  *
6572
6578
  * @param data - Closed tick result
6573
6579
  */
6574
6580
  addClosedEvent(data) {
6575
6581
  const durationMs = data.closeTimestamp - data.signal.pendingAt;
6576
6582
  const durationMin = Math.round(durationMs / 60000);
6577
- // Find existing event with the same signalId
6578
- const existingIndex = this._eventList.findIndex((event) => event.signalId === data.signal.id);
6579
6583
  const newEvent = {
6580
6584
  timestamp: data.closeTimestamp,
6581
6585
  action: "closed",
@@ -6591,16 +6595,10 @@ let ReportStorage$3 = class ReportStorage {
6591
6595
  closeReason: data.closeReason,
6592
6596
  duration: durationMin,
6593
6597
  };
6594
- // Replace existing event or add new one
6595
- if (existingIndex !== -1) {
6596
- this._eventList[existingIndex] = newEvent;
6597
- }
6598
- else {
6599
- this._eventList.push(newEvent);
6600
- // Trim queue if exceeded MAX_EVENTS
6601
- if (this._eventList.length > MAX_EVENTS$3) {
6602
- this._eventList.shift();
6603
- }
6598
+ this._eventList.push(newEvent);
6599
+ // Trim queue if exceeded MAX_EVENTS
6600
+ if (this._eventList.length > MAX_EVENTS$3) {
6601
+ this._eventList.shift();
6604
6602
  }
6605
6603
  }
6606
6604
  /**
@@ -7035,16 +7033,13 @@ let ReportStorage$2 = class ReportStorage {
7035
7033
  }
7036
7034
  }
7037
7035
  /**
7038
- * Updates or adds a cancelled event to the storage.
7039
- * Replaces the previous event with the same signalId.
7036
+ * Adds a cancelled event to the storage.
7040
7037
  *
7041
7038
  * @param data - Cancelled tick result
7042
7039
  */
7043
7040
  addCancelledEvent(data) {
7044
7041
  const durationMs = data.closeTimestamp - data.signal.scheduledAt;
7045
7042
  const durationMin = Math.round(durationMs / 60000);
7046
- // Find existing event with the same signalId
7047
- const existingIndex = this._eventList.findIndex((event) => event.signalId === data.signal.id);
7048
7043
  const newEvent = {
7049
7044
  timestamp: data.closeTimestamp,
7050
7045
  action: "cancelled",
@@ -7059,16 +7054,10 @@ let ReportStorage$2 = class ReportStorage {
7059
7054
  closeTimestamp: data.closeTimestamp,
7060
7055
  duration: durationMin,
7061
7056
  };
7062
- // Replace existing event or add new one
7063
- if (existingIndex !== -1) {
7064
- this._eventList[existingIndex] = newEvent;
7065
- }
7066
- else {
7067
- this._eventList.push(newEvent);
7068
- // Trim queue if exceeded MAX_EVENTS
7069
- if (this._eventList.length > MAX_EVENTS$2) {
7070
- this._eventList.shift();
7071
- }
7057
+ this._eventList.push(newEvent);
7058
+ // Trim queue if exceeded MAX_EVENTS
7059
+ if (this._eventList.length > MAX_EVENTS$2) {
7060
+ this._eventList.shift();
7072
7061
  }
7073
7062
  }
7074
7063
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backtest-kit",
3
- "version": "1.5.14",
3
+ "version": "1.5.15",
4
4
  "description": "A TypeScript library for trading system backtest",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
package/types.d.ts CHANGED
@@ -6708,7 +6708,23 @@ declare class ClientExchange implements IExchange {
6708
6708
  * @throws Error if no candles available
6709
6709
  */
6710
6710
  getAveragePrice(symbol: string): Promise<number>;
6711
+ /**
6712
+ * Formats quantity according to exchange-specific rules for the given symbol.
6713
+ * Applies proper decimal precision and rounding based on symbol's lot size filters.
6714
+ *
6715
+ * @param symbol - Trading pair symbol
6716
+ * @param quantity - Raw quantity to format
6717
+ * @returns Promise resolving to formatted quantity as string
6718
+ */
6711
6719
  formatQuantity(symbol: string, quantity: number): Promise<string>;
6720
+ /**
6721
+ * Formats price according to exchange-specific rules for the given symbol.
6722
+ * Applies proper decimal precision and rounding based on symbol's price filters.
6723
+ *
6724
+ * @param symbol - Trading pair symbol
6725
+ * @param price - Raw price to format
6726
+ * @returns Promise resolving to formatted price as string
6727
+ */
6712
6728
  formatPrice(symbol: string, price: number): Promise<string>;
6713
6729
  }
6714
6730