backtest-kit 2.2.18 → 2.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.mjs CHANGED
@@ -2808,6 +2808,11 @@ const INTERVAL_MINUTES$3 = {
2808
2808
  "30m": 30,
2809
2809
  "1h": 60,
2810
2810
  };
2811
+ /**
2812
+ * Mock value for scheduled signal pendingAt timestamp.
2813
+ * Used to indicate that the actual pendingAt will be set upon activation.
2814
+ */
2815
+ const SCHEDULED_SIGNAL_PENDING_MOCK = 0;
2811
2816
  const TIMEOUT_SYMBOL = Symbol('timeout');
2812
2817
  /**
2813
2818
  * Calls onCommit callback with strategy commit event.
@@ -2850,6 +2855,11 @@ const PROCESS_COMMIT_QUEUE_FN = async (self, timestamp) => {
2850
2855
  {
2851
2856
  self._commitQueue = [];
2852
2857
  }
2858
+ if (!self._pendingSignal) {
2859
+ return;
2860
+ }
2861
+ // Get public signal data for commit events (contains effective and original SL/TP)
2862
+ const publicSignal = TO_PUBLIC_SIGNAL(self._pendingSignal);
2853
2863
  for (const commit of queue) {
2854
2864
  if (commit.action === "partial-profit") {
2855
2865
  await CALL_COMMIT_FN(self, {
@@ -2862,6 +2872,14 @@ const PROCESS_COMMIT_QUEUE_FN = async (self, timestamp) => {
2862
2872
  percentToClose: commit.percentToClose,
2863
2873
  currentPrice: commit.currentPrice,
2864
2874
  timestamp,
2875
+ position: publicSignal.position,
2876
+ priceOpen: publicSignal.priceOpen,
2877
+ priceTakeProfit: publicSignal.priceTakeProfit,
2878
+ priceStopLoss: publicSignal.priceStopLoss,
2879
+ originalPriceTakeProfit: publicSignal.originalPriceTakeProfit,
2880
+ originalPriceStopLoss: publicSignal.originalPriceStopLoss,
2881
+ scheduledAt: publicSignal.scheduledAt,
2882
+ pendingAt: publicSignal.pendingAt,
2865
2883
  });
2866
2884
  continue;
2867
2885
  }
@@ -2876,6 +2894,14 @@ const PROCESS_COMMIT_QUEUE_FN = async (self, timestamp) => {
2876
2894
  percentToClose: commit.percentToClose,
2877
2895
  currentPrice: commit.currentPrice,
2878
2896
  timestamp,
2897
+ position: publicSignal.position,
2898
+ priceOpen: publicSignal.priceOpen,
2899
+ priceTakeProfit: publicSignal.priceTakeProfit,
2900
+ priceStopLoss: publicSignal.priceStopLoss,
2901
+ originalPriceTakeProfit: publicSignal.originalPriceTakeProfit,
2902
+ originalPriceStopLoss: publicSignal.originalPriceStopLoss,
2903
+ scheduledAt: publicSignal.scheduledAt,
2904
+ pendingAt: publicSignal.pendingAt,
2879
2905
  });
2880
2906
  continue;
2881
2907
  }
@@ -2889,6 +2915,14 @@ const PROCESS_COMMIT_QUEUE_FN = async (self, timestamp) => {
2889
2915
  backtest: commit.backtest,
2890
2916
  currentPrice: commit.currentPrice,
2891
2917
  timestamp,
2918
+ position: publicSignal.position,
2919
+ priceOpen: publicSignal.priceOpen,
2920
+ priceTakeProfit: publicSignal.priceTakeProfit,
2921
+ priceStopLoss: publicSignal.priceStopLoss,
2922
+ originalPriceTakeProfit: publicSignal.originalPriceTakeProfit,
2923
+ originalPriceStopLoss: publicSignal.originalPriceStopLoss,
2924
+ scheduledAt: publicSignal.scheduledAt,
2925
+ pendingAt: publicSignal.pendingAt,
2892
2926
  });
2893
2927
  continue;
2894
2928
  }
@@ -2903,6 +2937,14 @@ const PROCESS_COMMIT_QUEUE_FN = async (self, timestamp) => {
2903
2937
  percentShift: commit.percentShift,
2904
2938
  currentPrice: commit.currentPrice,
2905
2939
  timestamp,
2940
+ position: publicSignal.position,
2941
+ priceOpen: publicSignal.priceOpen,
2942
+ priceTakeProfit: publicSignal.priceTakeProfit,
2943
+ priceStopLoss: publicSignal.priceStopLoss,
2944
+ originalPriceTakeProfit: publicSignal.originalPriceTakeProfit,
2945
+ originalPriceStopLoss: publicSignal.originalPriceStopLoss,
2946
+ scheduledAt: publicSignal.scheduledAt,
2947
+ pendingAt: publicSignal.pendingAt,
2906
2948
  });
2907
2949
  continue;
2908
2950
  }
@@ -2917,6 +2959,14 @@ const PROCESS_COMMIT_QUEUE_FN = async (self, timestamp) => {
2917
2959
  percentShift: commit.percentShift,
2918
2960
  currentPrice: commit.currentPrice,
2919
2961
  timestamp,
2962
+ position: publicSignal.position,
2963
+ priceOpen: publicSignal.priceOpen,
2964
+ priceTakeProfit: publicSignal.priceTakeProfit,
2965
+ priceStopLoss: publicSignal.priceStopLoss,
2966
+ originalPriceTakeProfit: publicSignal.originalPriceTakeProfit,
2967
+ originalPriceStopLoss: publicSignal.originalPriceStopLoss,
2968
+ scheduledAt: publicSignal.scheduledAt,
2969
+ pendingAt: publicSignal.pendingAt,
2920
2970
  });
2921
2971
  continue;
2922
2972
  }
@@ -3243,7 +3293,7 @@ const VALIDATE_SIGNAL_FN = (signal, currentPrice, isScheduled) => {
3243
3293
  if (typeof signal.pendingAt !== "number") {
3244
3294
  errors.push(`pendingAt must be a number type, got ${signal.pendingAt} (${typeof signal.pendingAt})`);
3245
3295
  }
3246
- if (signal.pendingAt <= 0) {
3296
+ if (signal.pendingAt <= 0 && !isScheduled) {
3247
3297
  errors.push(`pendingAt must be positive, got ${signal.pendingAt}`);
3248
3298
  }
3249
3299
  }
@@ -3329,7 +3379,7 @@ const GET_SIGNAL_FN = trycatch(async (self) => {
3329
3379
  strategyName: self.params.method.context.strategyName,
3330
3380
  frameName: self.params.method.context.frameName,
3331
3381
  scheduledAt: currentTime,
3332
- pendingAt: currentTime, // Временно, обновится при активации
3382
+ pendingAt: SCHEDULED_SIGNAL_PENDING_MOCK, // Временно, обновится при активации
3333
3383
  _isScheduled: true,
3334
3384
  };
3335
3385
  // Валидируем сигнал перед возвратом
@@ -13473,6 +13523,8 @@ const backtest_columns = [
13473
13523
  key: "duration",
13474
13524
  label: "Duration (min)",
13475
13525
  format: (data) => {
13526
+ if (!data.closeTimestamp || !data.signal.pendingAt)
13527
+ return "N/A";
13476
13528
  const durationMs = data.closeTimestamp - data.signal.pendingAt;
13477
13529
  const durationMin = Math.round(durationMs / 60000);
13478
13530
  return `${durationMin}`;
@@ -13482,7 +13534,7 @@ const backtest_columns = [
13482
13534
  {
13483
13535
  key: "openTimestamp",
13484
13536
  label: "Open Time",
13485
- format: (data) => new Date(data.signal.pendingAt).toISOString(),
13537
+ format: (data) => data.signal.pendingAt ? new Date(data.signal.pendingAt).toISOString() : "N/A",
13486
13538
  isVisible: () => true,
13487
13539
  },
13488
13540
  {
@@ -23776,8 +23828,16 @@ class StrategyReportService {
23776
23828
  * @param isBacktest - Whether this is a backtest or live trading event
23777
23829
  * @param context - Strategy context with strategyName, exchangeName, frameName
23778
23830
  * @param timestamp - Timestamp from StrategyCommitContract (execution context time)
23779
- */
23780
- this.partialProfit = async (symbol, percentToClose, currentPrice, isBacktest, context, timestamp) => {
23831
+ * @param position - Trade direction: "long" or "short"
23832
+ * @param priceOpen - Entry price for the position
23833
+ * @param priceTakeProfit - Effective take profit price
23834
+ * @param priceStopLoss - Effective stop loss price
23835
+ * @param originalPriceTakeProfit - Original take profit before trailing
23836
+ * @param originalPriceStopLoss - Original stop loss before trailing
23837
+ * @param scheduledAt - Signal creation timestamp in milliseconds
23838
+ * @param pendingAt - Pending timestamp in milliseconds
23839
+ */
23840
+ this.partialProfit = async (symbol, percentToClose, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
23781
23841
  this.loggerService.log("strategyReportService partialProfit", {
23782
23842
  symbol,
23783
23843
  percentToClose,
@@ -23803,6 +23863,14 @@ class StrategyReportService {
23803
23863
  symbol,
23804
23864
  timestamp,
23805
23865
  createdAt,
23866
+ position,
23867
+ priceOpen,
23868
+ priceTakeProfit,
23869
+ priceStopLoss,
23870
+ originalPriceTakeProfit,
23871
+ originalPriceStopLoss,
23872
+ scheduledAt,
23873
+ pendingAt,
23806
23874
  }, {
23807
23875
  signalId: pendingRow.id,
23808
23876
  exchangeName: context.exchangeName,
@@ -23821,8 +23889,16 @@ class StrategyReportService {
23821
23889
  * @param isBacktest - Whether this is a backtest or live trading event
23822
23890
  * @param context - Strategy context with strategyName, exchangeName, frameName
23823
23891
  * @param timestamp - Timestamp from StrategyCommitContract (execution context time)
23824
- */
23825
- this.partialLoss = async (symbol, percentToClose, currentPrice, isBacktest, context, timestamp) => {
23892
+ * @param position - Trade direction: "long" or "short"
23893
+ * @param priceOpen - Entry price for the position
23894
+ * @param priceTakeProfit - Effective take profit price
23895
+ * @param priceStopLoss - Effective stop loss price
23896
+ * @param originalPriceTakeProfit - Original take profit before trailing
23897
+ * @param originalPriceStopLoss - Original stop loss before trailing
23898
+ * @param scheduledAt - Signal creation timestamp in milliseconds
23899
+ * @param pendingAt - Pending timestamp in milliseconds
23900
+ */
23901
+ this.partialLoss = async (symbol, percentToClose, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
23826
23902
  this.loggerService.log("strategyReportService partialLoss", {
23827
23903
  symbol,
23828
23904
  percentToClose,
@@ -23848,6 +23924,14 @@ class StrategyReportService {
23848
23924
  symbol,
23849
23925
  timestamp,
23850
23926
  createdAt,
23927
+ position,
23928
+ priceOpen,
23929
+ priceTakeProfit,
23930
+ priceStopLoss,
23931
+ originalPriceTakeProfit,
23932
+ originalPriceStopLoss,
23933
+ scheduledAt,
23934
+ pendingAt,
23851
23935
  }, {
23852
23936
  signalId: pendingRow.id,
23853
23937
  exchangeName: context.exchangeName,
@@ -23866,8 +23950,16 @@ class StrategyReportService {
23866
23950
  * @param isBacktest - Whether this is a backtest or live trading event
23867
23951
  * @param context - Strategy context with strategyName, exchangeName, frameName
23868
23952
  * @param timestamp - Timestamp from StrategyCommitContract (execution context time)
23869
- */
23870
- this.trailingStop = async (symbol, percentShift, currentPrice, isBacktest, context, timestamp) => {
23953
+ * @param position - Trade direction: "long" or "short"
23954
+ * @param priceOpen - Entry price for the position
23955
+ * @param priceTakeProfit - Effective take profit price
23956
+ * @param priceStopLoss - Effective stop loss price
23957
+ * @param originalPriceTakeProfit - Original take profit before trailing
23958
+ * @param originalPriceStopLoss - Original stop loss before trailing
23959
+ * @param scheduledAt - Signal creation timestamp in milliseconds
23960
+ * @param pendingAt - Pending timestamp in milliseconds
23961
+ */
23962
+ this.trailingStop = async (symbol, percentShift, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
23871
23963
  this.loggerService.log("strategyReportService trailingStop", {
23872
23964
  symbol,
23873
23965
  percentShift,
@@ -23893,6 +23985,14 @@ class StrategyReportService {
23893
23985
  symbol,
23894
23986
  timestamp,
23895
23987
  createdAt,
23988
+ position,
23989
+ priceOpen,
23990
+ priceTakeProfit,
23991
+ priceStopLoss,
23992
+ originalPriceTakeProfit,
23993
+ originalPriceStopLoss,
23994
+ scheduledAt,
23995
+ pendingAt,
23896
23996
  }, {
23897
23997
  signalId: pendingRow.id,
23898
23998
  exchangeName: context.exchangeName,
@@ -23911,8 +24011,16 @@ class StrategyReportService {
23911
24011
  * @param isBacktest - Whether this is a backtest or live trading event
23912
24012
  * @param context - Strategy context with strategyName, exchangeName, frameName
23913
24013
  * @param timestamp - Timestamp from StrategyCommitContract (execution context time)
23914
- */
23915
- this.trailingTake = async (symbol, percentShift, currentPrice, isBacktest, context, timestamp) => {
24014
+ * @param position - Trade direction: "long" or "short"
24015
+ * @param priceOpen - Entry price for the position
24016
+ * @param priceTakeProfit - Effective take profit price
24017
+ * @param priceStopLoss - Effective stop loss price
24018
+ * @param originalPriceTakeProfit - Original take profit before trailing
24019
+ * @param originalPriceStopLoss - Original stop loss before trailing
24020
+ * @param scheduledAt - Signal creation timestamp in milliseconds
24021
+ * @param pendingAt - Pending timestamp in milliseconds
24022
+ */
24023
+ this.trailingTake = async (symbol, percentShift, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
23916
24024
  this.loggerService.log("strategyReportService trailingTake", {
23917
24025
  symbol,
23918
24026
  percentShift,
@@ -23938,6 +24046,14 @@ class StrategyReportService {
23938
24046
  symbol,
23939
24047
  timestamp,
23940
24048
  createdAt,
24049
+ position,
24050
+ priceOpen,
24051
+ priceTakeProfit,
24052
+ priceStopLoss,
24053
+ originalPriceTakeProfit,
24054
+ originalPriceStopLoss,
24055
+ scheduledAt,
24056
+ pendingAt,
23941
24057
  }, {
23942
24058
  signalId: pendingRow.id,
23943
24059
  exchangeName: context.exchangeName,
@@ -23955,8 +24071,16 @@ class StrategyReportService {
23955
24071
  * @param isBacktest - Whether this is a backtest or live trading event
23956
24072
  * @param context - Strategy context with strategyName, exchangeName, frameName
23957
24073
  * @param timestamp - Timestamp from StrategyCommitContract (execution context time)
23958
- */
23959
- this.breakeven = async (symbol, currentPrice, isBacktest, context, timestamp) => {
24074
+ * @param position - Trade direction: "long" or "short"
24075
+ * @param priceOpen - Entry price for the position
24076
+ * @param priceTakeProfit - Effective take profit price
24077
+ * @param priceStopLoss - Effective stop loss price
24078
+ * @param originalPriceTakeProfit - Original take profit before trailing
24079
+ * @param originalPriceStopLoss - Original stop loss before trailing
24080
+ * @param scheduledAt - Signal creation timestamp in milliseconds
24081
+ * @param pendingAt - Pending timestamp in milliseconds
24082
+ */
24083
+ this.breakeven = async (symbol, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
23960
24084
  this.loggerService.log("strategyReportService breakeven", {
23961
24085
  symbol,
23962
24086
  currentPrice,
@@ -23980,6 +24104,14 @@ class StrategyReportService {
23980
24104
  symbol,
23981
24105
  timestamp,
23982
24106
  createdAt,
24107
+ position,
24108
+ priceOpen,
24109
+ priceTakeProfit,
24110
+ priceStopLoss,
24111
+ originalPriceTakeProfit,
24112
+ originalPriceStopLoss,
24113
+ scheduledAt,
24114
+ pendingAt,
23983
24115
  }, {
23984
24116
  signalId: pendingRow.id,
23985
24117
  exchangeName: context.exchangeName,
@@ -24019,35 +24151,35 @@ class StrategyReportService {
24019
24151
  exchangeName: event.exchangeName,
24020
24152
  frameName: event.frameName,
24021
24153
  strategyName: event.strategyName,
24022
- }, event.timestamp));
24154
+ }, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
24023
24155
  const unPartialLoss = strategyCommitSubject
24024
24156
  .filter(({ action }) => action === "partial-loss")
24025
24157
  .connect(async (event) => await this.partialLoss(event.symbol, event.percentToClose, event.currentPrice, event.backtest, {
24026
24158
  exchangeName: event.exchangeName,
24027
24159
  frameName: event.frameName,
24028
24160
  strategyName: event.strategyName,
24029
- }, event.timestamp));
24161
+ }, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
24030
24162
  const unTrailingStop = strategyCommitSubject
24031
24163
  .filter(({ action }) => action === "trailing-stop")
24032
24164
  .connect(async (event) => await this.trailingStop(event.symbol, event.percentShift, event.currentPrice, event.backtest, {
24033
24165
  exchangeName: event.exchangeName,
24034
24166
  frameName: event.frameName,
24035
24167
  strategyName: event.strategyName,
24036
- }, event.timestamp));
24168
+ }, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
24037
24169
  const unTrailingTake = strategyCommitSubject
24038
24170
  .filter(({ action }) => action === "trailing-take")
24039
24171
  .connect(async (event) => await this.trailingTake(event.symbol, event.percentShift, event.currentPrice, event.backtest, {
24040
24172
  exchangeName: event.exchangeName,
24041
24173
  frameName: event.frameName,
24042
24174
  strategyName: event.strategyName,
24043
- }, event.timestamp));
24175
+ }, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
24044
24176
  const unBreakeven = strategyCommitSubject
24045
24177
  .filter(({ action }) => action === "breakeven")
24046
24178
  .connect(async (event) => await this.breakeven(event.symbol, event.currentPrice, event.backtest, {
24047
24179
  exchangeName: event.exchangeName,
24048
24180
  frameName: event.frameName,
24049
24181
  strategyName: event.strategyName,
24050
- }, event.timestamp));
24182
+ }, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
24051
24183
  const disposeFn = compose(() => unCancelSchedule(), () => unClosePending(), () => unPartialProfit(), () => unPartialLoss(), () => unTrailingStop(), () => unTrailingTake(), () => unBreakeven());
24052
24184
  return () => {
24053
24185
  disposeFn();
@@ -24417,8 +24549,16 @@ class StrategyMarkdownService {
24417
24549
  * @param isBacktest - Whether this is a backtest or live trading event
24418
24550
  * @param context - Strategy context with strategyName, exchangeName, frameName
24419
24551
  * @param timestamp - Timestamp from StrategyCommitContract (execution context time)
24420
- */
24421
- this.partialProfit = async (symbol, percentToClose, currentPrice, isBacktest, context, timestamp) => {
24552
+ * @param position - Trade direction: "long" or "short"
24553
+ * @param priceOpen - Entry price for the position
24554
+ * @param priceTakeProfit - Effective take profit price
24555
+ * @param priceStopLoss - Effective stop loss price
24556
+ * @param originalPriceTakeProfit - Original take profit before trailing
24557
+ * @param originalPriceStopLoss - Original stop loss before trailing
24558
+ * @param scheduledAt - Signal creation timestamp in milliseconds
24559
+ * @param pendingAt - Pending timestamp in milliseconds
24560
+ */
24561
+ this.partialProfit = async (symbol, percentToClose, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
24422
24562
  this.loggerService.log("strategyMarkdownService partialProfit", {
24423
24563
  symbol,
24424
24564
  percentToClose,
@@ -24450,6 +24590,14 @@ class StrategyMarkdownService {
24450
24590
  currentPrice,
24451
24591
  createdAt,
24452
24592
  backtest: isBacktest,
24593
+ position,
24594
+ priceOpen,
24595
+ priceTakeProfit,
24596
+ priceStopLoss,
24597
+ originalPriceTakeProfit,
24598
+ originalPriceStopLoss,
24599
+ scheduledAt,
24600
+ pendingAt,
24453
24601
  });
24454
24602
  };
24455
24603
  /**
@@ -24461,8 +24609,16 @@ class StrategyMarkdownService {
24461
24609
  * @param isBacktest - Whether this is a backtest or live trading event
24462
24610
  * @param context - Strategy context with strategyName, exchangeName, frameName
24463
24611
  * @param timestamp - Timestamp from StrategyCommitContract (execution context time)
24464
- */
24465
- this.partialLoss = async (symbol, percentToClose, currentPrice, isBacktest, context, timestamp) => {
24612
+ * @param position - Trade direction: "long" or "short"
24613
+ * @param priceOpen - Entry price for the position
24614
+ * @param priceTakeProfit - Effective take profit price
24615
+ * @param priceStopLoss - Effective stop loss price
24616
+ * @param originalPriceTakeProfit - Original take profit before trailing
24617
+ * @param originalPriceStopLoss - Original stop loss before trailing
24618
+ * @param scheduledAt - Signal creation timestamp in milliseconds
24619
+ * @param pendingAt - Pending timestamp in milliseconds
24620
+ */
24621
+ this.partialLoss = async (symbol, percentToClose, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
24466
24622
  this.loggerService.log("strategyMarkdownService partialLoss", {
24467
24623
  symbol,
24468
24624
  percentToClose,
@@ -24494,6 +24650,14 @@ class StrategyMarkdownService {
24494
24650
  currentPrice,
24495
24651
  createdAt,
24496
24652
  backtest: isBacktest,
24653
+ position,
24654
+ priceOpen,
24655
+ priceTakeProfit,
24656
+ priceStopLoss,
24657
+ originalPriceTakeProfit,
24658
+ originalPriceStopLoss,
24659
+ scheduledAt,
24660
+ pendingAt,
24497
24661
  });
24498
24662
  };
24499
24663
  /**
@@ -24505,8 +24669,16 @@ class StrategyMarkdownService {
24505
24669
  * @param isBacktest - Whether this is a backtest or live trading event
24506
24670
  * @param context - Strategy context with strategyName, exchangeName, frameName
24507
24671
  * @param timestamp - Timestamp from StrategyCommitContract (execution context time)
24508
- */
24509
- this.trailingStop = async (symbol, percentShift, currentPrice, isBacktest, context, timestamp) => {
24672
+ * @param position - Trade direction: "long" or "short"
24673
+ * @param priceOpen - Entry price for the position
24674
+ * @param priceTakeProfit - Effective take profit price
24675
+ * @param priceStopLoss - Effective stop loss price
24676
+ * @param originalPriceTakeProfit - Original take profit before trailing
24677
+ * @param originalPriceStopLoss - Original stop loss before trailing
24678
+ * @param scheduledAt - Signal creation timestamp in milliseconds
24679
+ * @param pendingAt - Pending timestamp in milliseconds
24680
+ */
24681
+ this.trailingStop = async (symbol, percentShift, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
24510
24682
  this.loggerService.log("strategyMarkdownService trailingStop", {
24511
24683
  symbol,
24512
24684
  percentShift,
@@ -24538,6 +24710,14 @@ class StrategyMarkdownService {
24538
24710
  currentPrice,
24539
24711
  createdAt,
24540
24712
  backtest: isBacktest,
24713
+ position,
24714
+ priceOpen,
24715
+ priceTakeProfit,
24716
+ priceStopLoss,
24717
+ originalPriceTakeProfit,
24718
+ originalPriceStopLoss,
24719
+ scheduledAt,
24720
+ pendingAt,
24541
24721
  });
24542
24722
  };
24543
24723
  /**
@@ -24549,8 +24729,16 @@ class StrategyMarkdownService {
24549
24729
  * @param isBacktest - Whether this is a backtest or live trading event
24550
24730
  * @param context - Strategy context with strategyName, exchangeName, frameName
24551
24731
  * @param timestamp - Timestamp from StrategyCommitContract (execution context time)
24552
- */
24553
- this.trailingTake = async (symbol, percentShift, currentPrice, isBacktest, context, timestamp) => {
24732
+ * @param position - Trade direction: "long" or "short"
24733
+ * @param priceOpen - Entry price for the position
24734
+ * @param priceTakeProfit - Effective take profit price
24735
+ * @param priceStopLoss - Effective stop loss price
24736
+ * @param originalPriceTakeProfit - Original take profit before trailing
24737
+ * @param originalPriceStopLoss - Original stop loss before trailing
24738
+ * @param scheduledAt - Signal creation timestamp in milliseconds
24739
+ * @param pendingAt - Pending timestamp in milliseconds
24740
+ */
24741
+ this.trailingTake = async (symbol, percentShift, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
24554
24742
  this.loggerService.log("strategyMarkdownService trailingTake", {
24555
24743
  symbol,
24556
24744
  percentShift,
@@ -24582,6 +24770,14 @@ class StrategyMarkdownService {
24582
24770
  currentPrice,
24583
24771
  createdAt,
24584
24772
  backtest: isBacktest,
24773
+ position,
24774
+ priceOpen,
24775
+ priceTakeProfit,
24776
+ priceStopLoss,
24777
+ originalPriceTakeProfit,
24778
+ originalPriceStopLoss,
24779
+ scheduledAt,
24780
+ pendingAt,
24585
24781
  });
24586
24782
  };
24587
24783
  /**
@@ -24592,8 +24788,16 @@ class StrategyMarkdownService {
24592
24788
  * @param isBacktest - Whether this is a backtest or live trading event
24593
24789
  * @param context - Strategy context with strategyName, exchangeName, frameName
24594
24790
  * @param timestamp - Timestamp from StrategyCommitContract (execution context time)
24595
- */
24596
- this.breakeven = async (symbol, currentPrice, isBacktest, context, timestamp) => {
24791
+ * @param position - Trade direction: "long" or "short"
24792
+ * @param priceOpen - Entry price for the position
24793
+ * @param priceTakeProfit - Effective take profit price
24794
+ * @param priceStopLoss - Effective stop loss price
24795
+ * @param originalPriceTakeProfit - Original take profit before trailing
24796
+ * @param originalPriceStopLoss - Original stop loss before trailing
24797
+ * @param scheduledAt - Signal creation timestamp in milliseconds
24798
+ * @param pendingAt - Pending timestamp in milliseconds
24799
+ */
24800
+ this.breakeven = async (symbol, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
24597
24801
  this.loggerService.log("strategyMarkdownService breakeven", {
24598
24802
  symbol,
24599
24803
  currentPrice,
@@ -24623,6 +24827,14 @@ class StrategyMarkdownService {
24623
24827
  currentPrice,
24624
24828
  createdAt,
24625
24829
  backtest: isBacktest,
24830
+ position,
24831
+ priceOpen,
24832
+ priceTakeProfit,
24833
+ priceStopLoss,
24834
+ originalPriceTakeProfit,
24835
+ originalPriceStopLoss,
24836
+ scheduledAt,
24837
+ pendingAt,
24626
24838
  });
24627
24839
  };
24628
24840
  /**
@@ -24769,35 +24981,35 @@ class StrategyMarkdownService {
24769
24981
  exchangeName: event.exchangeName,
24770
24982
  frameName: event.frameName,
24771
24983
  strategyName: event.strategyName,
24772
- }, event.timestamp));
24984
+ }, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
24773
24985
  const unPartialLoss = strategyCommitSubject
24774
24986
  .filter(({ action }) => action === "partial-loss")
24775
24987
  .connect(async (event) => await this.partialLoss(event.symbol, event.percentToClose, event.currentPrice, event.backtest, {
24776
24988
  exchangeName: event.exchangeName,
24777
24989
  frameName: event.frameName,
24778
24990
  strategyName: event.strategyName,
24779
- }, event.timestamp));
24991
+ }, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
24780
24992
  const unTrailingStop = strategyCommitSubject
24781
24993
  .filter(({ action }) => action === "trailing-stop")
24782
24994
  .connect(async (event) => await this.trailingStop(event.symbol, event.percentShift, event.currentPrice, event.backtest, {
24783
24995
  exchangeName: event.exchangeName,
24784
24996
  frameName: event.frameName,
24785
24997
  strategyName: event.strategyName,
24786
- }, event.timestamp));
24998
+ }, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
24787
24999
  const unTrailingTake = strategyCommitSubject
24788
25000
  .filter(({ action }) => action === "trailing-take")
24789
25001
  .connect(async (event) => await this.trailingTake(event.symbol, event.percentShift, event.currentPrice, event.backtest, {
24790
25002
  exchangeName: event.exchangeName,
24791
25003
  frameName: event.frameName,
24792
25004
  strategyName: event.strategyName,
24793
- }, event.timestamp));
25005
+ }, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
24794
25006
  const unBreakeven = strategyCommitSubject
24795
25007
  .filter(({ action }) => action === "breakeven")
24796
25008
  .connect(async (event) => await this.breakeven(event.symbol, event.currentPrice, event.backtest, {
24797
25009
  exchangeName: event.exchangeName,
24798
25010
  frameName: event.frameName,
24799
25011
  strategyName: event.strategyName,
24800
- }, event.timestamp));
25012
+ }, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
24801
25013
  const disposeFn = compose(() => unCancelSchedule(), () => unClosePending(), () => unPartialProfit(), () => unPartialLoss(), () => unTrailingStop(), () => unTrailingTake(), () => unBreakeven());
24802
25014
  return () => {
24803
25015
  disposeFn();
@@ -33709,6 +33921,12 @@ class NotificationInstance {
33709
33921
  currentPrice: data.currentPrice,
33710
33922
  priceOpen: data.data.priceOpen,
33711
33923
  position: data.data.position,
33924
+ priceTakeProfit: data.data.priceTakeProfit,
33925
+ priceStopLoss: data.data.priceStopLoss,
33926
+ originalPriceTakeProfit: data.data.originalPriceTakeProfit,
33927
+ originalPriceStopLoss: data.data.originalPriceStopLoss,
33928
+ scheduledAt: data.data.scheduledAt,
33929
+ pendingAt: data.data.pendingAt,
33712
33930
  createdAt: data.timestamp,
33713
33931
  });
33714
33932
  };
@@ -33729,6 +33947,12 @@ class NotificationInstance {
33729
33947
  currentPrice: data.currentPrice,
33730
33948
  priceOpen: data.data.priceOpen,
33731
33949
  position: data.data.position,
33950
+ priceTakeProfit: data.data.priceTakeProfit,
33951
+ priceStopLoss: data.data.priceStopLoss,
33952
+ originalPriceTakeProfit: data.data.originalPriceTakeProfit,
33953
+ originalPriceStopLoss: data.data.originalPriceStopLoss,
33954
+ scheduledAt: data.data.scheduledAt,
33955
+ pendingAt: data.data.pendingAt,
33732
33956
  createdAt: data.timestamp,
33733
33957
  });
33734
33958
  };
@@ -33748,6 +33972,12 @@ class NotificationInstance {
33748
33972
  currentPrice: data.currentPrice,
33749
33973
  priceOpen: data.data.priceOpen,
33750
33974
  position: data.data.position,
33975
+ priceTakeProfit: data.data.priceTakeProfit,
33976
+ priceStopLoss: data.data.priceStopLoss,
33977
+ originalPriceTakeProfit: data.data.originalPriceTakeProfit,
33978
+ originalPriceStopLoss: data.data.originalPriceStopLoss,
33979
+ scheduledAt: data.data.scheduledAt,
33980
+ pendingAt: data.data.pendingAt,
33751
33981
  createdAt: data.timestamp,
33752
33982
  });
33753
33983
  };
@@ -33766,6 +33996,14 @@ class NotificationInstance {
33766
33996
  exchangeName: data.exchangeName,
33767
33997
  percentToClose: data.percentToClose,
33768
33998
  currentPrice: data.currentPrice,
33999
+ position: data.position,
34000
+ priceOpen: data.priceOpen,
34001
+ priceTakeProfit: data.priceTakeProfit,
34002
+ priceStopLoss: data.priceStopLoss,
34003
+ originalPriceTakeProfit: data.originalPriceTakeProfit,
34004
+ originalPriceStopLoss: data.originalPriceStopLoss,
34005
+ scheduledAt: data.scheduledAt,
34006
+ pendingAt: data.pendingAt,
33769
34007
  createdAt: data.timestamp,
33770
34008
  });
33771
34009
  }
@@ -33780,6 +34018,14 @@ class NotificationInstance {
33780
34018
  exchangeName: data.exchangeName,
33781
34019
  percentToClose: data.percentToClose,
33782
34020
  currentPrice: data.currentPrice,
34021
+ position: data.position,
34022
+ priceOpen: data.priceOpen,
34023
+ priceTakeProfit: data.priceTakeProfit,
34024
+ priceStopLoss: data.priceStopLoss,
34025
+ originalPriceTakeProfit: data.originalPriceTakeProfit,
34026
+ originalPriceStopLoss: data.originalPriceStopLoss,
34027
+ scheduledAt: data.scheduledAt,
34028
+ pendingAt: data.pendingAt,
33783
34029
  createdAt: data.timestamp,
33784
34030
  });
33785
34031
  }
@@ -33793,6 +34039,14 @@ class NotificationInstance {
33793
34039
  strategyName: data.strategyName,
33794
34040
  exchangeName: data.exchangeName,
33795
34041
  currentPrice: data.currentPrice,
34042
+ position: data.position,
34043
+ priceOpen: data.priceOpen,
34044
+ priceTakeProfit: data.priceTakeProfit,
34045
+ priceStopLoss: data.priceStopLoss,
34046
+ originalPriceTakeProfit: data.originalPriceTakeProfit,
34047
+ originalPriceStopLoss: data.originalPriceStopLoss,
34048
+ scheduledAt: data.scheduledAt,
34049
+ pendingAt: data.pendingAt,
33796
34050
  createdAt: data.timestamp,
33797
34051
  });
33798
34052
  }
@@ -33807,6 +34061,14 @@ class NotificationInstance {
33807
34061
  exchangeName: data.exchangeName,
33808
34062
  percentShift: data.percentShift,
33809
34063
  currentPrice: data.currentPrice,
34064
+ position: data.position,
34065
+ priceOpen: data.priceOpen,
34066
+ priceTakeProfit: data.priceTakeProfit,
34067
+ priceStopLoss: data.priceStopLoss,
34068
+ originalPriceTakeProfit: data.originalPriceTakeProfit,
34069
+ originalPriceStopLoss: data.originalPriceStopLoss,
34070
+ scheduledAt: data.scheduledAt,
34071
+ pendingAt: data.pendingAt,
33810
34072
  createdAt: data.timestamp,
33811
34073
  });
33812
34074
  }
@@ -33821,6 +34083,14 @@ class NotificationInstance {
33821
34083
  exchangeName: data.exchangeName,
33822
34084
  percentShift: data.percentShift,
33823
34085
  currentPrice: data.currentPrice,
34086
+ position: data.position,
34087
+ priceOpen: data.priceOpen,
34088
+ priceTakeProfit: data.priceTakeProfit,
34089
+ priceStopLoss: data.priceStopLoss,
34090
+ originalPriceTakeProfit: data.originalPriceTakeProfit,
34091
+ originalPriceStopLoss: data.originalPriceStopLoss,
34092
+ scheduledAt: data.scheduledAt,
34093
+ pendingAt: data.pendingAt,
33824
34094
  createdAt: data.timestamp,
33825
34095
  });
33826
34096
  }