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.cjs +303 -33
- package/build/index.mjs +303 -33
- package/package.json +1 -1
- package/types.d.ts +262 -10
package/build/index.cjs
CHANGED
|
@@ -2828,6 +2828,11 @@ const INTERVAL_MINUTES$3 = {
|
|
|
2828
2828
|
"30m": 30,
|
|
2829
2829
|
"1h": 60,
|
|
2830
2830
|
};
|
|
2831
|
+
/**
|
|
2832
|
+
* Mock value for scheduled signal pendingAt timestamp.
|
|
2833
|
+
* Used to indicate that the actual pendingAt will be set upon activation.
|
|
2834
|
+
*/
|
|
2835
|
+
const SCHEDULED_SIGNAL_PENDING_MOCK = 0;
|
|
2831
2836
|
const TIMEOUT_SYMBOL = Symbol('timeout');
|
|
2832
2837
|
/**
|
|
2833
2838
|
* Calls onCommit callback with strategy commit event.
|
|
@@ -2870,6 +2875,11 @@ const PROCESS_COMMIT_QUEUE_FN = async (self, timestamp) => {
|
|
|
2870
2875
|
{
|
|
2871
2876
|
self._commitQueue = [];
|
|
2872
2877
|
}
|
|
2878
|
+
if (!self._pendingSignal) {
|
|
2879
|
+
return;
|
|
2880
|
+
}
|
|
2881
|
+
// Get public signal data for commit events (contains effective and original SL/TP)
|
|
2882
|
+
const publicSignal = TO_PUBLIC_SIGNAL(self._pendingSignal);
|
|
2873
2883
|
for (const commit of queue) {
|
|
2874
2884
|
if (commit.action === "partial-profit") {
|
|
2875
2885
|
await CALL_COMMIT_FN(self, {
|
|
@@ -2882,6 +2892,14 @@ const PROCESS_COMMIT_QUEUE_FN = async (self, timestamp) => {
|
|
|
2882
2892
|
percentToClose: commit.percentToClose,
|
|
2883
2893
|
currentPrice: commit.currentPrice,
|
|
2884
2894
|
timestamp,
|
|
2895
|
+
position: publicSignal.position,
|
|
2896
|
+
priceOpen: publicSignal.priceOpen,
|
|
2897
|
+
priceTakeProfit: publicSignal.priceTakeProfit,
|
|
2898
|
+
priceStopLoss: publicSignal.priceStopLoss,
|
|
2899
|
+
originalPriceTakeProfit: publicSignal.originalPriceTakeProfit,
|
|
2900
|
+
originalPriceStopLoss: publicSignal.originalPriceStopLoss,
|
|
2901
|
+
scheduledAt: publicSignal.scheduledAt,
|
|
2902
|
+
pendingAt: publicSignal.pendingAt,
|
|
2885
2903
|
});
|
|
2886
2904
|
continue;
|
|
2887
2905
|
}
|
|
@@ -2896,6 +2914,14 @@ const PROCESS_COMMIT_QUEUE_FN = async (self, timestamp) => {
|
|
|
2896
2914
|
percentToClose: commit.percentToClose,
|
|
2897
2915
|
currentPrice: commit.currentPrice,
|
|
2898
2916
|
timestamp,
|
|
2917
|
+
position: publicSignal.position,
|
|
2918
|
+
priceOpen: publicSignal.priceOpen,
|
|
2919
|
+
priceTakeProfit: publicSignal.priceTakeProfit,
|
|
2920
|
+
priceStopLoss: publicSignal.priceStopLoss,
|
|
2921
|
+
originalPriceTakeProfit: publicSignal.originalPriceTakeProfit,
|
|
2922
|
+
originalPriceStopLoss: publicSignal.originalPriceStopLoss,
|
|
2923
|
+
scheduledAt: publicSignal.scheduledAt,
|
|
2924
|
+
pendingAt: publicSignal.pendingAt,
|
|
2899
2925
|
});
|
|
2900
2926
|
continue;
|
|
2901
2927
|
}
|
|
@@ -2909,6 +2935,14 @@ const PROCESS_COMMIT_QUEUE_FN = async (self, timestamp) => {
|
|
|
2909
2935
|
backtest: commit.backtest,
|
|
2910
2936
|
currentPrice: commit.currentPrice,
|
|
2911
2937
|
timestamp,
|
|
2938
|
+
position: publicSignal.position,
|
|
2939
|
+
priceOpen: publicSignal.priceOpen,
|
|
2940
|
+
priceTakeProfit: publicSignal.priceTakeProfit,
|
|
2941
|
+
priceStopLoss: publicSignal.priceStopLoss,
|
|
2942
|
+
originalPriceTakeProfit: publicSignal.originalPriceTakeProfit,
|
|
2943
|
+
originalPriceStopLoss: publicSignal.originalPriceStopLoss,
|
|
2944
|
+
scheduledAt: publicSignal.scheduledAt,
|
|
2945
|
+
pendingAt: publicSignal.pendingAt,
|
|
2912
2946
|
});
|
|
2913
2947
|
continue;
|
|
2914
2948
|
}
|
|
@@ -2923,6 +2957,14 @@ const PROCESS_COMMIT_QUEUE_FN = async (self, timestamp) => {
|
|
|
2923
2957
|
percentShift: commit.percentShift,
|
|
2924
2958
|
currentPrice: commit.currentPrice,
|
|
2925
2959
|
timestamp,
|
|
2960
|
+
position: publicSignal.position,
|
|
2961
|
+
priceOpen: publicSignal.priceOpen,
|
|
2962
|
+
priceTakeProfit: publicSignal.priceTakeProfit,
|
|
2963
|
+
priceStopLoss: publicSignal.priceStopLoss,
|
|
2964
|
+
originalPriceTakeProfit: publicSignal.originalPriceTakeProfit,
|
|
2965
|
+
originalPriceStopLoss: publicSignal.originalPriceStopLoss,
|
|
2966
|
+
scheduledAt: publicSignal.scheduledAt,
|
|
2967
|
+
pendingAt: publicSignal.pendingAt,
|
|
2926
2968
|
});
|
|
2927
2969
|
continue;
|
|
2928
2970
|
}
|
|
@@ -2937,6 +2979,14 @@ const PROCESS_COMMIT_QUEUE_FN = async (self, timestamp) => {
|
|
|
2937
2979
|
percentShift: commit.percentShift,
|
|
2938
2980
|
currentPrice: commit.currentPrice,
|
|
2939
2981
|
timestamp,
|
|
2982
|
+
position: publicSignal.position,
|
|
2983
|
+
priceOpen: publicSignal.priceOpen,
|
|
2984
|
+
priceTakeProfit: publicSignal.priceTakeProfit,
|
|
2985
|
+
priceStopLoss: publicSignal.priceStopLoss,
|
|
2986
|
+
originalPriceTakeProfit: publicSignal.originalPriceTakeProfit,
|
|
2987
|
+
originalPriceStopLoss: publicSignal.originalPriceStopLoss,
|
|
2988
|
+
scheduledAt: publicSignal.scheduledAt,
|
|
2989
|
+
pendingAt: publicSignal.pendingAt,
|
|
2940
2990
|
});
|
|
2941
2991
|
continue;
|
|
2942
2992
|
}
|
|
@@ -3263,7 +3313,7 @@ const VALIDATE_SIGNAL_FN = (signal, currentPrice, isScheduled) => {
|
|
|
3263
3313
|
if (typeof signal.pendingAt !== "number") {
|
|
3264
3314
|
errors.push(`pendingAt must be a number type, got ${signal.pendingAt} (${typeof signal.pendingAt})`);
|
|
3265
3315
|
}
|
|
3266
|
-
if (signal.pendingAt <= 0) {
|
|
3316
|
+
if (signal.pendingAt <= 0 && !isScheduled) {
|
|
3267
3317
|
errors.push(`pendingAt must be positive, got ${signal.pendingAt}`);
|
|
3268
3318
|
}
|
|
3269
3319
|
}
|
|
@@ -3349,7 +3399,7 @@ const GET_SIGNAL_FN = functoolsKit.trycatch(async (self) => {
|
|
|
3349
3399
|
strategyName: self.params.method.context.strategyName,
|
|
3350
3400
|
frameName: self.params.method.context.frameName,
|
|
3351
3401
|
scheduledAt: currentTime,
|
|
3352
|
-
pendingAt:
|
|
3402
|
+
pendingAt: SCHEDULED_SIGNAL_PENDING_MOCK, // Временно, обновится при активации
|
|
3353
3403
|
_isScheduled: true,
|
|
3354
3404
|
};
|
|
3355
3405
|
// Валидируем сигнал перед возвратом
|
|
@@ -13493,6 +13543,8 @@ const backtest_columns = [
|
|
|
13493
13543
|
key: "duration",
|
|
13494
13544
|
label: "Duration (min)",
|
|
13495
13545
|
format: (data) => {
|
|
13546
|
+
if (!data.closeTimestamp || !data.signal.pendingAt)
|
|
13547
|
+
return "N/A";
|
|
13496
13548
|
const durationMs = data.closeTimestamp - data.signal.pendingAt;
|
|
13497
13549
|
const durationMin = Math.round(durationMs / 60000);
|
|
13498
13550
|
return `${durationMin}`;
|
|
@@ -13502,7 +13554,7 @@ const backtest_columns = [
|
|
|
13502
13554
|
{
|
|
13503
13555
|
key: "openTimestamp",
|
|
13504
13556
|
label: "Open Time",
|
|
13505
|
-
format: (data) => new Date(data.signal.pendingAt).toISOString(),
|
|
13557
|
+
format: (data) => data.signal.pendingAt ? new Date(data.signal.pendingAt).toISOString() : "N/A",
|
|
13506
13558
|
isVisible: () => true,
|
|
13507
13559
|
},
|
|
13508
13560
|
{
|
|
@@ -23796,8 +23848,16 @@ class StrategyReportService {
|
|
|
23796
23848
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
23797
23849
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
23798
23850
|
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
23799
|
-
|
|
23800
|
-
|
|
23851
|
+
* @param position - Trade direction: "long" or "short"
|
|
23852
|
+
* @param priceOpen - Entry price for the position
|
|
23853
|
+
* @param priceTakeProfit - Effective take profit price
|
|
23854
|
+
* @param priceStopLoss - Effective stop loss price
|
|
23855
|
+
* @param originalPriceTakeProfit - Original take profit before trailing
|
|
23856
|
+
* @param originalPriceStopLoss - Original stop loss before trailing
|
|
23857
|
+
* @param scheduledAt - Signal creation timestamp in milliseconds
|
|
23858
|
+
* @param pendingAt - Pending timestamp in milliseconds
|
|
23859
|
+
*/
|
|
23860
|
+
this.partialProfit = async (symbol, percentToClose, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
|
|
23801
23861
|
this.loggerService.log("strategyReportService partialProfit", {
|
|
23802
23862
|
symbol,
|
|
23803
23863
|
percentToClose,
|
|
@@ -23823,6 +23883,14 @@ class StrategyReportService {
|
|
|
23823
23883
|
symbol,
|
|
23824
23884
|
timestamp,
|
|
23825
23885
|
createdAt,
|
|
23886
|
+
position,
|
|
23887
|
+
priceOpen,
|
|
23888
|
+
priceTakeProfit,
|
|
23889
|
+
priceStopLoss,
|
|
23890
|
+
originalPriceTakeProfit,
|
|
23891
|
+
originalPriceStopLoss,
|
|
23892
|
+
scheduledAt,
|
|
23893
|
+
pendingAt,
|
|
23826
23894
|
}, {
|
|
23827
23895
|
signalId: pendingRow.id,
|
|
23828
23896
|
exchangeName: context.exchangeName,
|
|
@@ -23841,8 +23909,16 @@ class StrategyReportService {
|
|
|
23841
23909
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
23842
23910
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
23843
23911
|
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
23844
|
-
|
|
23845
|
-
|
|
23912
|
+
* @param position - Trade direction: "long" or "short"
|
|
23913
|
+
* @param priceOpen - Entry price for the position
|
|
23914
|
+
* @param priceTakeProfit - Effective take profit price
|
|
23915
|
+
* @param priceStopLoss - Effective stop loss price
|
|
23916
|
+
* @param originalPriceTakeProfit - Original take profit before trailing
|
|
23917
|
+
* @param originalPriceStopLoss - Original stop loss before trailing
|
|
23918
|
+
* @param scheduledAt - Signal creation timestamp in milliseconds
|
|
23919
|
+
* @param pendingAt - Pending timestamp in milliseconds
|
|
23920
|
+
*/
|
|
23921
|
+
this.partialLoss = async (symbol, percentToClose, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
|
|
23846
23922
|
this.loggerService.log("strategyReportService partialLoss", {
|
|
23847
23923
|
symbol,
|
|
23848
23924
|
percentToClose,
|
|
@@ -23868,6 +23944,14 @@ class StrategyReportService {
|
|
|
23868
23944
|
symbol,
|
|
23869
23945
|
timestamp,
|
|
23870
23946
|
createdAt,
|
|
23947
|
+
position,
|
|
23948
|
+
priceOpen,
|
|
23949
|
+
priceTakeProfit,
|
|
23950
|
+
priceStopLoss,
|
|
23951
|
+
originalPriceTakeProfit,
|
|
23952
|
+
originalPriceStopLoss,
|
|
23953
|
+
scheduledAt,
|
|
23954
|
+
pendingAt,
|
|
23871
23955
|
}, {
|
|
23872
23956
|
signalId: pendingRow.id,
|
|
23873
23957
|
exchangeName: context.exchangeName,
|
|
@@ -23886,8 +23970,16 @@ class StrategyReportService {
|
|
|
23886
23970
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
23887
23971
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
23888
23972
|
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
23889
|
-
|
|
23890
|
-
|
|
23973
|
+
* @param position - Trade direction: "long" or "short"
|
|
23974
|
+
* @param priceOpen - Entry price for the position
|
|
23975
|
+
* @param priceTakeProfit - Effective take profit price
|
|
23976
|
+
* @param priceStopLoss - Effective stop loss price
|
|
23977
|
+
* @param originalPriceTakeProfit - Original take profit before trailing
|
|
23978
|
+
* @param originalPriceStopLoss - Original stop loss before trailing
|
|
23979
|
+
* @param scheduledAt - Signal creation timestamp in milliseconds
|
|
23980
|
+
* @param pendingAt - Pending timestamp in milliseconds
|
|
23981
|
+
*/
|
|
23982
|
+
this.trailingStop = async (symbol, percentShift, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
|
|
23891
23983
|
this.loggerService.log("strategyReportService trailingStop", {
|
|
23892
23984
|
symbol,
|
|
23893
23985
|
percentShift,
|
|
@@ -23913,6 +24005,14 @@ class StrategyReportService {
|
|
|
23913
24005
|
symbol,
|
|
23914
24006
|
timestamp,
|
|
23915
24007
|
createdAt,
|
|
24008
|
+
position,
|
|
24009
|
+
priceOpen,
|
|
24010
|
+
priceTakeProfit,
|
|
24011
|
+
priceStopLoss,
|
|
24012
|
+
originalPriceTakeProfit,
|
|
24013
|
+
originalPriceStopLoss,
|
|
24014
|
+
scheduledAt,
|
|
24015
|
+
pendingAt,
|
|
23916
24016
|
}, {
|
|
23917
24017
|
signalId: pendingRow.id,
|
|
23918
24018
|
exchangeName: context.exchangeName,
|
|
@@ -23931,8 +24031,16 @@ class StrategyReportService {
|
|
|
23931
24031
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
23932
24032
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
23933
24033
|
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
23934
|
-
|
|
23935
|
-
|
|
24034
|
+
* @param position - Trade direction: "long" or "short"
|
|
24035
|
+
* @param priceOpen - Entry price for the position
|
|
24036
|
+
* @param priceTakeProfit - Effective take profit price
|
|
24037
|
+
* @param priceStopLoss - Effective stop loss price
|
|
24038
|
+
* @param originalPriceTakeProfit - Original take profit before trailing
|
|
24039
|
+
* @param originalPriceStopLoss - Original stop loss before trailing
|
|
24040
|
+
* @param scheduledAt - Signal creation timestamp in milliseconds
|
|
24041
|
+
* @param pendingAt - Pending timestamp in milliseconds
|
|
24042
|
+
*/
|
|
24043
|
+
this.trailingTake = async (symbol, percentShift, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
|
|
23936
24044
|
this.loggerService.log("strategyReportService trailingTake", {
|
|
23937
24045
|
symbol,
|
|
23938
24046
|
percentShift,
|
|
@@ -23958,6 +24066,14 @@ class StrategyReportService {
|
|
|
23958
24066
|
symbol,
|
|
23959
24067
|
timestamp,
|
|
23960
24068
|
createdAt,
|
|
24069
|
+
position,
|
|
24070
|
+
priceOpen,
|
|
24071
|
+
priceTakeProfit,
|
|
24072
|
+
priceStopLoss,
|
|
24073
|
+
originalPriceTakeProfit,
|
|
24074
|
+
originalPriceStopLoss,
|
|
24075
|
+
scheduledAt,
|
|
24076
|
+
pendingAt,
|
|
23961
24077
|
}, {
|
|
23962
24078
|
signalId: pendingRow.id,
|
|
23963
24079
|
exchangeName: context.exchangeName,
|
|
@@ -23975,8 +24091,16 @@ class StrategyReportService {
|
|
|
23975
24091
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
23976
24092
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
23977
24093
|
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
23978
|
-
|
|
23979
|
-
|
|
24094
|
+
* @param position - Trade direction: "long" or "short"
|
|
24095
|
+
* @param priceOpen - Entry price for the position
|
|
24096
|
+
* @param priceTakeProfit - Effective take profit price
|
|
24097
|
+
* @param priceStopLoss - Effective stop loss price
|
|
24098
|
+
* @param originalPriceTakeProfit - Original take profit before trailing
|
|
24099
|
+
* @param originalPriceStopLoss - Original stop loss before trailing
|
|
24100
|
+
* @param scheduledAt - Signal creation timestamp in milliseconds
|
|
24101
|
+
* @param pendingAt - Pending timestamp in milliseconds
|
|
24102
|
+
*/
|
|
24103
|
+
this.breakeven = async (symbol, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
|
|
23980
24104
|
this.loggerService.log("strategyReportService breakeven", {
|
|
23981
24105
|
symbol,
|
|
23982
24106
|
currentPrice,
|
|
@@ -24000,6 +24124,14 @@ class StrategyReportService {
|
|
|
24000
24124
|
symbol,
|
|
24001
24125
|
timestamp,
|
|
24002
24126
|
createdAt,
|
|
24127
|
+
position,
|
|
24128
|
+
priceOpen,
|
|
24129
|
+
priceTakeProfit,
|
|
24130
|
+
priceStopLoss,
|
|
24131
|
+
originalPriceTakeProfit,
|
|
24132
|
+
originalPriceStopLoss,
|
|
24133
|
+
scheduledAt,
|
|
24134
|
+
pendingAt,
|
|
24003
24135
|
}, {
|
|
24004
24136
|
signalId: pendingRow.id,
|
|
24005
24137
|
exchangeName: context.exchangeName,
|
|
@@ -24039,35 +24171,35 @@ class StrategyReportService {
|
|
|
24039
24171
|
exchangeName: event.exchangeName,
|
|
24040
24172
|
frameName: event.frameName,
|
|
24041
24173
|
strategyName: event.strategyName,
|
|
24042
|
-
}, event.timestamp));
|
|
24174
|
+
}, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
|
|
24043
24175
|
const unPartialLoss = strategyCommitSubject
|
|
24044
24176
|
.filter(({ action }) => action === "partial-loss")
|
|
24045
24177
|
.connect(async (event) => await this.partialLoss(event.symbol, event.percentToClose, event.currentPrice, event.backtest, {
|
|
24046
24178
|
exchangeName: event.exchangeName,
|
|
24047
24179
|
frameName: event.frameName,
|
|
24048
24180
|
strategyName: event.strategyName,
|
|
24049
|
-
}, event.timestamp));
|
|
24181
|
+
}, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
|
|
24050
24182
|
const unTrailingStop = strategyCommitSubject
|
|
24051
24183
|
.filter(({ action }) => action === "trailing-stop")
|
|
24052
24184
|
.connect(async (event) => await this.trailingStop(event.symbol, event.percentShift, event.currentPrice, event.backtest, {
|
|
24053
24185
|
exchangeName: event.exchangeName,
|
|
24054
24186
|
frameName: event.frameName,
|
|
24055
24187
|
strategyName: event.strategyName,
|
|
24056
|
-
}, event.timestamp));
|
|
24188
|
+
}, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
|
|
24057
24189
|
const unTrailingTake = strategyCommitSubject
|
|
24058
24190
|
.filter(({ action }) => action === "trailing-take")
|
|
24059
24191
|
.connect(async (event) => await this.trailingTake(event.symbol, event.percentShift, event.currentPrice, event.backtest, {
|
|
24060
24192
|
exchangeName: event.exchangeName,
|
|
24061
24193
|
frameName: event.frameName,
|
|
24062
24194
|
strategyName: event.strategyName,
|
|
24063
|
-
}, event.timestamp));
|
|
24195
|
+
}, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
|
|
24064
24196
|
const unBreakeven = strategyCommitSubject
|
|
24065
24197
|
.filter(({ action }) => action === "breakeven")
|
|
24066
24198
|
.connect(async (event) => await this.breakeven(event.symbol, event.currentPrice, event.backtest, {
|
|
24067
24199
|
exchangeName: event.exchangeName,
|
|
24068
24200
|
frameName: event.frameName,
|
|
24069
24201
|
strategyName: event.strategyName,
|
|
24070
|
-
}, event.timestamp));
|
|
24202
|
+
}, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
|
|
24071
24203
|
const disposeFn = functoolsKit.compose(() => unCancelSchedule(), () => unClosePending(), () => unPartialProfit(), () => unPartialLoss(), () => unTrailingStop(), () => unTrailingTake(), () => unBreakeven());
|
|
24072
24204
|
return () => {
|
|
24073
24205
|
disposeFn();
|
|
@@ -24437,8 +24569,16 @@ class StrategyMarkdownService {
|
|
|
24437
24569
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
24438
24570
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
24439
24571
|
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
24440
|
-
|
|
24441
|
-
|
|
24572
|
+
* @param position - Trade direction: "long" or "short"
|
|
24573
|
+
* @param priceOpen - Entry price for the position
|
|
24574
|
+
* @param priceTakeProfit - Effective take profit price
|
|
24575
|
+
* @param priceStopLoss - Effective stop loss price
|
|
24576
|
+
* @param originalPriceTakeProfit - Original take profit before trailing
|
|
24577
|
+
* @param originalPriceStopLoss - Original stop loss before trailing
|
|
24578
|
+
* @param scheduledAt - Signal creation timestamp in milliseconds
|
|
24579
|
+
* @param pendingAt - Pending timestamp in milliseconds
|
|
24580
|
+
*/
|
|
24581
|
+
this.partialProfit = async (symbol, percentToClose, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
|
|
24442
24582
|
this.loggerService.log("strategyMarkdownService partialProfit", {
|
|
24443
24583
|
symbol,
|
|
24444
24584
|
percentToClose,
|
|
@@ -24470,6 +24610,14 @@ class StrategyMarkdownService {
|
|
|
24470
24610
|
currentPrice,
|
|
24471
24611
|
createdAt,
|
|
24472
24612
|
backtest: isBacktest,
|
|
24613
|
+
position,
|
|
24614
|
+
priceOpen,
|
|
24615
|
+
priceTakeProfit,
|
|
24616
|
+
priceStopLoss,
|
|
24617
|
+
originalPriceTakeProfit,
|
|
24618
|
+
originalPriceStopLoss,
|
|
24619
|
+
scheduledAt,
|
|
24620
|
+
pendingAt,
|
|
24473
24621
|
});
|
|
24474
24622
|
};
|
|
24475
24623
|
/**
|
|
@@ -24481,8 +24629,16 @@ class StrategyMarkdownService {
|
|
|
24481
24629
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
24482
24630
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
24483
24631
|
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
24484
|
-
|
|
24485
|
-
|
|
24632
|
+
* @param position - Trade direction: "long" or "short"
|
|
24633
|
+
* @param priceOpen - Entry price for the position
|
|
24634
|
+
* @param priceTakeProfit - Effective take profit price
|
|
24635
|
+
* @param priceStopLoss - Effective stop loss price
|
|
24636
|
+
* @param originalPriceTakeProfit - Original take profit before trailing
|
|
24637
|
+
* @param originalPriceStopLoss - Original stop loss before trailing
|
|
24638
|
+
* @param scheduledAt - Signal creation timestamp in milliseconds
|
|
24639
|
+
* @param pendingAt - Pending timestamp in milliseconds
|
|
24640
|
+
*/
|
|
24641
|
+
this.partialLoss = async (symbol, percentToClose, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
|
|
24486
24642
|
this.loggerService.log("strategyMarkdownService partialLoss", {
|
|
24487
24643
|
symbol,
|
|
24488
24644
|
percentToClose,
|
|
@@ -24514,6 +24670,14 @@ class StrategyMarkdownService {
|
|
|
24514
24670
|
currentPrice,
|
|
24515
24671
|
createdAt,
|
|
24516
24672
|
backtest: isBacktest,
|
|
24673
|
+
position,
|
|
24674
|
+
priceOpen,
|
|
24675
|
+
priceTakeProfit,
|
|
24676
|
+
priceStopLoss,
|
|
24677
|
+
originalPriceTakeProfit,
|
|
24678
|
+
originalPriceStopLoss,
|
|
24679
|
+
scheduledAt,
|
|
24680
|
+
pendingAt,
|
|
24517
24681
|
});
|
|
24518
24682
|
};
|
|
24519
24683
|
/**
|
|
@@ -24525,8 +24689,16 @@ class StrategyMarkdownService {
|
|
|
24525
24689
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
24526
24690
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
24527
24691
|
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
24528
|
-
|
|
24529
|
-
|
|
24692
|
+
* @param position - Trade direction: "long" or "short"
|
|
24693
|
+
* @param priceOpen - Entry price for the position
|
|
24694
|
+
* @param priceTakeProfit - Effective take profit price
|
|
24695
|
+
* @param priceStopLoss - Effective stop loss price
|
|
24696
|
+
* @param originalPriceTakeProfit - Original take profit before trailing
|
|
24697
|
+
* @param originalPriceStopLoss - Original stop loss before trailing
|
|
24698
|
+
* @param scheduledAt - Signal creation timestamp in milliseconds
|
|
24699
|
+
* @param pendingAt - Pending timestamp in milliseconds
|
|
24700
|
+
*/
|
|
24701
|
+
this.trailingStop = async (symbol, percentShift, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
|
|
24530
24702
|
this.loggerService.log("strategyMarkdownService trailingStop", {
|
|
24531
24703
|
symbol,
|
|
24532
24704
|
percentShift,
|
|
@@ -24558,6 +24730,14 @@ class StrategyMarkdownService {
|
|
|
24558
24730
|
currentPrice,
|
|
24559
24731
|
createdAt,
|
|
24560
24732
|
backtest: isBacktest,
|
|
24733
|
+
position,
|
|
24734
|
+
priceOpen,
|
|
24735
|
+
priceTakeProfit,
|
|
24736
|
+
priceStopLoss,
|
|
24737
|
+
originalPriceTakeProfit,
|
|
24738
|
+
originalPriceStopLoss,
|
|
24739
|
+
scheduledAt,
|
|
24740
|
+
pendingAt,
|
|
24561
24741
|
});
|
|
24562
24742
|
};
|
|
24563
24743
|
/**
|
|
@@ -24569,8 +24749,16 @@ class StrategyMarkdownService {
|
|
|
24569
24749
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
24570
24750
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
24571
24751
|
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
24572
|
-
|
|
24573
|
-
|
|
24752
|
+
* @param position - Trade direction: "long" or "short"
|
|
24753
|
+
* @param priceOpen - Entry price for the position
|
|
24754
|
+
* @param priceTakeProfit - Effective take profit price
|
|
24755
|
+
* @param priceStopLoss - Effective stop loss price
|
|
24756
|
+
* @param originalPriceTakeProfit - Original take profit before trailing
|
|
24757
|
+
* @param originalPriceStopLoss - Original stop loss before trailing
|
|
24758
|
+
* @param scheduledAt - Signal creation timestamp in milliseconds
|
|
24759
|
+
* @param pendingAt - Pending timestamp in milliseconds
|
|
24760
|
+
*/
|
|
24761
|
+
this.trailingTake = async (symbol, percentShift, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
|
|
24574
24762
|
this.loggerService.log("strategyMarkdownService trailingTake", {
|
|
24575
24763
|
symbol,
|
|
24576
24764
|
percentShift,
|
|
@@ -24602,6 +24790,14 @@ class StrategyMarkdownService {
|
|
|
24602
24790
|
currentPrice,
|
|
24603
24791
|
createdAt,
|
|
24604
24792
|
backtest: isBacktest,
|
|
24793
|
+
position,
|
|
24794
|
+
priceOpen,
|
|
24795
|
+
priceTakeProfit,
|
|
24796
|
+
priceStopLoss,
|
|
24797
|
+
originalPriceTakeProfit,
|
|
24798
|
+
originalPriceStopLoss,
|
|
24799
|
+
scheduledAt,
|
|
24800
|
+
pendingAt,
|
|
24605
24801
|
});
|
|
24606
24802
|
};
|
|
24607
24803
|
/**
|
|
@@ -24612,8 +24808,16 @@ class StrategyMarkdownService {
|
|
|
24612
24808
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
24613
24809
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
24614
24810
|
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
24615
|
-
|
|
24616
|
-
|
|
24811
|
+
* @param position - Trade direction: "long" or "short"
|
|
24812
|
+
* @param priceOpen - Entry price for the position
|
|
24813
|
+
* @param priceTakeProfit - Effective take profit price
|
|
24814
|
+
* @param priceStopLoss - Effective stop loss price
|
|
24815
|
+
* @param originalPriceTakeProfit - Original take profit before trailing
|
|
24816
|
+
* @param originalPriceStopLoss - Original stop loss before trailing
|
|
24817
|
+
* @param scheduledAt - Signal creation timestamp in milliseconds
|
|
24818
|
+
* @param pendingAt - Pending timestamp in milliseconds
|
|
24819
|
+
*/
|
|
24820
|
+
this.breakeven = async (symbol, currentPrice, isBacktest, context, timestamp, position, priceOpen, priceTakeProfit, priceStopLoss, originalPriceTakeProfit, originalPriceStopLoss, scheduledAt, pendingAt) => {
|
|
24617
24821
|
this.loggerService.log("strategyMarkdownService breakeven", {
|
|
24618
24822
|
symbol,
|
|
24619
24823
|
currentPrice,
|
|
@@ -24643,6 +24847,14 @@ class StrategyMarkdownService {
|
|
|
24643
24847
|
currentPrice,
|
|
24644
24848
|
createdAt,
|
|
24645
24849
|
backtest: isBacktest,
|
|
24850
|
+
position,
|
|
24851
|
+
priceOpen,
|
|
24852
|
+
priceTakeProfit,
|
|
24853
|
+
priceStopLoss,
|
|
24854
|
+
originalPriceTakeProfit,
|
|
24855
|
+
originalPriceStopLoss,
|
|
24856
|
+
scheduledAt,
|
|
24857
|
+
pendingAt,
|
|
24646
24858
|
});
|
|
24647
24859
|
};
|
|
24648
24860
|
/**
|
|
@@ -24789,35 +25001,35 @@ class StrategyMarkdownService {
|
|
|
24789
25001
|
exchangeName: event.exchangeName,
|
|
24790
25002
|
frameName: event.frameName,
|
|
24791
25003
|
strategyName: event.strategyName,
|
|
24792
|
-
}, event.timestamp));
|
|
25004
|
+
}, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
|
|
24793
25005
|
const unPartialLoss = strategyCommitSubject
|
|
24794
25006
|
.filter(({ action }) => action === "partial-loss")
|
|
24795
25007
|
.connect(async (event) => await this.partialLoss(event.symbol, event.percentToClose, event.currentPrice, event.backtest, {
|
|
24796
25008
|
exchangeName: event.exchangeName,
|
|
24797
25009
|
frameName: event.frameName,
|
|
24798
25010
|
strategyName: event.strategyName,
|
|
24799
|
-
}, event.timestamp));
|
|
25011
|
+
}, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
|
|
24800
25012
|
const unTrailingStop = strategyCommitSubject
|
|
24801
25013
|
.filter(({ action }) => action === "trailing-stop")
|
|
24802
25014
|
.connect(async (event) => await this.trailingStop(event.symbol, event.percentShift, event.currentPrice, event.backtest, {
|
|
24803
25015
|
exchangeName: event.exchangeName,
|
|
24804
25016
|
frameName: event.frameName,
|
|
24805
25017
|
strategyName: event.strategyName,
|
|
24806
|
-
}, event.timestamp));
|
|
25018
|
+
}, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
|
|
24807
25019
|
const unTrailingTake = strategyCommitSubject
|
|
24808
25020
|
.filter(({ action }) => action === "trailing-take")
|
|
24809
25021
|
.connect(async (event) => await this.trailingTake(event.symbol, event.percentShift, event.currentPrice, event.backtest, {
|
|
24810
25022
|
exchangeName: event.exchangeName,
|
|
24811
25023
|
frameName: event.frameName,
|
|
24812
25024
|
strategyName: event.strategyName,
|
|
24813
|
-
}, event.timestamp));
|
|
25025
|
+
}, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
|
|
24814
25026
|
const unBreakeven = strategyCommitSubject
|
|
24815
25027
|
.filter(({ action }) => action === "breakeven")
|
|
24816
25028
|
.connect(async (event) => await this.breakeven(event.symbol, event.currentPrice, event.backtest, {
|
|
24817
25029
|
exchangeName: event.exchangeName,
|
|
24818
25030
|
frameName: event.frameName,
|
|
24819
25031
|
strategyName: event.strategyName,
|
|
24820
|
-
}, event.timestamp));
|
|
25032
|
+
}, event.timestamp, event.position, event.priceOpen, event.priceTakeProfit, event.priceStopLoss, event.originalPriceTakeProfit, event.originalPriceStopLoss, event.scheduledAt, event.pendingAt));
|
|
24821
25033
|
const disposeFn = functoolsKit.compose(() => unCancelSchedule(), () => unClosePending(), () => unPartialProfit(), () => unPartialLoss(), () => unTrailingStop(), () => unTrailingTake(), () => unBreakeven());
|
|
24822
25034
|
return () => {
|
|
24823
25035
|
disposeFn();
|
|
@@ -33729,6 +33941,12 @@ class NotificationInstance {
|
|
|
33729
33941
|
currentPrice: data.currentPrice,
|
|
33730
33942
|
priceOpen: data.data.priceOpen,
|
|
33731
33943
|
position: data.data.position,
|
|
33944
|
+
priceTakeProfit: data.data.priceTakeProfit,
|
|
33945
|
+
priceStopLoss: data.data.priceStopLoss,
|
|
33946
|
+
originalPriceTakeProfit: data.data.originalPriceTakeProfit,
|
|
33947
|
+
originalPriceStopLoss: data.data.originalPriceStopLoss,
|
|
33948
|
+
scheduledAt: data.data.scheduledAt,
|
|
33949
|
+
pendingAt: data.data.pendingAt,
|
|
33732
33950
|
createdAt: data.timestamp,
|
|
33733
33951
|
});
|
|
33734
33952
|
};
|
|
@@ -33749,6 +33967,12 @@ class NotificationInstance {
|
|
|
33749
33967
|
currentPrice: data.currentPrice,
|
|
33750
33968
|
priceOpen: data.data.priceOpen,
|
|
33751
33969
|
position: data.data.position,
|
|
33970
|
+
priceTakeProfit: data.data.priceTakeProfit,
|
|
33971
|
+
priceStopLoss: data.data.priceStopLoss,
|
|
33972
|
+
originalPriceTakeProfit: data.data.originalPriceTakeProfit,
|
|
33973
|
+
originalPriceStopLoss: data.data.originalPriceStopLoss,
|
|
33974
|
+
scheduledAt: data.data.scheduledAt,
|
|
33975
|
+
pendingAt: data.data.pendingAt,
|
|
33752
33976
|
createdAt: data.timestamp,
|
|
33753
33977
|
});
|
|
33754
33978
|
};
|
|
@@ -33768,6 +33992,12 @@ class NotificationInstance {
|
|
|
33768
33992
|
currentPrice: data.currentPrice,
|
|
33769
33993
|
priceOpen: data.data.priceOpen,
|
|
33770
33994
|
position: data.data.position,
|
|
33995
|
+
priceTakeProfit: data.data.priceTakeProfit,
|
|
33996
|
+
priceStopLoss: data.data.priceStopLoss,
|
|
33997
|
+
originalPriceTakeProfit: data.data.originalPriceTakeProfit,
|
|
33998
|
+
originalPriceStopLoss: data.data.originalPriceStopLoss,
|
|
33999
|
+
scheduledAt: data.data.scheduledAt,
|
|
34000
|
+
pendingAt: data.data.pendingAt,
|
|
33771
34001
|
createdAt: data.timestamp,
|
|
33772
34002
|
});
|
|
33773
34003
|
};
|
|
@@ -33786,6 +34016,14 @@ class NotificationInstance {
|
|
|
33786
34016
|
exchangeName: data.exchangeName,
|
|
33787
34017
|
percentToClose: data.percentToClose,
|
|
33788
34018
|
currentPrice: data.currentPrice,
|
|
34019
|
+
position: data.position,
|
|
34020
|
+
priceOpen: data.priceOpen,
|
|
34021
|
+
priceTakeProfit: data.priceTakeProfit,
|
|
34022
|
+
priceStopLoss: data.priceStopLoss,
|
|
34023
|
+
originalPriceTakeProfit: data.originalPriceTakeProfit,
|
|
34024
|
+
originalPriceStopLoss: data.originalPriceStopLoss,
|
|
34025
|
+
scheduledAt: data.scheduledAt,
|
|
34026
|
+
pendingAt: data.pendingAt,
|
|
33789
34027
|
createdAt: data.timestamp,
|
|
33790
34028
|
});
|
|
33791
34029
|
}
|
|
@@ -33800,6 +34038,14 @@ class NotificationInstance {
|
|
|
33800
34038
|
exchangeName: data.exchangeName,
|
|
33801
34039
|
percentToClose: data.percentToClose,
|
|
33802
34040
|
currentPrice: data.currentPrice,
|
|
34041
|
+
position: data.position,
|
|
34042
|
+
priceOpen: data.priceOpen,
|
|
34043
|
+
priceTakeProfit: data.priceTakeProfit,
|
|
34044
|
+
priceStopLoss: data.priceStopLoss,
|
|
34045
|
+
originalPriceTakeProfit: data.originalPriceTakeProfit,
|
|
34046
|
+
originalPriceStopLoss: data.originalPriceStopLoss,
|
|
34047
|
+
scheduledAt: data.scheduledAt,
|
|
34048
|
+
pendingAt: data.pendingAt,
|
|
33803
34049
|
createdAt: data.timestamp,
|
|
33804
34050
|
});
|
|
33805
34051
|
}
|
|
@@ -33813,6 +34059,14 @@ class NotificationInstance {
|
|
|
33813
34059
|
strategyName: data.strategyName,
|
|
33814
34060
|
exchangeName: data.exchangeName,
|
|
33815
34061
|
currentPrice: data.currentPrice,
|
|
34062
|
+
position: data.position,
|
|
34063
|
+
priceOpen: data.priceOpen,
|
|
34064
|
+
priceTakeProfit: data.priceTakeProfit,
|
|
34065
|
+
priceStopLoss: data.priceStopLoss,
|
|
34066
|
+
originalPriceTakeProfit: data.originalPriceTakeProfit,
|
|
34067
|
+
originalPriceStopLoss: data.originalPriceStopLoss,
|
|
34068
|
+
scheduledAt: data.scheduledAt,
|
|
34069
|
+
pendingAt: data.pendingAt,
|
|
33816
34070
|
createdAt: data.timestamp,
|
|
33817
34071
|
});
|
|
33818
34072
|
}
|
|
@@ -33827,6 +34081,14 @@ class NotificationInstance {
|
|
|
33827
34081
|
exchangeName: data.exchangeName,
|
|
33828
34082
|
percentShift: data.percentShift,
|
|
33829
34083
|
currentPrice: data.currentPrice,
|
|
34084
|
+
position: data.position,
|
|
34085
|
+
priceOpen: data.priceOpen,
|
|
34086
|
+
priceTakeProfit: data.priceTakeProfit,
|
|
34087
|
+
priceStopLoss: data.priceStopLoss,
|
|
34088
|
+
originalPriceTakeProfit: data.originalPriceTakeProfit,
|
|
34089
|
+
originalPriceStopLoss: data.originalPriceStopLoss,
|
|
34090
|
+
scheduledAt: data.scheduledAt,
|
|
34091
|
+
pendingAt: data.pendingAt,
|
|
33830
34092
|
createdAt: data.timestamp,
|
|
33831
34093
|
});
|
|
33832
34094
|
}
|
|
@@ -33841,6 +34103,14 @@ class NotificationInstance {
|
|
|
33841
34103
|
exchangeName: data.exchangeName,
|
|
33842
34104
|
percentShift: data.percentShift,
|
|
33843
34105
|
currentPrice: data.currentPrice,
|
|
34106
|
+
position: data.position,
|
|
34107
|
+
priceOpen: data.priceOpen,
|
|
34108
|
+
priceTakeProfit: data.priceTakeProfit,
|
|
34109
|
+
priceStopLoss: data.priceStopLoss,
|
|
34110
|
+
originalPriceTakeProfit: data.originalPriceTakeProfit,
|
|
34111
|
+
originalPriceStopLoss: data.originalPriceStopLoss,
|
|
34112
|
+
scheduledAt: data.scheduledAt,
|
|
34113
|
+
pendingAt: data.pendingAt,
|
|
33844
34114
|
createdAt: data.timestamp,
|
|
33845
34115
|
});
|
|
33846
34116
|
}
|