backtest-kit 2.2.13 → 2.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.cjs +334 -259
- package/build/index.mjs +334 -259
- package/package.json +1 -1
- package/types.d.ts +128 -151
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.
|
|
@@ -1135,6 +1215,8 @@ interface IPublicSignalRow extends ISignalRow {
|
|
|
1135
1215
|
* Used for persisting signals with accurate creation time.
|
|
1136
1216
|
*/
|
|
1137
1217
|
interface IStorageSignalRow extends IPublicSignalRow {
|
|
1218
|
+
/** Creation timestamp taken from IStrategyTickResult */
|
|
1219
|
+
createdAt: number;
|
|
1138
1220
|
/** Creation timestamp taken from IStrategyTickResult */
|
|
1139
1221
|
updatedAt: number;
|
|
1140
1222
|
/** Storage adapter rewrite priority. Equal to Date.now for live and backtest both */
|
|
@@ -5101,84 +5183,6 @@ interface WalkerContract {
|
|
|
5101
5183
|
totalStrategies: number;
|
|
5102
5184
|
}
|
|
5103
5185
|
|
|
5104
|
-
/**
|
|
5105
|
-
* Base fields for all signal commit events.
|
|
5106
|
-
*/
|
|
5107
|
-
interface SignalCommitBase {
|
|
5108
|
-
symbol: string;
|
|
5109
|
-
strategyName: StrategyName;
|
|
5110
|
-
exchangeName: ExchangeName;
|
|
5111
|
-
frameName: FrameName;
|
|
5112
|
-
backtest: boolean;
|
|
5113
|
-
}
|
|
5114
|
-
/**
|
|
5115
|
-
* Cancel scheduled signal event.
|
|
5116
|
-
*/
|
|
5117
|
-
interface CancelScheduledCommit extends SignalCommitBase {
|
|
5118
|
-
action: "cancel-scheduled";
|
|
5119
|
-
cancelId?: string;
|
|
5120
|
-
}
|
|
5121
|
-
/**
|
|
5122
|
-
* Close pending signal event.
|
|
5123
|
-
*/
|
|
5124
|
-
interface ClosePendingCommit extends SignalCommitBase {
|
|
5125
|
-
action: "close-pending";
|
|
5126
|
-
closeId?: string;
|
|
5127
|
-
}
|
|
5128
|
-
/**
|
|
5129
|
-
* Partial profit event.
|
|
5130
|
-
*/
|
|
5131
|
-
interface PartialProfitCommit extends SignalCommitBase {
|
|
5132
|
-
action: "partial-profit";
|
|
5133
|
-
percentToClose: number;
|
|
5134
|
-
currentPrice: number;
|
|
5135
|
-
}
|
|
5136
|
-
/**
|
|
5137
|
-
* Partial loss event.
|
|
5138
|
-
*/
|
|
5139
|
-
interface PartialLossCommit extends SignalCommitBase {
|
|
5140
|
-
action: "partial-loss";
|
|
5141
|
-
percentToClose: number;
|
|
5142
|
-
currentPrice: number;
|
|
5143
|
-
}
|
|
5144
|
-
/**
|
|
5145
|
-
* Trailing stop event.
|
|
5146
|
-
*/
|
|
5147
|
-
interface TrailingStopCommit extends SignalCommitBase {
|
|
5148
|
-
action: "trailing-stop";
|
|
5149
|
-
percentShift: number;
|
|
5150
|
-
currentPrice: number;
|
|
5151
|
-
}
|
|
5152
|
-
/**
|
|
5153
|
-
* Trailing take event.
|
|
5154
|
-
*/
|
|
5155
|
-
interface TrailingTakeCommit extends SignalCommitBase {
|
|
5156
|
-
action: "trailing-take";
|
|
5157
|
-
percentShift: number;
|
|
5158
|
-
currentPrice: number;
|
|
5159
|
-
}
|
|
5160
|
-
/**
|
|
5161
|
-
* Breakeven event.
|
|
5162
|
-
*/
|
|
5163
|
-
interface BreakevenCommit extends SignalCommitBase {
|
|
5164
|
-
action: "breakeven";
|
|
5165
|
-
currentPrice: number;
|
|
5166
|
-
}
|
|
5167
|
-
/**
|
|
5168
|
-
* Discriminated union for strategy management signal events.
|
|
5169
|
-
*
|
|
5170
|
-
* Emitted by strategyCommitSubject when strategy management actions are executed.
|
|
5171
|
-
*
|
|
5172
|
-
* Consumers:
|
|
5173
|
-
* - StrategyReportService: Persists events to JSON files
|
|
5174
|
-
* - StrategyMarkdownService: Accumulates events for markdown reports
|
|
5175
|
-
*
|
|
5176
|
-
* Note: Signal data (IPublicSignalRow) is NOT included in this contract.
|
|
5177
|
-
* Consumers must retrieve signal data from StrategyCoreService using
|
|
5178
|
-
* getPendingSignal() or getScheduledSignal() methods.
|
|
5179
|
-
*/
|
|
5180
|
-
type StrategyCommitContract = CancelScheduledCommit | ClosePendingCommit | PartialProfitCommit | PartialLossCommit | TrailingStopCommit | TrailingTakeCommit | BreakevenCommit;
|
|
5181
|
-
|
|
5182
5186
|
/**
|
|
5183
5187
|
* Subscribes to all signal events with queued async processing.
|
|
5184
5188
|
*
|
|
@@ -6558,6 +6562,8 @@ interface PartialProfitAvailableNotification {
|
|
|
6558
6562
|
priceOpen: number;
|
|
6559
6563
|
/** Trade direction: "long" (buy) or "short" (sell) */
|
|
6560
6564
|
position: "long" | "short";
|
|
6565
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6566
|
+
createdAt: number;
|
|
6561
6567
|
}
|
|
6562
6568
|
/**
|
|
6563
6569
|
* Partial loss notification.
|
|
@@ -6588,6 +6594,8 @@ interface PartialLossAvailableNotification {
|
|
|
6588
6594
|
priceOpen: number;
|
|
6589
6595
|
/** Trade direction: "long" (buy) or "short" (sell) */
|
|
6590
6596
|
position: "long" | "short";
|
|
6597
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6598
|
+
createdAt: number;
|
|
6591
6599
|
}
|
|
6592
6600
|
/**
|
|
6593
6601
|
* Breakeven available notification.
|
|
@@ -6616,6 +6624,8 @@ interface BreakevenAvailableNotification {
|
|
|
6616
6624
|
priceOpen: number;
|
|
6617
6625
|
/** Trade direction: "long" (buy) or "short" (sell) */
|
|
6618
6626
|
position: "long" | "short";
|
|
6627
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6628
|
+
createdAt: number;
|
|
6619
6629
|
}
|
|
6620
6630
|
/**
|
|
6621
6631
|
* Partial profit commit notification.
|
|
@@ -6640,6 +6650,8 @@ interface PartialProfitCommitNotification {
|
|
|
6640
6650
|
percentToClose: number;
|
|
6641
6651
|
/** Current market price when partial was executed */
|
|
6642
6652
|
currentPrice: number;
|
|
6653
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6654
|
+
createdAt: number;
|
|
6643
6655
|
}
|
|
6644
6656
|
/**
|
|
6645
6657
|
* Partial loss commit notification.
|
|
@@ -6664,6 +6676,8 @@ interface PartialLossCommitNotification {
|
|
|
6664
6676
|
percentToClose: number;
|
|
6665
6677
|
/** Current market price when partial was executed */
|
|
6666
6678
|
currentPrice: number;
|
|
6679
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6680
|
+
createdAt: number;
|
|
6667
6681
|
}
|
|
6668
6682
|
/**
|
|
6669
6683
|
* Breakeven commit notification.
|
|
@@ -6686,6 +6700,8 @@ interface BreakevenCommitNotification {
|
|
|
6686
6700
|
exchangeName: ExchangeName;
|
|
6687
6701
|
/** Current market price when breakeven was executed */
|
|
6688
6702
|
currentPrice: number;
|
|
6703
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6704
|
+
createdAt: number;
|
|
6689
6705
|
}
|
|
6690
6706
|
/**
|
|
6691
6707
|
* Trailing stop commit notification.
|
|
@@ -6710,6 +6726,8 @@ interface TrailingStopCommitNotification {
|
|
|
6710
6726
|
percentShift: number;
|
|
6711
6727
|
/** Current market price when trailing stop was executed */
|
|
6712
6728
|
currentPrice: number;
|
|
6729
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6730
|
+
createdAt: number;
|
|
6713
6731
|
}
|
|
6714
6732
|
/**
|
|
6715
6733
|
* Trailing take commit notification.
|
|
@@ -6734,6 +6752,8 @@ interface TrailingTakeCommitNotification {
|
|
|
6734
6752
|
percentShift: number;
|
|
6735
6753
|
/** Current market price when trailing take was executed */
|
|
6736
6754
|
currentPrice: number;
|
|
6755
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6756
|
+
createdAt: number;
|
|
6737
6757
|
}
|
|
6738
6758
|
/**
|
|
6739
6759
|
* Risk rejection notification.
|
|
@@ -6764,6 +6784,8 @@ interface RiskRejectionNotification {
|
|
|
6764
6784
|
currentPrice: number;
|
|
6765
6785
|
/** The signal that was rejected */
|
|
6766
6786
|
pendingSignal: ISignalDto;
|
|
6787
|
+
/** Unix timestamp in milliseconds when the notification was created */
|
|
6788
|
+
createdAt: number;
|
|
6767
6789
|
}
|
|
6768
6790
|
/**
|
|
6769
6791
|
* Scheduled signal notification.
|
|
@@ -6842,8 +6864,6 @@ interface InfoErrorNotification {
|
|
|
6842
6864
|
error: object;
|
|
6843
6865
|
/** Human-readable error message */
|
|
6844
6866
|
message: string;
|
|
6845
|
-
/** Unix timestamp in milliseconds when error occurred */
|
|
6846
|
-
timestamp: number;
|
|
6847
6867
|
/** Always false for error notifications (errors are from live context) */
|
|
6848
6868
|
backtest: boolean;
|
|
6849
6869
|
}
|
|
@@ -6860,8 +6880,6 @@ interface CriticalErrorNotification {
|
|
|
6860
6880
|
error: object;
|
|
6861
6881
|
/** Human-readable error message */
|
|
6862
6882
|
message: string;
|
|
6863
|
-
/** Unix timestamp in milliseconds when critical error occurred */
|
|
6864
|
-
timestamp: number;
|
|
6865
6883
|
/** Always false for error notifications (errors are from live context) */
|
|
6866
6884
|
backtest: boolean;
|
|
6867
6885
|
}
|
|
@@ -6878,8 +6896,6 @@ interface ValidationErrorNotification {
|
|
|
6878
6896
|
error: object;
|
|
6879
6897
|
/** Human-readable validation error message */
|
|
6880
6898
|
message: string;
|
|
6881
|
-
/** Unix timestamp in milliseconds when validation error occurred */
|
|
6882
|
-
timestamp: number;
|
|
6883
6899
|
/** Always false for error notifications (errors are from live context) */
|
|
6884
6900
|
backtest: boolean;
|
|
6885
6901
|
}
|
|
@@ -13897,9 +13913,6 @@ type Columns = ColumnModel<StrategyEvent>;
|
|
|
13897
13913
|
*/
|
|
13898
13914
|
declare class StrategyMarkdownService {
|
|
13899
13915
|
readonly loggerService: LoggerService;
|
|
13900
|
-
readonly executionContextService: {
|
|
13901
|
-
readonly context: IExecutionContext;
|
|
13902
|
-
};
|
|
13903
13916
|
readonly strategyCoreService: StrategyCoreService;
|
|
13904
13917
|
/**
|
|
13905
13918
|
* Memoized factory for ReportStorage instances.
|
|
@@ -13913,114 +13926,105 @@ declare class StrategyMarkdownService {
|
|
|
13913
13926
|
/**
|
|
13914
13927
|
* Records a cancel-scheduled event when a scheduled signal is cancelled.
|
|
13915
13928
|
*
|
|
13916
|
-
* Retrieves the scheduled signal from StrategyCoreService and stores
|
|
13917
|
-
* the cancellation event in the appropriate ReportStorage.
|
|
13918
|
-
*
|
|
13919
13929
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13920
13930
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13921
13931
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13932
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
13922
13933
|
* @param cancelId - Optional identifier for the cancellation reason
|
|
13923
13934
|
*/
|
|
13924
13935
|
cancelScheduled: (symbol: string, isBacktest: boolean, context: {
|
|
13925
13936
|
strategyName: StrategyName;
|
|
13926
13937
|
exchangeName: ExchangeName;
|
|
13927
13938
|
frameName: FrameName;
|
|
13928
|
-
}, cancelId?: string) => Promise<void>;
|
|
13939
|
+
}, timestamp: number, cancelId?: string) => Promise<void>;
|
|
13929
13940
|
/**
|
|
13930
13941
|
* Records a close-pending event when a pending signal is closed.
|
|
13931
13942
|
*
|
|
13932
|
-
* Retrieves the pending signal from StrategyCoreService and stores
|
|
13933
|
-
* the close event in the appropriate ReportStorage.
|
|
13934
|
-
*
|
|
13935
13943
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13936
13944
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13937
13945
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13946
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
13938
13947
|
* @param closeId - Optional identifier for the close reason
|
|
13939
13948
|
*/
|
|
13940
13949
|
closePending: (symbol: string, isBacktest: boolean, context: {
|
|
13941
13950
|
strategyName: StrategyName;
|
|
13942
13951
|
exchangeName: ExchangeName;
|
|
13943
13952
|
frameName: FrameName;
|
|
13944
|
-
}, closeId?: string) => Promise<void>;
|
|
13953
|
+
}, timestamp: number, closeId?: string) => Promise<void>;
|
|
13945
13954
|
/**
|
|
13946
13955
|
* Records a partial-profit event when a portion of the position is closed at profit.
|
|
13947
13956
|
*
|
|
13948
|
-
* Stores the percentage closed and current price when partial profit-taking occurs.
|
|
13949
|
-
*
|
|
13950
13957
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13951
13958
|
* @param percentToClose - Percentage of position to close (0-100)
|
|
13952
13959
|
* @param currentPrice - Current market price at time of partial close
|
|
13953
13960
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13954
13961
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13962
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
13955
13963
|
*/
|
|
13956
13964
|
partialProfit: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
|
|
13957
13965
|
strategyName: StrategyName;
|
|
13958
13966
|
exchangeName: ExchangeName;
|
|
13959
13967
|
frameName: FrameName;
|
|
13960
|
-
}) => Promise<void>;
|
|
13968
|
+
}, timestamp: number) => Promise<void>;
|
|
13961
13969
|
/**
|
|
13962
13970
|
* Records a partial-loss event when a portion of the position is closed at loss.
|
|
13963
13971
|
*
|
|
13964
|
-
* Stores the percentage closed and current price when partial loss-cutting occurs.
|
|
13965
|
-
*
|
|
13966
13972
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13967
13973
|
* @param percentToClose - Percentage of position to close (0-100)
|
|
13968
13974
|
* @param currentPrice - Current market price at time of partial close
|
|
13969
13975
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13970
13976
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13977
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
13971
13978
|
*/
|
|
13972
13979
|
partialLoss: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
|
|
13973
13980
|
strategyName: StrategyName;
|
|
13974
13981
|
exchangeName: ExchangeName;
|
|
13975
13982
|
frameName: FrameName;
|
|
13976
|
-
}) => Promise<void>;
|
|
13983
|
+
}, timestamp: number) => Promise<void>;
|
|
13977
13984
|
/**
|
|
13978
13985
|
* Records a trailing-stop event when the stop-loss is adjusted.
|
|
13979
13986
|
*
|
|
13980
|
-
* Stores the percentage shift and current price when trailing stop moves.
|
|
13981
|
-
*
|
|
13982
13987
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13983
13988
|
* @param percentShift - Percentage the stop-loss was shifted
|
|
13984
13989
|
* @param currentPrice - Current market price at time of adjustment
|
|
13985
13990
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13986
13991
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13992
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
13987
13993
|
*/
|
|
13988
13994
|
trailingStop: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
|
|
13989
13995
|
strategyName: StrategyName;
|
|
13990
13996
|
exchangeName: ExchangeName;
|
|
13991
13997
|
frameName: FrameName;
|
|
13992
|
-
}) => Promise<void>;
|
|
13998
|
+
}, timestamp: number) => Promise<void>;
|
|
13993
13999
|
/**
|
|
13994
14000
|
* Records a trailing-take event when the take-profit is adjusted.
|
|
13995
14001
|
*
|
|
13996
|
-
* Stores the percentage shift and current price when trailing take-profit moves.
|
|
13997
|
-
*
|
|
13998
14002
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13999
14003
|
* @param percentShift - Percentage the take-profit was shifted
|
|
14000
14004
|
* @param currentPrice - Current market price at time of adjustment
|
|
14001
14005
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
14002
14006
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
14007
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
14003
14008
|
*/
|
|
14004
14009
|
trailingTake: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
|
|
14005
14010
|
strategyName: StrategyName;
|
|
14006
14011
|
exchangeName: ExchangeName;
|
|
14007
14012
|
frameName: FrameName;
|
|
14008
|
-
}) => Promise<void>;
|
|
14013
|
+
}, timestamp: number) => Promise<void>;
|
|
14009
14014
|
/**
|
|
14010
14015
|
* Records a breakeven event when the stop-loss is moved to entry price.
|
|
14011
14016
|
*
|
|
14012
|
-
* Stores the current price when breakeven protection is activated.
|
|
14013
|
-
*
|
|
14014
14017
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
14015
14018
|
* @param currentPrice - Current market price at time of breakeven activation
|
|
14016
14019
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
14017
14020
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
14021
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
14018
14022
|
*/
|
|
14019
14023
|
breakeven: (symbol: string, currentPrice: number, isBacktest: boolean, context: {
|
|
14020
14024
|
strategyName: StrategyName;
|
|
14021
14025
|
exchangeName: ExchangeName;
|
|
14022
14026
|
frameName: FrameName;
|
|
14023
|
-
}) => Promise<void>;
|
|
14027
|
+
}, timestamp: number) => Promise<void>;
|
|
14024
14028
|
/**
|
|
14025
14029
|
* Retrieves aggregated statistics from accumulated strategy events.
|
|
14026
14030
|
*
|
|
@@ -19395,141 +19399,114 @@ declare class RiskReportService {
|
|
|
19395
19399
|
* - Events are written via Report.writeData() with "strategy" category
|
|
19396
19400
|
* - Call unsubscribe() to disable event logging
|
|
19397
19401
|
*
|
|
19398
|
-
* @example
|
|
19399
|
-
* ```typescript
|
|
19400
|
-
* // Service is typically used internally by strategy management classes
|
|
19401
|
-
* strategyReportService.subscribe();
|
|
19402
|
-
*
|
|
19403
|
-
* // Events are logged automatically when strategy actions occur
|
|
19404
|
-
* await strategyReportService.partialProfit("BTCUSDT", 50, 50100, false, {
|
|
19405
|
-
* strategyName: "my-strategy",
|
|
19406
|
-
* exchangeName: "binance",
|
|
19407
|
-
* frameName: "1h"
|
|
19408
|
-
* });
|
|
19409
|
-
*
|
|
19410
|
-
* strategyReportService.unsubscribe();
|
|
19411
|
-
* ```
|
|
19412
|
-
*
|
|
19413
19402
|
* @see StrategyMarkdownService for in-memory event accumulation and markdown report generation
|
|
19414
19403
|
* @see Report for the underlying persistence mechanism
|
|
19415
19404
|
*/
|
|
19416
19405
|
declare class StrategyReportService {
|
|
19417
19406
|
readonly loggerService: LoggerService;
|
|
19418
|
-
readonly executionContextService: {
|
|
19419
|
-
readonly context: IExecutionContext;
|
|
19420
|
-
};
|
|
19421
19407
|
readonly strategyCoreService: StrategyCoreService;
|
|
19422
19408
|
/**
|
|
19423
19409
|
* Logs a cancel-scheduled event when a scheduled signal is cancelled.
|
|
19424
19410
|
*
|
|
19425
|
-
* Retrieves the scheduled signal from StrategyCoreService and writes
|
|
19426
|
-
* the cancellation event to the report file.
|
|
19427
|
-
*
|
|
19428
19411
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19429
19412
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19430
19413
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19414
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
19431
19415
|
* @param cancelId - Optional identifier for the cancellation reason
|
|
19432
19416
|
*/
|
|
19433
19417
|
cancelScheduled: (symbol: string, isBacktest: boolean, context: {
|
|
19434
19418
|
strategyName: StrategyName;
|
|
19435
19419
|
exchangeName: ExchangeName;
|
|
19436
19420
|
frameName: FrameName;
|
|
19437
|
-
}, cancelId?: string) => Promise<void>;
|
|
19421
|
+
}, timestamp: number, cancelId?: string) => Promise<void>;
|
|
19438
19422
|
/**
|
|
19439
19423
|
* Logs a close-pending event when a pending signal is closed.
|
|
19440
19424
|
*
|
|
19441
|
-
* Retrieves the pending signal from StrategyCoreService and writes
|
|
19442
|
-
* the close event to the report file.
|
|
19443
|
-
*
|
|
19444
19425
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19445
19426
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19446
19427
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19428
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
19447
19429
|
* @param closeId - Optional identifier for the close reason
|
|
19448
19430
|
*/
|
|
19449
19431
|
closePending: (symbol: string, isBacktest: boolean, context: {
|
|
19450
19432
|
strategyName: StrategyName;
|
|
19451
19433
|
exchangeName: ExchangeName;
|
|
19452
19434
|
frameName: FrameName;
|
|
19453
|
-
}, closeId?: string) => Promise<void>;
|
|
19435
|
+
}, timestamp: number, closeId?: string) => Promise<void>;
|
|
19454
19436
|
/**
|
|
19455
19437
|
* Logs a partial-profit event when a portion of the position is closed at profit.
|
|
19456
19438
|
*
|
|
19457
|
-
* Records the percentage closed and current price when partial profit-taking occurs.
|
|
19458
|
-
*
|
|
19459
19439
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19460
19440
|
* @param percentToClose - Percentage of position to close (0-100)
|
|
19461
19441
|
* @param currentPrice - Current market price at time of partial close
|
|
19462
19442
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19463
19443
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19444
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
19464
19445
|
*/
|
|
19465
19446
|
partialProfit: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
|
|
19466
19447
|
strategyName: StrategyName;
|
|
19467
19448
|
exchangeName: ExchangeName;
|
|
19468
19449
|
frameName: FrameName;
|
|
19469
|
-
}) => Promise<void>;
|
|
19450
|
+
}, timestamp: number) => Promise<void>;
|
|
19470
19451
|
/**
|
|
19471
19452
|
* Logs a partial-loss event when a portion of the position is closed at loss.
|
|
19472
19453
|
*
|
|
19473
|
-
* Records the percentage closed and current price when partial loss-cutting occurs.
|
|
19474
|
-
*
|
|
19475
19454
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19476
19455
|
* @param percentToClose - Percentage of position to close (0-100)
|
|
19477
19456
|
* @param currentPrice - Current market price at time of partial close
|
|
19478
19457
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19479
19458
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19459
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
19480
19460
|
*/
|
|
19481
19461
|
partialLoss: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
|
|
19482
19462
|
strategyName: StrategyName;
|
|
19483
19463
|
exchangeName: ExchangeName;
|
|
19484
19464
|
frameName: FrameName;
|
|
19485
|
-
}) => Promise<void>;
|
|
19465
|
+
}, timestamp: number) => Promise<void>;
|
|
19486
19466
|
/**
|
|
19487
19467
|
* Logs a trailing-stop event when the stop-loss is adjusted.
|
|
19488
19468
|
*
|
|
19489
|
-
* Records the percentage shift and current price when trailing stop moves.
|
|
19490
|
-
*
|
|
19491
19469
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19492
19470
|
* @param percentShift - Percentage the stop-loss was shifted
|
|
19493
19471
|
* @param currentPrice - Current market price at time of adjustment
|
|
19494
19472
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19495
19473
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19474
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
19496
19475
|
*/
|
|
19497
19476
|
trailingStop: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
|
|
19498
19477
|
strategyName: StrategyName;
|
|
19499
19478
|
exchangeName: ExchangeName;
|
|
19500
19479
|
frameName: FrameName;
|
|
19501
|
-
}) => Promise<void>;
|
|
19480
|
+
}, timestamp: number) => Promise<void>;
|
|
19502
19481
|
/**
|
|
19503
19482
|
* Logs a trailing-take event when the take-profit is adjusted.
|
|
19504
19483
|
*
|
|
19505
|
-
* Records the percentage shift and current price when trailing take-profit moves.
|
|
19506
|
-
*
|
|
19507
19484
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19508
19485
|
* @param percentShift - Percentage the take-profit was shifted
|
|
19509
19486
|
* @param currentPrice - Current market price at time of adjustment
|
|
19510
19487
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19511
19488
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19489
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
19512
19490
|
*/
|
|
19513
19491
|
trailingTake: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
|
|
19514
19492
|
strategyName: StrategyName;
|
|
19515
19493
|
exchangeName: ExchangeName;
|
|
19516
19494
|
frameName: FrameName;
|
|
19517
|
-
}) => Promise<void>;
|
|
19495
|
+
}, timestamp: number) => Promise<void>;
|
|
19518
19496
|
/**
|
|
19519
19497
|
* Logs a breakeven event when the stop-loss is moved to entry price.
|
|
19520
19498
|
*
|
|
19521
|
-
* Records the current price when breakeven protection is activated.
|
|
19522
|
-
*
|
|
19523
19499
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19524
19500
|
* @param currentPrice - Current market price at time of breakeven activation
|
|
19525
19501
|
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19526
19502
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19503
|
+
* @param timestamp - Timestamp from StrategyCommitContract (execution context time)
|
|
19527
19504
|
*/
|
|
19528
19505
|
breakeven: (symbol: string, currentPrice: number, isBacktest: boolean, context: {
|
|
19529
19506
|
strategyName: StrategyName;
|
|
19530
19507
|
exchangeName: ExchangeName;
|
|
19531
19508
|
frameName: FrameName;
|
|
19532
|
-
}) => Promise<void>;
|
|
19509
|
+
}, timestamp: number) => Promise<void>;
|
|
19533
19510
|
/**
|
|
19534
19511
|
* Initializes the service for event logging.
|
|
19535
19512
|
*
|