backtest-kit 2.2.19 → 2.2.20
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 +37 -31
- package/build/index.mjs +37 -31
- package/package.json +1 -1
- package/types.d.ts +19 -7
package/build/index.cjs
CHANGED
|
@@ -4383,7 +4383,7 @@ const CALL_PARTIAL_CLEAR_FN = functoolsKit.trycatch(beginTime(async (self, symbo
|
|
|
4383
4383
|
const CALL_RISK_CHECK_SIGNAL_FN = functoolsKit.trycatch(beginTime(async (self, symbol, pendingSignal, currentPrice, timestamp, backtest) => {
|
|
4384
4384
|
return await ExecutionContextService.runInContext(async () => {
|
|
4385
4385
|
return await self.params.risk.checkSignal({
|
|
4386
|
-
|
|
4386
|
+
currentSignal: TO_PUBLIC_SIGNAL(pendingSignal),
|
|
4387
4387
|
symbol: symbol,
|
|
4388
4388
|
strategyName: self.params.method.context.strategyName,
|
|
4389
4389
|
exchangeName: self.params.method.context.exchangeName,
|
|
@@ -8292,7 +8292,7 @@ class ClientRisk {
|
|
|
8292
8292
|
const riskMap = this._activePositions;
|
|
8293
8293
|
const payload = {
|
|
8294
8294
|
...params,
|
|
8295
|
-
|
|
8295
|
+
currentSignal: TO_RISK_SIGNAL(params.currentSignal, params.currentPrice),
|
|
8296
8296
|
activePositionCount: riskMap.size,
|
|
8297
8297
|
activePositions: Array.from(riskMap.values()),
|
|
8298
8298
|
};
|
|
@@ -8428,7 +8428,7 @@ const CREATE_KEY_FN$k = (riskName, exchangeName, frameName, backtest) => {
|
|
|
8428
8428
|
const CREATE_COMMIT_REJECTION_FN = (self, exchangeName, frameName) => functoolsKit.trycatch(async (symbol, params, activePositionCount, rejectionResult, timestamp, backtest) => {
|
|
8429
8429
|
const event = {
|
|
8430
8430
|
symbol,
|
|
8431
|
-
|
|
8431
|
+
currentSignal: params.currentSignal,
|
|
8432
8432
|
strategyName: params.strategyName,
|
|
8433
8433
|
exchangeName,
|
|
8434
8434
|
currentPrice: params.currentPrice,
|
|
@@ -14261,19 +14261,19 @@ const risk_columns = [
|
|
|
14261
14261
|
{
|
|
14262
14262
|
key: "signalId",
|
|
14263
14263
|
label: "Signal ID",
|
|
14264
|
-
format: (data) => data.
|
|
14264
|
+
format: (data) => data.currentSignal.id || "N/A",
|
|
14265
14265
|
isVisible: () => true,
|
|
14266
14266
|
},
|
|
14267
14267
|
{
|
|
14268
14268
|
key: "note",
|
|
14269
14269
|
label: "Note",
|
|
14270
|
-
format: (data) => toPlainString(data.
|
|
14270
|
+
format: (data) => toPlainString(data.currentSignal.note ?? "N/A"),
|
|
14271
14271
|
isVisible: () => GLOBAL_CONFIG.CC_REPORT_SHOW_SIGNAL_NOTE,
|
|
14272
14272
|
},
|
|
14273
14273
|
{
|
|
14274
14274
|
key: "position",
|
|
14275
14275
|
label: "Position",
|
|
14276
|
-
format: (data) => data.
|
|
14276
|
+
format: (data) => data.currentSignal.position.toUpperCase(),
|
|
14277
14277
|
isVisible: () => true,
|
|
14278
14278
|
},
|
|
14279
14279
|
{
|
|
@@ -14285,48 +14285,48 @@ const risk_columns = [
|
|
|
14285
14285
|
{
|
|
14286
14286
|
key: "openPrice",
|
|
14287
14287
|
label: "Open Price",
|
|
14288
|
-
format: (data) => data.
|
|
14289
|
-
? `${data.
|
|
14288
|
+
format: (data) => data.currentSignal.priceOpen !== undefined
|
|
14289
|
+
? `${data.currentSignal.priceOpen.toFixed(8)} USD`
|
|
14290
14290
|
: "N/A",
|
|
14291
14291
|
isVisible: () => true,
|
|
14292
14292
|
},
|
|
14293
14293
|
{
|
|
14294
14294
|
key: "takeProfit",
|
|
14295
14295
|
label: "Take Profit",
|
|
14296
|
-
format: (data) => data.
|
|
14297
|
-
? `${data.
|
|
14296
|
+
format: (data) => data.currentSignal.priceTakeProfit !== undefined
|
|
14297
|
+
? `${data.currentSignal.priceTakeProfit.toFixed(8)} USD`
|
|
14298
14298
|
: "N/A",
|
|
14299
14299
|
isVisible: () => true,
|
|
14300
14300
|
},
|
|
14301
14301
|
{
|
|
14302
14302
|
key: "stopLoss",
|
|
14303
14303
|
label: "Stop Loss",
|
|
14304
|
-
format: (data) => data.
|
|
14305
|
-
? `${data.
|
|
14304
|
+
format: (data) => data.currentSignal.priceStopLoss !== undefined
|
|
14305
|
+
? `${data.currentSignal.priceStopLoss.toFixed(8)} USD`
|
|
14306
14306
|
: "N/A",
|
|
14307
14307
|
isVisible: () => true,
|
|
14308
14308
|
},
|
|
14309
14309
|
{
|
|
14310
14310
|
key: "originalPriceTakeProfit",
|
|
14311
14311
|
label: "Original TP",
|
|
14312
|
-
format: (data) => data.
|
|
14313
|
-
? `${data.
|
|
14312
|
+
format: (data) => data.currentSignal.originalPriceTakeProfit !== undefined
|
|
14313
|
+
? `${data.currentSignal.originalPriceTakeProfit.toFixed(8)} USD`
|
|
14314
14314
|
: "N/A",
|
|
14315
14315
|
isVisible: () => true,
|
|
14316
14316
|
},
|
|
14317
14317
|
{
|
|
14318
14318
|
key: "originalPriceStopLoss",
|
|
14319
14319
|
label: "Original SL",
|
|
14320
|
-
format: (data) => data.
|
|
14321
|
-
? `${data.
|
|
14320
|
+
format: (data) => data.currentSignal.originalPriceStopLoss !== undefined
|
|
14321
|
+
? `${data.currentSignal.originalPriceStopLoss.toFixed(8)} USD`
|
|
14322
14322
|
: "N/A",
|
|
14323
14323
|
isVisible: () => true,
|
|
14324
14324
|
},
|
|
14325
14325
|
{
|
|
14326
14326
|
key: "partialExecuted",
|
|
14327
14327
|
label: "Partial Executed %",
|
|
14328
|
-
format: (data) => data.
|
|
14329
|
-
? `${data.
|
|
14328
|
+
format: (data) => data.currentSignal.partialExecuted !== undefined
|
|
14329
|
+
? `${data.currentSignal.partialExecuted.toFixed(1)}%`
|
|
14330
14330
|
: "N/A",
|
|
14331
14331
|
isVisible: () => true,
|
|
14332
14332
|
},
|
|
@@ -23667,23 +23667,23 @@ class RiskReportService {
|
|
|
23667
23667
|
activePositionCount: data.activePositionCount,
|
|
23668
23668
|
rejectionId: data.rejectionId,
|
|
23669
23669
|
rejectionNote: data.rejectionNote,
|
|
23670
|
-
|
|
23671
|
-
signalId: data.
|
|
23672
|
-
position: data.
|
|
23673
|
-
priceOpen: data.
|
|
23674
|
-
priceTakeProfit: data.
|
|
23675
|
-
priceStopLoss: data.
|
|
23676
|
-
originalPriceTakeProfit: data.
|
|
23677
|
-
originalPriceStopLoss: data.
|
|
23678
|
-
partialExecuted: data.
|
|
23679
|
-
note: data.
|
|
23680
|
-
minuteEstimatedTime: data.
|
|
23670
|
+
currentSignal: data.currentSignal,
|
|
23671
|
+
signalId: data.currentSignal?.id,
|
|
23672
|
+
position: data.currentSignal?.position,
|
|
23673
|
+
priceOpen: data.currentSignal?.priceOpen,
|
|
23674
|
+
priceTakeProfit: data.currentSignal?.priceTakeProfit,
|
|
23675
|
+
priceStopLoss: data.currentSignal?.priceStopLoss,
|
|
23676
|
+
originalPriceTakeProfit: data.currentSignal?.originalPriceTakeProfit,
|
|
23677
|
+
originalPriceStopLoss: data.currentSignal?.originalPriceStopLoss,
|
|
23678
|
+
partialExecuted: data.currentSignal?.partialExecuted,
|
|
23679
|
+
note: data.currentSignal?.note,
|
|
23680
|
+
minuteEstimatedTime: data.currentSignal?.minuteEstimatedTime,
|
|
23681
23681
|
}, {
|
|
23682
23682
|
symbol: data.symbol,
|
|
23683
23683
|
strategyName: data.strategyName,
|
|
23684
23684
|
exchangeName: data.exchangeName,
|
|
23685
23685
|
frameName: data.frameName,
|
|
23686
|
-
signalId: data.
|
|
23686
|
+
signalId: data.currentSignal?.id || "",
|
|
23687
23687
|
walkerName: "",
|
|
23688
23688
|
});
|
|
23689
23689
|
};
|
|
@@ -34131,7 +34131,13 @@ class NotificationInstance {
|
|
|
34131
34131
|
rejectionId: data.rejectionId,
|
|
34132
34132
|
activePositionCount: data.activePositionCount,
|
|
34133
34133
|
currentPrice: data.currentPrice,
|
|
34134
|
-
|
|
34134
|
+
signalId: data.currentSignal.id,
|
|
34135
|
+
position: data.currentSignal.position,
|
|
34136
|
+
priceOpen: data.currentSignal.priceOpen,
|
|
34137
|
+
priceTakeProfit: data.currentSignal.priceTakeProfit,
|
|
34138
|
+
priceStopLoss: data.currentSignal.priceStopLoss,
|
|
34139
|
+
minuteEstimatedTime: data.currentSignal.minuteEstimatedTime,
|
|
34140
|
+
signalNote: data.currentSignal.note,
|
|
34135
34141
|
createdAt: data.timestamp,
|
|
34136
34142
|
});
|
|
34137
34143
|
};
|
package/build/index.mjs
CHANGED
|
@@ -4363,7 +4363,7 @@ const CALL_PARTIAL_CLEAR_FN = trycatch(beginTime(async (self, symbol, signal, cu
|
|
|
4363
4363
|
const CALL_RISK_CHECK_SIGNAL_FN = trycatch(beginTime(async (self, symbol, pendingSignal, currentPrice, timestamp, backtest) => {
|
|
4364
4364
|
return await ExecutionContextService.runInContext(async () => {
|
|
4365
4365
|
return await self.params.risk.checkSignal({
|
|
4366
|
-
|
|
4366
|
+
currentSignal: TO_PUBLIC_SIGNAL(pendingSignal),
|
|
4367
4367
|
symbol: symbol,
|
|
4368
4368
|
strategyName: self.params.method.context.strategyName,
|
|
4369
4369
|
exchangeName: self.params.method.context.exchangeName,
|
|
@@ -8272,7 +8272,7 @@ class ClientRisk {
|
|
|
8272
8272
|
const riskMap = this._activePositions;
|
|
8273
8273
|
const payload = {
|
|
8274
8274
|
...params,
|
|
8275
|
-
|
|
8275
|
+
currentSignal: TO_RISK_SIGNAL(params.currentSignal, params.currentPrice),
|
|
8276
8276
|
activePositionCount: riskMap.size,
|
|
8277
8277
|
activePositions: Array.from(riskMap.values()),
|
|
8278
8278
|
};
|
|
@@ -8408,7 +8408,7 @@ const CREATE_KEY_FN$k = (riskName, exchangeName, frameName, backtest) => {
|
|
|
8408
8408
|
const CREATE_COMMIT_REJECTION_FN = (self, exchangeName, frameName) => trycatch(async (symbol, params, activePositionCount, rejectionResult, timestamp, backtest) => {
|
|
8409
8409
|
const event = {
|
|
8410
8410
|
symbol,
|
|
8411
|
-
|
|
8411
|
+
currentSignal: params.currentSignal,
|
|
8412
8412
|
strategyName: params.strategyName,
|
|
8413
8413
|
exchangeName,
|
|
8414
8414
|
currentPrice: params.currentPrice,
|
|
@@ -14241,19 +14241,19 @@ const risk_columns = [
|
|
|
14241
14241
|
{
|
|
14242
14242
|
key: "signalId",
|
|
14243
14243
|
label: "Signal ID",
|
|
14244
|
-
format: (data) => data.
|
|
14244
|
+
format: (data) => data.currentSignal.id || "N/A",
|
|
14245
14245
|
isVisible: () => true,
|
|
14246
14246
|
},
|
|
14247
14247
|
{
|
|
14248
14248
|
key: "note",
|
|
14249
14249
|
label: "Note",
|
|
14250
|
-
format: (data) => toPlainString(data.
|
|
14250
|
+
format: (data) => toPlainString(data.currentSignal.note ?? "N/A"),
|
|
14251
14251
|
isVisible: () => GLOBAL_CONFIG.CC_REPORT_SHOW_SIGNAL_NOTE,
|
|
14252
14252
|
},
|
|
14253
14253
|
{
|
|
14254
14254
|
key: "position",
|
|
14255
14255
|
label: "Position",
|
|
14256
|
-
format: (data) => data.
|
|
14256
|
+
format: (data) => data.currentSignal.position.toUpperCase(),
|
|
14257
14257
|
isVisible: () => true,
|
|
14258
14258
|
},
|
|
14259
14259
|
{
|
|
@@ -14265,48 +14265,48 @@ const risk_columns = [
|
|
|
14265
14265
|
{
|
|
14266
14266
|
key: "openPrice",
|
|
14267
14267
|
label: "Open Price",
|
|
14268
|
-
format: (data) => data.
|
|
14269
|
-
? `${data.
|
|
14268
|
+
format: (data) => data.currentSignal.priceOpen !== undefined
|
|
14269
|
+
? `${data.currentSignal.priceOpen.toFixed(8)} USD`
|
|
14270
14270
|
: "N/A",
|
|
14271
14271
|
isVisible: () => true,
|
|
14272
14272
|
},
|
|
14273
14273
|
{
|
|
14274
14274
|
key: "takeProfit",
|
|
14275
14275
|
label: "Take Profit",
|
|
14276
|
-
format: (data) => data.
|
|
14277
|
-
? `${data.
|
|
14276
|
+
format: (data) => data.currentSignal.priceTakeProfit !== undefined
|
|
14277
|
+
? `${data.currentSignal.priceTakeProfit.toFixed(8)} USD`
|
|
14278
14278
|
: "N/A",
|
|
14279
14279
|
isVisible: () => true,
|
|
14280
14280
|
},
|
|
14281
14281
|
{
|
|
14282
14282
|
key: "stopLoss",
|
|
14283
14283
|
label: "Stop Loss",
|
|
14284
|
-
format: (data) => data.
|
|
14285
|
-
? `${data.
|
|
14284
|
+
format: (data) => data.currentSignal.priceStopLoss !== undefined
|
|
14285
|
+
? `${data.currentSignal.priceStopLoss.toFixed(8)} USD`
|
|
14286
14286
|
: "N/A",
|
|
14287
14287
|
isVisible: () => true,
|
|
14288
14288
|
},
|
|
14289
14289
|
{
|
|
14290
14290
|
key: "originalPriceTakeProfit",
|
|
14291
14291
|
label: "Original TP",
|
|
14292
|
-
format: (data) => data.
|
|
14293
|
-
? `${data.
|
|
14292
|
+
format: (data) => data.currentSignal.originalPriceTakeProfit !== undefined
|
|
14293
|
+
? `${data.currentSignal.originalPriceTakeProfit.toFixed(8)} USD`
|
|
14294
14294
|
: "N/A",
|
|
14295
14295
|
isVisible: () => true,
|
|
14296
14296
|
},
|
|
14297
14297
|
{
|
|
14298
14298
|
key: "originalPriceStopLoss",
|
|
14299
14299
|
label: "Original SL",
|
|
14300
|
-
format: (data) => data.
|
|
14301
|
-
? `${data.
|
|
14300
|
+
format: (data) => data.currentSignal.originalPriceStopLoss !== undefined
|
|
14301
|
+
? `${data.currentSignal.originalPriceStopLoss.toFixed(8)} USD`
|
|
14302
14302
|
: "N/A",
|
|
14303
14303
|
isVisible: () => true,
|
|
14304
14304
|
},
|
|
14305
14305
|
{
|
|
14306
14306
|
key: "partialExecuted",
|
|
14307
14307
|
label: "Partial Executed %",
|
|
14308
|
-
format: (data) => data.
|
|
14309
|
-
? `${data.
|
|
14308
|
+
format: (data) => data.currentSignal.partialExecuted !== undefined
|
|
14309
|
+
? `${data.currentSignal.partialExecuted.toFixed(1)}%`
|
|
14310
14310
|
: "N/A",
|
|
14311
14311
|
isVisible: () => true,
|
|
14312
14312
|
},
|
|
@@ -23647,23 +23647,23 @@ class RiskReportService {
|
|
|
23647
23647
|
activePositionCount: data.activePositionCount,
|
|
23648
23648
|
rejectionId: data.rejectionId,
|
|
23649
23649
|
rejectionNote: data.rejectionNote,
|
|
23650
|
-
|
|
23651
|
-
signalId: data.
|
|
23652
|
-
position: data.
|
|
23653
|
-
priceOpen: data.
|
|
23654
|
-
priceTakeProfit: data.
|
|
23655
|
-
priceStopLoss: data.
|
|
23656
|
-
originalPriceTakeProfit: data.
|
|
23657
|
-
originalPriceStopLoss: data.
|
|
23658
|
-
partialExecuted: data.
|
|
23659
|
-
note: data.
|
|
23660
|
-
minuteEstimatedTime: data.
|
|
23650
|
+
currentSignal: data.currentSignal,
|
|
23651
|
+
signalId: data.currentSignal?.id,
|
|
23652
|
+
position: data.currentSignal?.position,
|
|
23653
|
+
priceOpen: data.currentSignal?.priceOpen,
|
|
23654
|
+
priceTakeProfit: data.currentSignal?.priceTakeProfit,
|
|
23655
|
+
priceStopLoss: data.currentSignal?.priceStopLoss,
|
|
23656
|
+
originalPriceTakeProfit: data.currentSignal?.originalPriceTakeProfit,
|
|
23657
|
+
originalPriceStopLoss: data.currentSignal?.originalPriceStopLoss,
|
|
23658
|
+
partialExecuted: data.currentSignal?.partialExecuted,
|
|
23659
|
+
note: data.currentSignal?.note,
|
|
23660
|
+
minuteEstimatedTime: data.currentSignal?.minuteEstimatedTime,
|
|
23661
23661
|
}, {
|
|
23662
23662
|
symbol: data.symbol,
|
|
23663
23663
|
strategyName: data.strategyName,
|
|
23664
23664
|
exchangeName: data.exchangeName,
|
|
23665
23665
|
frameName: data.frameName,
|
|
23666
|
-
signalId: data.
|
|
23666
|
+
signalId: data.currentSignal?.id || "",
|
|
23667
23667
|
walkerName: "",
|
|
23668
23668
|
});
|
|
23669
23669
|
};
|
|
@@ -34111,7 +34111,13 @@ class NotificationInstance {
|
|
|
34111
34111
|
rejectionId: data.rejectionId,
|
|
34112
34112
|
activePositionCount: data.activePositionCount,
|
|
34113
34113
|
currentPrice: data.currentPrice,
|
|
34114
|
-
|
|
34114
|
+
signalId: data.currentSignal.id,
|
|
34115
|
+
position: data.currentSignal.position,
|
|
34116
|
+
priceOpen: data.currentSignal.priceOpen,
|
|
34117
|
+
priceTakeProfit: data.currentSignal.priceTakeProfit,
|
|
34118
|
+
priceStopLoss: data.currentSignal.priceStopLoss,
|
|
34119
|
+
minuteEstimatedTime: data.currentSignal.minuteEstimatedTime,
|
|
34120
|
+
signalNote: data.currentSignal.note,
|
|
34115
34121
|
createdAt: data.timestamp,
|
|
34116
34122
|
});
|
|
34117
34123
|
};
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -559,7 +559,7 @@ interface IRiskCheckArgs {
|
|
|
559
559
|
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
560
560
|
symbol: string;
|
|
561
561
|
/** Pending signal to apply */
|
|
562
|
-
|
|
562
|
+
currentSignal: IPublicSignalRow;
|
|
563
563
|
/** Strategy name requesting to open a position */
|
|
564
564
|
strategyName: StrategyName;
|
|
565
565
|
/** Exchange name */
|
|
@@ -612,8 +612,8 @@ interface IRiskCallbacks {
|
|
|
612
612
|
* Extends IRiskCheckArgs with portfolio state data.
|
|
613
613
|
*/
|
|
614
614
|
interface IRiskValidationPayload extends IRiskCheckArgs {
|
|
615
|
-
/**
|
|
616
|
-
|
|
615
|
+
/** Current signal being validated (IRiskSignalRow is calculated internally so priceOpen always exist) */
|
|
616
|
+
currentSignal: IRiskSignalRow;
|
|
617
617
|
/** Number of currently active positions across all strategies */
|
|
618
618
|
activePositionCount: number;
|
|
619
619
|
/** List of currently active positions across all strategies */
|
|
@@ -2563,7 +2563,7 @@ interface RiskContract {
|
|
|
2563
2563
|
* Pending signal to apply.
|
|
2564
2564
|
* Contains signal details (position, priceOpen, priceTakeProfit, priceStopLoss, etc).
|
|
2565
2565
|
*/
|
|
2566
|
-
|
|
2566
|
+
currentSignal: ISignalDto;
|
|
2567
2567
|
/**
|
|
2568
2568
|
* Strategy name requesting to open a position.
|
|
2569
2569
|
* Identifies which strategy attempted to create the signal.
|
|
@@ -7040,8 +7040,20 @@ interface RiskRejectionNotification {
|
|
|
7040
7040
|
activePositionCount: number;
|
|
7041
7041
|
/** Current market price when rejection occurred */
|
|
7042
7042
|
currentPrice: number;
|
|
7043
|
-
/**
|
|
7044
|
-
|
|
7043
|
+
/** Unique signal identifier from pending signal (may be undefined if not provided) */
|
|
7044
|
+
signalId: string | undefined;
|
|
7045
|
+
/** Trade direction: "long" (buy) or "short" (sell) */
|
|
7046
|
+
position: "long" | "short";
|
|
7047
|
+
/** Entry price for the position (may be undefined if not provided) */
|
|
7048
|
+
priceOpen: number | undefined;
|
|
7049
|
+
/** Take profit target price */
|
|
7050
|
+
priceTakeProfit: number;
|
|
7051
|
+
/** Stop loss exit price */
|
|
7052
|
+
priceStopLoss: number;
|
|
7053
|
+
/** Expected duration in minutes before time_expired */
|
|
7054
|
+
minuteEstimatedTime: number;
|
|
7055
|
+
/** Optional human-readable description of signal reason */
|
|
7056
|
+
signalNote?: string;
|
|
7045
7057
|
/** Unix timestamp in milliseconds when the notification was created */
|
|
7046
7058
|
createdAt: number;
|
|
7047
7059
|
}
|
|
@@ -7547,7 +7559,7 @@ interface RiskEvent {
|
|
|
7547
7559
|
/** Trading pair symbol */
|
|
7548
7560
|
symbol: string;
|
|
7549
7561
|
/** Pending signal details */
|
|
7550
|
-
|
|
7562
|
+
currentSignal: IRiskSignalRow;
|
|
7551
7563
|
/** Strategy name */
|
|
7552
7564
|
strategyName: StrategyName;
|
|
7553
7565
|
/** Exchange name */
|