backtest-kit 2.2.14 → 2.2.16
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 +328 -259
- package/build/index.mjs +328 -259
- package/package.json +1 -1
- package/types.d.ts +163 -154
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -1003,6 +1003,86 @@ interface IBreakeven {
|
|
|
1003
1003
|
clear(symbol: string, data: IPublicSignalRow, priceClose: number, backtest: boolean): Promise<void>;
|
|
1004
1004
|
}
|
|
1005
1005
|
|
|
1006
|
+
/**
|
|
1007
|
+
* Base fields for all signal commit events.
|
|
1008
|
+
*/
|
|
1009
|
+
interface SignalCommitBase {
|
|
1010
|
+
symbol: string;
|
|
1011
|
+
strategyName: StrategyName;
|
|
1012
|
+
exchangeName: ExchangeName;
|
|
1013
|
+
frameName: FrameName;
|
|
1014
|
+
backtest: boolean;
|
|
1015
|
+
/** Timestamp from execution context (tick's when or backtest candle timestamp) */
|
|
1016
|
+
timestamp: number;
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Cancel scheduled signal event.
|
|
1020
|
+
*/
|
|
1021
|
+
interface CancelScheduledCommit extends SignalCommitBase {
|
|
1022
|
+
action: "cancel-scheduled";
|
|
1023
|
+
cancelId?: string;
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Close pending signal event.
|
|
1027
|
+
*/
|
|
1028
|
+
interface ClosePendingCommit extends SignalCommitBase {
|
|
1029
|
+
action: "close-pending";
|
|
1030
|
+
closeId?: string;
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Partial profit event.
|
|
1034
|
+
*/
|
|
1035
|
+
interface PartialProfitCommit extends SignalCommitBase {
|
|
1036
|
+
action: "partial-profit";
|
|
1037
|
+
percentToClose: number;
|
|
1038
|
+
currentPrice: number;
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* Partial loss event.
|
|
1042
|
+
*/
|
|
1043
|
+
interface PartialLossCommit extends SignalCommitBase {
|
|
1044
|
+
action: "partial-loss";
|
|
1045
|
+
percentToClose: number;
|
|
1046
|
+
currentPrice: number;
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Trailing stop event.
|
|
1050
|
+
*/
|
|
1051
|
+
interface TrailingStopCommit extends SignalCommitBase {
|
|
1052
|
+
action: "trailing-stop";
|
|
1053
|
+
percentShift: number;
|
|
1054
|
+
currentPrice: number;
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Trailing take event.
|
|
1058
|
+
*/
|
|
1059
|
+
interface TrailingTakeCommit extends SignalCommitBase {
|
|
1060
|
+
action: "trailing-take";
|
|
1061
|
+
percentShift: number;
|
|
1062
|
+
currentPrice: number;
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Breakeven event.
|
|
1066
|
+
*/
|
|
1067
|
+
interface BreakevenCommit extends SignalCommitBase {
|
|
1068
|
+
action: "breakeven";
|
|
1069
|
+
currentPrice: number;
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Discriminated union for strategy management signal events.
|
|
1073
|
+
*
|
|
1074
|
+
* Emitted by strategyCommitSubject when strategy management actions are executed.
|
|
1075
|
+
*
|
|
1076
|
+
* Consumers:
|
|
1077
|
+
* - StrategyReportService: Persists events to JSON files
|
|
1078
|
+
* - StrategyMarkdownService: Accumulates events for markdown reports
|
|
1079
|
+
*
|
|
1080
|
+
* Note: Signal data (IPublicSignalRow) is NOT included in this contract.
|
|
1081
|
+
* Consumers must retrieve signal data from StrategyCoreService using
|
|
1082
|
+
* getPendingSignal() or getScheduledSignal() methods.
|
|
1083
|
+
*/
|
|
1084
|
+
type StrategyCommitContract = CancelScheduledCommit | ClosePendingCommit | PartialProfitCommit | PartialLossCommit | TrailingStopCommit | TrailingTakeCommit | BreakevenCommit;
|
|
1085
|
+
|
|
1006
1086
|
/**
|
|
1007
1087
|
* Signal generation interval for throttling.
|
|
1008
1088
|
* Enforces minimum time between getSignal calls.
|
|
@@ -1131,19 +1211,53 @@ interface IPublicSignalRow extends ISignalRow {
|
|
|
1131
1211
|
partialExecuted: number;
|
|
1132
1212
|
}
|
|
1133
1213
|
/**
|
|
1134
|
-
*
|
|
1214
|
+
* Base storage signal row fields shared by all status variants.
|
|
1135
1215
|
* Used for persisting signals with accurate creation time.
|
|
1136
1216
|
*/
|
|
1137
|
-
interface
|
|
1217
|
+
interface IStorageSignalRowBase extends IPublicSignalRow {
|
|
1138
1218
|
/** Creation timestamp taken from IStrategyTickResult */
|
|
1139
1219
|
createdAt: number;
|
|
1140
1220
|
/** Creation timestamp taken from IStrategyTickResult */
|
|
1141
1221
|
updatedAt: number;
|
|
1142
1222
|
/** Storage adapter rewrite priority. Equal to Date.now for live and backtest both */
|
|
1143
1223
|
priority: number;
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Storage signal row for opened status.
|
|
1227
|
+
*/
|
|
1228
|
+
interface IStorageSignalRowOpened extends IStorageSignalRowBase {
|
|
1229
|
+
/** Current status of the signal */
|
|
1230
|
+
status: "opened";
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* Storage signal row for scheduled status.
|
|
1234
|
+
*/
|
|
1235
|
+
interface IStorageSignalRowScheduled extends IStorageSignalRowBase {
|
|
1236
|
+
/** Current status of the signal */
|
|
1237
|
+
status: "scheduled";
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* Storage signal row for closed status.
|
|
1241
|
+
* Only closed signals have PNL data.
|
|
1242
|
+
*/
|
|
1243
|
+
interface IStorageSignalRowClosed extends IStorageSignalRowBase {
|
|
1244
|
+
/** Current status of the signal */
|
|
1245
|
+
status: "closed";
|
|
1246
|
+
/** Profit and loss value for the signal when closed */
|
|
1247
|
+
pnl: IStrategyPnL;
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* Storage signal row for cancelled status.
|
|
1251
|
+
*/
|
|
1252
|
+
interface IStorageSignalRowCancelled extends IStorageSignalRowBase {
|
|
1144
1253
|
/** Current status of the signal */
|
|
1145
|
-
status: "
|
|
1254
|
+
status: "cancelled";
|
|
1146
1255
|
}
|
|
1256
|
+
/**
|
|
1257
|
+
* Discriminated union of storage signal rows.
|
|
1258
|
+
* Use type guards: `row.status === "closed"` for type-safe access to pnl.
|
|
1259
|
+
*/
|
|
1260
|
+
type IStorageSignalRow = IStorageSignalRowOpened | IStorageSignalRowScheduled | IStorageSignalRowClosed | IStorageSignalRowCancelled;
|
|
1147
1261
|
/**
|
|
1148
1262
|
* Risk signal row for internal risk management.
|
|
1149
1263
|
* Extends ISignalDto to include priceOpen, originalPriceStopLoss and originalPriceTakeProfit.
|
|
@@ -5103,84 +5217,6 @@ interface WalkerContract {
|
|
|
5103
5217
|
totalStrategies: number;
|
|
5104
5218
|
}
|
|
5105
5219
|
|
|
5106
|
-
/**
|
|
5107
|
-
* Base fields for all signal commit events.
|
|
5108
|
-
*/
|
|
5109
|
-
interface SignalCommitBase {
|
|
5110
|
-
symbol: string;
|
|
5111
|
-
strategyName: StrategyName;
|
|
5112
|
-
exchangeName: ExchangeName;
|
|
5113
|
-
frameName: FrameName;
|
|
5114
|
-
backtest: boolean;
|
|
5115
|
-
}
|
|
5116
|
-
/**
|
|
5117
|
-
* Cancel scheduled signal event.
|
|
5118
|
-
*/
|
|
5119
|
-
interface CancelScheduledCommit extends SignalCommitBase {
|
|
5120
|
-
action: "cancel-scheduled";
|
|
5121
|
-
cancelId?: string;
|
|
5122
|
-
}
|
|
5123
|
-
/**
|
|
5124
|
-
* Close pending signal event.
|
|
5125
|
-
*/
|
|
5126
|
-
interface ClosePendingCommit extends SignalCommitBase {
|
|
5127
|
-
action: "close-pending";
|
|
5128
|
-
closeId?: string;
|
|
5129
|
-
}
|
|
5130
|
-
/**
|
|
5131
|
-
* Partial profit event.
|
|
5132
|
-
*/
|
|
5133
|
-
interface PartialProfitCommit extends SignalCommitBase {
|
|
5134
|
-
action: "partial-profit";
|
|
5135
|
-
percentToClose: number;
|
|
5136
|
-
currentPrice: number;
|
|
5137
|
-
}
|
|
5138
|
-
/**
|
|
5139
|
-
* Partial loss event.
|
|
5140
|
-
*/
|
|
5141
|
-
interface PartialLossCommit extends SignalCommitBase {
|
|
5142
|
-
action: "partial-loss";
|
|
5143
|
-
percentToClose: number;
|
|
5144
|
-
currentPrice: number;
|
|
5145
|
-
}
|
|
5146
|
-
/**
|
|
5147
|
-
* Trailing stop event.
|
|
5148
|
-
*/
|
|
5149
|
-
interface TrailingStopCommit extends SignalCommitBase {
|
|
5150
|
-
action: "trailing-stop";
|
|
5151
|
-
percentShift: number;
|
|
5152
|
-
currentPrice: number;
|
|
5153
|
-
}
|
|
5154
|
-
/**
|
|
5155
|
-
* Trailing take event.
|
|
5156
|
-
*/
|
|
5157
|
-
interface TrailingTakeCommit extends SignalCommitBase {
|
|
5158
|
-
action: "trailing-take";
|
|
5159
|
-
percentShift: number;
|
|
5160
|
-
currentPrice: number;
|
|
5161
|
-
}
|
|
5162
|
-
/**
|
|
5163
|
-
* Breakeven event.
|
|
5164
|
-
*/
|
|
5165
|
-
interface BreakevenCommit extends SignalCommitBase {
|
|
5166
|
-
action: "breakeven";
|
|
5167
|
-
currentPrice: number;
|
|
5168
|
-
}
|
|
5169
|
-
/**
|
|
5170
|
-
* Discriminated union for strategy management signal events.
|
|
5171
|
-
*
|
|
5172
|
-
* Emitted by strategyCommitSubject when strategy management actions are executed.
|
|
5173
|
-
*
|
|
5174
|
-
* Consumers:
|
|
5175
|
-
* - StrategyReportService: Persists events to JSON files
|
|
5176
|
-
* - StrategyMarkdownService: Accumulates events for markdown reports
|
|
5177
|
-
*
|
|
5178
|
-
* Note: Signal data (IPublicSignalRow) is NOT included in this contract.
|
|
5179
|
-
* Consumers must retrieve signal data from StrategyCoreService using
|
|
5180
|
-
* getPendingSignal() or getScheduledSignal() methods.
|
|
5181
|
-
*/
|
|
5182
|
-
type StrategyCommitContract = CancelScheduledCommit | ClosePendingCommit | PartialProfitCommit | PartialLossCommit | TrailingStopCommit | TrailingTakeCommit | BreakevenCommit;
|
|
5183
|
-
|
|
5184
5220
|
/**
|
|
5185
5221
|
* Subscribes to all signal events with queued async processing.
|
|
5186
5222
|
*
|
|
@@ -6560,6 +6596,8 @@ interface PartialProfitAvailableNotification {
|
|
|
6560
6596
|
priceOpen: number;
|
|
6561
6597
|
/** Trade direction: "long" (buy) or "short" (sell) */
|
|
6562
6598
|
position: "long" | "short";
|
|
6599
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6600
|
+
createdAt: number;
|
|
6563
6601
|
}
|
|
6564
6602
|
/**
|
|
6565
6603
|
* Partial loss notification.
|
|
@@ -6590,6 +6628,8 @@ interface PartialLossAvailableNotification {
|
|
|
6590
6628
|
priceOpen: number;
|
|
6591
6629
|
/** Trade direction: "long" (buy) or "short" (sell) */
|
|
6592
6630
|
position: "long" | "short";
|
|
6631
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6632
|
+
createdAt: number;
|
|
6593
6633
|
}
|
|
6594
6634
|
/**
|
|
6595
6635
|
* Breakeven available notification.
|
|
@@ -6618,6 +6658,8 @@ interface BreakevenAvailableNotification {
|
|
|
6618
6658
|
priceOpen: number;
|
|
6619
6659
|
/** Trade direction: "long" (buy) or "short" (sell) */
|
|
6620
6660
|
position: "long" | "short";
|
|
6661
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6662
|
+
createdAt: number;
|
|
6621
6663
|
}
|
|
6622
6664
|
/**
|
|
6623
6665
|
* Partial profit commit notification.
|
|
@@ -6642,6 +6684,8 @@ interface PartialProfitCommitNotification {
|
|
|
6642
6684
|
percentToClose: number;
|
|
6643
6685
|
/** Current market price when partial was executed */
|
|
6644
6686
|
currentPrice: number;
|
|
6687
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6688
|
+
createdAt: number;
|
|
6645
6689
|
}
|
|
6646
6690
|
/**
|
|
6647
6691
|
* Partial loss commit notification.
|
|
@@ -6666,6 +6710,8 @@ interface PartialLossCommitNotification {
|
|
|
6666
6710
|
percentToClose: number;
|
|
6667
6711
|
/** Current market price when partial was executed */
|
|
6668
6712
|
currentPrice: number;
|
|
6713
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6714
|
+
createdAt: number;
|
|
6669
6715
|
}
|
|
6670
6716
|
/**
|
|
6671
6717
|
* Breakeven commit notification.
|
|
@@ -6688,6 +6734,8 @@ interface BreakevenCommitNotification {
|
|
|
6688
6734
|
exchangeName: ExchangeName;
|
|
6689
6735
|
/** Current market price when breakeven was executed */
|
|
6690
6736
|
currentPrice: number;
|
|
6737
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6738
|
+
createdAt: number;
|
|
6691
6739
|
}
|
|
6692
6740
|
/**
|
|
6693
6741
|
* Trailing stop commit notification.
|
|
@@ -6712,6 +6760,8 @@ interface TrailingStopCommitNotification {
|
|
|
6712
6760
|
percentShift: number;
|
|
6713
6761
|
/** Current market price when trailing stop was executed */
|
|
6714
6762
|
currentPrice: number;
|
|
6763
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6764
|
+
createdAt: number;
|
|
6715
6765
|
}
|
|
6716
6766
|
/**
|
|
6717
6767
|
* Trailing take commit notification.
|
|
@@ -6736,6 +6786,8 @@ interface TrailingTakeCommitNotification {
|
|
|
6736
6786
|
percentShift: number;
|
|
6737
6787
|
/** Current market price when trailing take was executed */
|
|
6738
6788
|
currentPrice: number;
|
|
6789
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6790
|
+
createdAt: number;
|
|
6739
6791
|
}
|
|
6740
6792
|
/**
|
|
6741
6793
|
* Risk rejection notification.
|
|
@@ -6766,6 +6818,8 @@ interface RiskRejectionNotification {
|
|
|
6766
6818
|
currentPrice: number;
|
|
6767
6819
|
/** The signal that was rejected */
|
|
6768
6820
|
pendingSignal: ISignalDto;
|
|
6821
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6822
|
+
createdAt: number;
|
|
6769
6823
|
}
|
|
6770
6824
|
/**
|
|
6771
6825
|
* Scheduled signal notification.
|
|
@@ -6844,8 +6898,6 @@ interface InfoErrorNotification {
|
|
|
6844
6898
|
error: object;
|
|
6845
6899
|
/** Human-readable error message */
|
|
6846
6900
|
message: string;
|
|
6847
|
-
/** Unix timestamp in milliseconds when error occurred */
|
|
6848
|
-
timestamp: number;
|
|
6849
6901
|
/** Always false for error notifications (errors are from live context) */
|
|
6850
6902
|
backtest: boolean;
|
|
6851
6903
|
}
|
|
@@ -6862,8 +6914,6 @@ interface CriticalErrorNotification {
|
|
|
6862
6914
|
error: object;
|
|
6863
6915
|
/** Human-readable error message */
|
|
6864
6916
|
message: string;
|
|
6865
|
-
/** Unix timestamp in milliseconds when critical error occurred */
|
|
6866
|
-
timestamp: number;
|
|
6867
6917
|
/** Always false for error notifications (errors are from live context) */
|
|
6868
6918
|
backtest: boolean;
|
|
6869
6919
|
}
|
|
@@ -6880,8 +6930,6 @@ interface ValidationErrorNotification {
|
|
|
6880
6930
|
error: object;
|
|
6881
6931
|
/** Human-readable validation error message */
|
|
6882
6932
|
message: string;
|
|
6883
|
-
/** Unix timestamp in milliseconds when validation error occurred */
|
|
6884
|
-
timestamp: number;
|
|
6885
6933
|
/** Always false for error notifications (errors are from live context) */
|
|
6886
6934
|
backtest: boolean;
|
|
6887
6935
|
}
|
|
@@ -13899,9 +13947,6 @@ type Columns = ColumnModel<StrategyEvent>;
|
|
|
13899
13947
|
*/
|
|
13900
13948
|
declare class StrategyMarkdownService {
|
|
13901
13949
|
readonly loggerService: LoggerService;
|
|
13902
|
-
readonly executionContextService: {
|
|
13903
|
-
readonly context: IExecutionContext;
|
|
13904
|
-
};
|
|
13905
13950
|
readonly strategyCoreService: StrategyCoreService;
|
|
13906
13951
|
/**
|
|
13907
13952
|
* Memoized factory for ReportStorage instances.
|
|
@@ -13915,114 +13960,105 @@ declare class StrategyMarkdownService {
|
|
|
13915
13960
|
/**
|
|
13916
13961
|
* Records a cancel-scheduled event when a scheduled signal is cancelled.
|
|
13917
13962
|
*
|
|
13918
|
-
* Retrieves the scheduled signal from StrategyCoreService and stores
|
|
13919
|
-
* the cancellation event in the appropriate ReportStorage.
|
|
13920
|
-
*
|
|
13921
13963
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13922
13964
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13923
13965
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13966
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
13924
13967
|
* @param cancelId - Optional identifier for the cancellation reason
|
|
13925
13968
|
*/
|
|
13926
13969
|
cancelScheduled: (symbol: string, isBacktest: boolean, context: {
|
|
13927
13970
|
strategyName: StrategyName;
|
|
13928
13971
|
exchangeName: ExchangeName;
|
|
13929
13972
|
frameName: FrameName;
|
|
13930
|
-
}, cancelId?: string) => Promise<void>;
|
|
13973
|
+
}, timestamp: number, cancelId?: string) => Promise<void>;
|
|
13931
13974
|
/**
|
|
13932
13975
|
* Records a close-pending event when a pending signal is closed.
|
|
13933
13976
|
*
|
|
13934
|
-
* Retrieves the pending signal from StrategyCoreService and stores
|
|
13935
|
-
* the close event in the appropriate ReportStorage.
|
|
13936
|
-
*
|
|
13937
13977
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13938
13978
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13939
13979
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13980
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
13940
13981
|
* @param closeId - Optional identifier for the close reason
|
|
13941
13982
|
*/
|
|
13942
13983
|
closePending: (symbol: string, isBacktest: boolean, context: {
|
|
13943
13984
|
strategyName: StrategyName;
|
|
13944
13985
|
exchangeName: ExchangeName;
|
|
13945
13986
|
frameName: FrameName;
|
|
13946
|
-
}, closeId?: string) => Promise<void>;
|
|
13987
|
+
}, timestamp: number, closeId?: string) => Promise<void>;
|
|
13947
13988
|
/**
|
|
13948
13989
|
* Records a partial-profit event when a portion of the position is closed at profit.
|
|
13949
13990
|
*
|
|
13950
|
-
* Stores the percentage closed and current price when partial profit-taking occurs.
|
|
13951
|
-
*
|
|
13952
13991
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13953
13992
|
* @param percentToClose - Percentage of position to close (0-100)
|
|
13954
13993
|
* @param currentPrice - Current market price at time of partial close
|
|
13955
13994
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13956
13995
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13996
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
13957
13997
|
*/
|
|
13958
13998
|
partialProfit: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
|
|
13959
13999
|
strategyName: StrategyName;
|
|
13960
14000
|
exchangeName: ExchangeName;
|
|
13961
14001
|
frameName: FrameName;
|
|
13962
|
-
}) => Promise<void>;
|
|
14002
|
+
}, timestamp: number) => Promise<void>;
|
|
13963
14003
|
/**
|
|
13964
14004
|
* Records a partial-loss event when a portion of the position is closed at loss.
|
|
13965
14005
|
*
|
|
13966
|
-
* Stores the percentage closed and current price when partial loss-cutting occurs.
|
|
13967
|
-
*
|
|
13968
14006
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13969
14007
|
* @param percentToClose - Percentage of position to close (0-100)
|
|
13970
14008
|
* @param currentPrice - Current market price at time of partial close
|
|
13971
14009
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13972
14010
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
14011
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
13973
14012
|
*/
|
|
13974
14013
|
partialLoss: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
|
|
13975
14014
|
strategyName: StrategyName;
|
|
13976
14015
|
exchangeName: ExchangeName;
|
|
13977
14016
|
frameName: FrameName;
|
|
13978
|
-
}) => Promise<void>;
|
|
14017
|
+
}, timestamp: number) => Promise<void>;
|
|
13979
14018
|
/**
|
|
13980
14019
|
* Records a trailing-stop event when the stop-loss is adjusted.
|
|
13981
14020
|
*
|
|
13982
|
-
* Stores the percentage shift and current price when trailing stop moves.
|
|
13983
|
-
*
|
|
13984
14021
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13985
14022
|
* @param percentShift - Percentage the stop-loss was shifted
|
|
13986
14023
|
* @param currentPrice - Current market price at time of adjustment
|
|
13987
14024
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13988
14025
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
14026
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
13989
14027
|
*/
|
|
13990
14028
|
trailingStop: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
|
|
13991
14029
|
strategyName: StrategyName;
|
|
13992
14030
|
exchangeName: ExchangeName;
|
|
13993
14031
|
frameName: FrameName;
|
|
13994
|
-
}) => Promise<void>;
|
|
14032
|
+
}, timestamp: number) => Promise<void>;
|
|
13995
14033
|
/**
|
|
13996
14034
|
* Records a trailing-take event when the take-profit is adjusted.
|
|
13997
14035
|
*
|
|
13998
|
-
* Stores the percentage shift and current price when trailing take-profit moves.
|
|
13999
|
-
*
|
|
14000
14036
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
14001
14037
|
* @param percentShift - Percentage the take-profit was shifted
|
|
14002
14038
|
* @param currentPrice - Current market price at time of adjustment
|
|
14003
14039
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
14004
14040
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
14041
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
14005
14042
|
*/
|
|
14006
14043
|
trailingTake: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
|
|
14007
14044
|
strategyName: StrategyName;
|
|
14008
14045
|
exchangeName: ExchangeName;
|
|
14009
14046
|
frameName: FrameName;
|
|
14010
|
-
}) => Promise<void>;
|
|
14047
|
+
}, timestamp: number) => Promise<void>;
|
|
14011
14048
|
/**
|
|
14012
14049
|
* Records a breakeven event when the stop-loss is moved to entry price.
|
|
14013
14050
|
*
|
|
14014
|
-
* Stores the current price when breakeven protection is activated.
|
|
14015
|
-
*
|
|
14016
14051
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
14017
14052
|
* @param currentPrice - Current market price at time of breakeven activation
|
|
14018
14053
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
14019
14054
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
14055
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
14020
14056
|
*/
|
|
14021
14057
|
breakeven: (symbol: string, currentPrice: number, isBacktest: boolean, context: {
|
|
14022
14058
|
strategyName: StrategyName;
|
|
14023
14059
|
exchangeName: ExchangeName;
|
|
14024
14060
|
frameName: FrameName;
|
|
14025
|
-
}) => Promise<void>;
|
|
14061
|
+
}, timestamp: number) => Promise<void>;
|
|
14026
14062
|
/**
|
|
14027
14063
|
* Retrieves aggregated statistics from accumulated strategy events.
|
|
14028
14064
|
*
|
|
@@ -19397,141 +19433,114 @@ declare class RiskReportService {
|
|
|
19397
19433
|
* - Events are written via Report.writeData() with "strategy" category
|
|
19398
19434
|
* - Call unsubscribe() to disable event logging
|
|
19399
19435
|
*
|
|
19400
|
-
* @example
|
|
19401
|
-
* ```typescript
|
|
19402
|
-
* // Service is typically used internally by strategy management classes
|
|
19403
|
-
* strategyReportService.subscribe();
|
|
19404
|
-
*
|
|
19405
|
-
* // Events are logged automatically when strategy actions occur
|
|
19406
|
-
* await strategyReportService.partialProfit("BTCUSDT", 50, 50100, false, {
|
|
19407
|
-
* strategyName: "my-strategy",
|
|
19408
|
-
* exchangeName: "binance",
|
|
19409
|
-
* frameName: "1h"
|
|
19410
|
-
* });
|
|
19411
|
-
*
|
|
19412
|
-
* strategyReportService.unsubscribe();
|
|
19413
|
-
* ```
|
|
19414
|
-
*
|
|
19415
19436
|
* @see StrategyMarkdownService for in-memory event accumulation and markdown report generation
|
|
19416
19437
|
* @see Report for the underlying persistence mechanism
|
|
19417
19438
|
*/
|
|
19418
19439
|
declare class StrategyReportService {
|
|
19419
19440
|
readonly loggerService: LoggerService;
|
|
19420
|
-
readonly executionContextService: {
|
|
19421
|
-
readonly context: IExecutionContext;
|
|
19422
|
-
};
|
|
19423
19441
|
readonly strategyCoreService: StrategyCoreService;
|
|
19424
19442
|
/**
|
|
19425
19443
|
* Logs a cancel-scheduled event when a scheduled signal is cancelled.
|
|
19426
19444
|
*
|
|
19427
|
-
* Retrieves the scheduled signal from StrategyCoreService and writes
|
|
19428
|
-
* the cancellation event to the report file.
|
|
19429
|
-
*
|
|
19430
19445
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19431
19446
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19432
19447
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19448
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
19433
19449
|
* @param cancelId - Optional identifier for the cancellation reason
|
|
19434
19450
|
*/
|
|
19435
19451
|
cancelScheduled: (symbol: string, isBacktest: boolean, context: {
|
|
19436
19452
|
strategyName: StrategyName;
|
|
19437
19453
|
exchangeName: ExchangeName;
|
|
19438
19454
|
frameName: FrameName;
|
|
19439
|
-
}, cancelId?: string) => Promise<void>;
|
|
19455
|
+
}, timestamp: number, cancelId?: string) => Promise<void>;
|
|
19440
19456
|
/**
|
|
19441
19457
|
* Logs a close-pending event when a pending signal is closed.
|
|
19442
19458
|
*
|
|
19443
|
-
* Retrieves the pending signal from StrategyCoreService and writes
|
|
19444
|
-
* the close event to the report file.
|
|
19445
|
-
*
|
|
19446
19459
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19447
19460
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19448
19461
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19462
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
19449
19463
|
* @param closeId - Optional identifier for the close reason
|
|
19450
19464
|
*/
|
|
19451
19465
|
closePending: (symbol: string, isBacktest: boolean, context: {
|
|
19452
19466
|
strategyName: StrategyName;
|
|
19453
19467
|
exchangeName: ExchangeName;
|
|
19454
19468
|
frameName: FrameName;
|
|
19455
|
-
}, closeId?: string) => Promise<void>;
|
|
19469
|
+
}, timestamp: number, closeId?: string) => Promise<void>;
|
|
19456
19470
|
/**
|
|
19457
19471
|
* Logs a partial-profit event when a portion of the position is closed at profit.
|
|
19458
19472
|
*
|
|
19459
|
-
* Records the percentage closed and current price when partial profit-taking occurs.
|
|
19460
|
-
*
|
|
19461
19473
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19462
19474
|
* @param percentToClose - Percentage of position to close (0-100)
|
|
19463
19475
|
* @param currentPrice - Current market price at time of partial close
|
|
19464
19476
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19465
19477
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19478
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
19466
19479
|
*/
|
|
19467
19480
|
partialProfit: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
|
|
19468
19481
|
strategyName: StrategyName;
|
|
19469
19482
|
exchangeName: ExchangeName;
|
|
19470
19483
|
frameName: FrameName;
|
|
19471
|
-
}) => Promise<void>;
|
|
19484
|
+
}, timestamp: number) => Promise<void>;
|
|
19472
19485
|
/**
|
|
19473
19486
|
* Logs a partial-loss event when a portion of the position is closed at loss.
|
|
19474
19487
|
*
|
|
19475
|
-
* Records the percentage closed and current price when partial loss-cutting occurs.
|
|
19476
|
-
*
|
|
19477
19488
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19478
19489
|
* @param percentToClose - Percentage of position to close (0-100)
|
|
19479
19490
|
* @param currentPrice - Current market price at time of partial close
|
|
19480
19491
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19481
19492
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19493
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
19482
19494
|
*/
|
|
19483
19495
|
partialLoss: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
|
|
19484
19496
|
strategyName: StrategyName;
|
|
19485
19497
|
exchangeName: ExchangeName;
|
|
19486
19498
|
frameName: FrameName;
|
|
19487
|
-
}) => Promise<void>;
|
|
19499
|
+
}, timestamp: number) => Promise<void>;
|
|
19488
19500
|
/**
|
|
19489
19501
|
* Logs a trailing-stop event when the stop-loss is adjusted.
|
|
19490
19502
|
*
|
|
19491
|
-
* Records the percentage shift and current price when trailing stop moves.
|
|
19492
|
-
*
|
|
19493
19503
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19494
19504
|
* @param percentShift - Percentage the stop-loss was shifted
|
|
19495
19505
|
* @param currentPrice - Current market price at time of adjustment
|
|
19496
19506
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19497
19507
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19508
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
19498
19509
|
*/
|
|
19499
19510
|
trailingStop: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
|
|
19500
19511
|
strategyName: StrategyName;
|
|
19501
19512
|
exchangeName: ExchangeName;
|
|
19502
19513
|
frameName: FrameName;
|
|
19503
|
-
}) => Promise<void>;
|
|
19514
|
+
}, timestamp: number) => Promise<void>;
|
|
19504
19515
|
/**
|
|
19505
19516
|
* Logs a trailing-take event when the take-profit is adjusted.
|
|
19506
19517
|
*
|
|
19507
|
-
* Records the percentage shift and current price when trailing take-profit moves.
|
|
19508
|
-
*
|
|
19509
19518
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19510
19519
|
* @param percentShift - Percentage the take-profit was shifted
|
|
19511
19520
|
* @param currentPrice - Current market price at time of adjustment
|
|
19512
19521
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19513
19522
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19523
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
19514
19524
|
*/
|
|
19515
19525
|
trailingTake: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
|
|
19516
19526
|
strategyName: StrategyName;
|
|
19517
19527
|
exchangeName: ExchangeName;
|
|
19518
19528
|
frameName: FrameName;
|
|
19519
|
-
}) => Promise<void>;
|
|
19529
|
+
}, timestamp: number) => Promise<void>;
|
|
19520
19530
|
/**
|
|
19521
19531
|
* Logs a breakeven event when the stop-loss is moved to entry price.
|
|
19522
19532
|
*
|
|
19523
|
-
* Records the current price when breakeven protection is activated.
|
|
19524
|
-
*
|
|
19525
19533
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19526
19534
|
* @param currentPrice - Current market price at time of breakeven activation
|
|
19527
19535
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19528
19536
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19537
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
19529
19538
|
*/
|
|
19530
19539
|
breakeven: (symbol: string, currentPrice: number, isBacktest: boolean, context: {
|
|
19531
19540
|
strategyName: StrategyName;
|
|
19532
19541
|
exchangeName: ExchangeName;
|
|
19533
19542
|
frameName: FrameName;
|
|
19534
|
-
}) => Promise<void>;
|
|
19543
|
+
}, timestamp: number) => Promise<void>;
|
|
19535
19544
|
/**
|
|
19536
19545
|
* Initializes the service for event logging.
|
|
19537
19546
|
*
|