backtest-kit 2.0.7 → 2.0.8

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 CHANGED
@@ -8,8 +8,10 @@ var path = require('path');
8
8
  var crypto = require('crypto');
9
9
  var os = require('os');
10
10
  var fs$1 = require('fs');
11
+ var module$1 = require('module');
11
12
  var util = require('util');
12
13
 
14
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
13
15
  function _interopNamespaceDefault(e) {
14
16
  var n = Object.create(null);
15
17
  if (e) {
@@ -151,6 +153,16 @@ const validationServices$1 = {
151
153
  const templateServices$1 = {
152
154
  optimizerTemplateService: Symbol('optimizerTemplateService'),
153
155
  };
156
+ const promptServices$1 = {
157
+ signalPromptService: Symbol('signalPromptService'),
158
+ riskPromptService: Symbol('riskPromptService'),
159
+ trailingTakePromptService: Symbol('trailingTakePromptService'),
160
+ trailingStopPromptService: Symbol('trailingStopPromptService'),
161
+ partialProfitPromptService: Symbol('partialProfitPromptService'),
162
+ partialLossPromptService: Symbol('partialLossPromptService'),
163
+ breakevenPromptService: Symbol('breakevenPromptService'),
164
+ scheduleCancelPromptService: Symbol('scheduleCancelPromptService'),
165
+ };
154
166
  const TYPES = {
155
167
  ...baseServices$1,
156
168
  ...contextServices$1,
@@ -165,6 +177,7 @@ const TYPES = {
165
177
  ...reportServices$1,
166
178
  ...validationServices$1,
167
179
  ...templateServices$1,
180
+ ...promptServices$1,
168
181
  };
169
182
 
170
183
  /**
@@ -22985,264 +22998,1137 @@ class RiskReportService {
22985
22998
  }
22986
22999
  }
22987
23000
 
22988
- {
22989
- provide(TYPES.loggerService, () => new LoggerService());
22990
- }
22991
- {
22992
- provide(TYPES.executionContextService, () => new ExecutionContextService());
22993
- provide(TYPES.methodContextService, () => new MethodContextService());
22994
- }
22995
- {
22996
- provide(TYPES.exchangeConnectionService, () => new ExchangeConnectionService());
22997
- provide(TYPES.strategyConnectionService, () => new StrategyConnectionService());
22998
- provide(TYPES.frameConnectionService, () => new FrameConnectionService());
22999
- provide(TYPES.sizingConnectionService, () => new SizingConnectionService());
23000
- provide(TYPES.riskConnectionService, () => new RiskConnectionService());
23001
- provide(TYPES.actionConnectionService, () => new ActionConnectionService());
23002
- provide(TYPES.optimizerConnectionService, () => new OptimizerConnectionService());
23003
- provide(TYPES.partialConnectionService, () => new PartialConnectionService());
23004
- provide(TYPES.breakevenConnectionService, () => new BreakevenConnectionService());
23005
- }
23006
- {
23007
- provide(TYPES.exchangeSchemaService, () => new ExchangeSchemaService());
23008
- provide(TYPES.strategySchemaService, () => new StrategySchemaService());
23009
- provide(TYPES.frameSchemaService, () => new FrameSchemaService());
23010
- provide(TYPES.walkerSchemaService, () => new WalkerSchemaService());
23011
- provide(TYPES.sizingSchemaService, () => new SizingSchemaService());
23012
- provide(TYPES.riskSchemaService, () => new RiskSchemaService());
23013
- provide(TYPES.actionSchemaService, () => new ActionSchemaService());
23014
- provide(TYPES.optimizerSchemaService, () => new OptimizerSchemaService());
23015
- }
23016
- {
23017
- provide(TYPES.exchangeCoreService, () => new ExchangeCoreService());
23018
- provide(TYPES.strategyCoreService, () => new StrategyCoreService());
23019
- provide(TYPES.actionCoreService, () => new ActionCoreService());
23020
- provide(TYPES.frameCoreService, () => new FrameCoreService());
23021
- }
23022
- {
23023
- provide(TYPES.sizingGlobalService, () => new SizingGlobalService());
23024
- provide(TYPES.riskGlobalService, () => new RiskGlobalService());
23025
- provide(TYPES.optimizerGlobalService, () => new OptimizerGlobalService());
23026
- provide(TYPES.partialGlobalService, () => new PartialGlobalService());
23027
- provide(TYPES.breakevenGlobalService, () => new BreakevenGlobalService());
23028
- }
23029
- {
23030
- provide(TYPES.liveCommandService, () => new LiveCommandService());
23031
- provide(TYPES.backtestCommandService, () => new BacktestCommandService());
23032
- provide(TYPES.walkerCommandService, () => new WalkerCommandService());
23033
- }
23034
- {
23035
- provide(TYPES.backtestLogicPrivateService, () => new BacktestLogicPrivateService());
23036
- provide(TYPES.liveLogicPrivateService, () => new LiveLogicPrivateService());
23037
- provide(TYPES.walkerLogicPrivateService, () => new WalkerLogicPrivateService());
23038
- }
23039
- {
23040
- provide(TYPES.backtestLogicPublicService, () => new BacktestLogicPublicService());
23041
- provide(TYPES.liveLogicPublicService, () => new LiveLogicPublicService());
23042
- provide(TYPES.walkerLogicPublicService, () => new WalkerLogicPublicService());
23043
- }
23044
- {
23045
- provide(TYPES.backtestMarkdownService, () => new BacktestMarkdownService());
23046
- provide(TYPES.liveMarkdownService, () => new LiveMarkdownService());
23047
- provide(TYPES.scheduleMarkdownService, () => new ScheduleMarkdownService());
23048
- provide(TYPES.performanceMarkdownService, () => new PerformanceMarkdownService());
23049
- provide(TYPES.walkerMarkdownService, () => new WalkerMarkdownService());
23050
- provide(TYPES.heatMarkdownService, () => new HeatMarkdownService());
23051
- provide(TYPES.partialMarkdownService, () => new PartialMarkdownService());
23052
- provide(TYPES.breakevenMarkdownService, () => new BreakevenMarkdownService());
23053
- provide(TYPES.outlineMarkdownService, () => new OutlineMarkdownService());
23054
- provide(TYPES.riskMarkdownService, () => new RiskMarkdownService());
23055
- }
23056
- {
23057
- provide(TYPES.backtestReportService, () => new BacktestReportService());
23058
- provide(TYPES.liveReportService, () => new LiveReportService());
23059
- provide(TYPES.scheduleReportService, () => new ScheduleReportService());
23060
- provide(TYPES.performanceReportService, () => new PerformanceReportService());
23061
- provide(TYPES.walkerReportService, () => new WalkerReportService());
23062
- provide(TYPES.heatReportService, () => new HeatReportService());
23063
- provide(TYPES.partialReportService, () => new PartialReportService());
23064
- provide(TYPES.breakevenReportService, () => new BreakevenReportService());
23065
- provide(TYPES.riskReportService, () => new RiskReportService());
23066
- }
23067
- {
23068
- provide(TYPES.exchangeValidationService, () => new ExchangeValidationService());
23069
- provide(TYPES.strategyValidationService, () => new StrategyValidationService());
23070
- provide(TYPES.frameValidationService, () => new FrameValidationService());
23071
- provide(TYPES.walkerValidationService, () => new WalkerValidationService());
23072
- provide(TYPES.sizingValidationService, () => new SizingValidationService());
23073
- provide(TYPES.riskValidationService, () => new RiskValidationService());
23074
- provide(TYPES.actionValidationService, () => new ActionValidationService());
23075
- provide(TYPES.optimizerValidationService, () => new OptimizerValidationService());
23076
- provide(TYPES.configValidationService, () => new ConfigValidationService());
23077
- provide(TYPES.columnValidationService, () => new ColumnValidationService());
23078
- }
23079
- {
23080
- provide(TYPES.optimizerTemplateService, () => new OptimizerTemplateService());
23081
- }
23082
-
23083
- const baseServices = {
23084
- loggerService: inject(TYPES.loggerService),
23085
- };
23086
- const contextServices = {
23087
- executionContextService: inject(TYPES.executionContextService),
23088
- methodContextService: inject(TYPES.methodContextService),
23089
- };
23090
- const connectionServices = {
23091
- exchangeConnectionService: inject(TYPES.exchangeConnectionService),
23092
- strategyConnectionService: inject(TYPES.strategyConnectionService),
23093
- frameConnectionService: inject(TYPES.frameConnectionService),
23094
- sizingConnectionService: inject(TYPES.sizingConnectionService),
23095
- riskConnectionService: inject(TYPES.riskConnectionService),
23096
- actionConnectionService: inject(TYPES.actionConnectionService),
23097
- optimizerConnectionService: inject(TYPES.optimizerConnectionService),
23098
- partialConnectionService: inject(TYPES.partialConnectionService),
23099
- breakevenConnectionService: inject(TYPES.breakevenConnectionService),
23100
- };
23101
- const schemaServices = {
23102
- exchangeSchemaService: inject(TYPES.exchangeSchemaService),
23103
- strategySchemaService: inject(TYPES.strategySchemaService),
23104
- frameSchemaService: inject(TYPES.frameSchemaService),
23105
- walkerSchemaService: inject(TYPES.walkerSchemaService),
23106
- sizingSchemaService: inject(TYPES.sizingSchemaService),
23107
- riskSchemaService: inject(TYPES.riskSchemaService),
23108
- actionSchemaService: inject(TYPES.actionSchemaService),
23109
- optimizerSchemaService: inject(TYPES.optimizerSchemaService),
23110
- };
23111
- const coreServices = {
23112
- exchangeCoreService: inject(TYPES.exchangeCoreService),
23113
- strategyCoreService: inject(TYPES.strategyCoreService),
23114
- actionCoreService: inject(TYPES.actionCoreService),
23115
- frameCoreService: inject(TYPES.frameCoreService),
23116
- };
23117
- const globalServices = {
23118
- sizingGlobalService: inject(TYPES.sizingGlobalService),
23119
- riskGlobalService: inject(TYPES.riskGlobalService),
23120
- optimizerGlobalService: inject(TYPES.optimizerGlobalService),
23121
- partialGlobalService: inject(TYPES.partialGlobalService),
23122
- breakevenGlobalService: inject(TYPES.breakevenGlobalService),
23123
- };
23124
- const commandServices = {
23125
- liveCommandService: inject(TYPES.liveCommandService),
23126
- backtestCommandService: inject(TYPES.backtestCommandService),
23127
- walkerCommandService: inject(TYPES.walkerCommandService),
23128
- };
23129
- const logicPrivateServices = {
23130
- backtestLogicPrivateService: inject(TYPES.backtestLogicPrivateService),
23131
- liveLogicPrivateService: inject(TYPES.liveLogicPrivateService),
23132
- walkerLogicPrivateService: inject(TYPES.walkerLogicPrivateService),
23133
- };
23134
- const logicPublicServices = {
23135
- backtestLogicPublicService: inject(TYPES.backtestLogicPublicService),
23136
- liveLogicPublicService: inject(TYPES.liveLogicPublicService),
23137
- walkerLogicPublicService: inject(TYPES.walkerLogicPublicService),
23138
- };
23139
- const markdownServices = {
23140
- backtestMarkdownService: inject(TYPES.backtestMarkdownService),
23141
- liveMarkdownService: inject(TYPES.liveMarkdownService),
23142
- scheduleMarkdownService: inject(TYPES.scheduleMarkdownService),
23143
- performanceMarkdownService: inject(TYPES.performanceMarkdownService),
23144
- walkerMarkdownService: inject(TYPES.walkerMarkdownService),
23145
- heatMarkdownService: inject(TYPES.heatMarkdownService),
23146
- partialMarkdownService: inject(TYPES.partialMarkdownService),
23147
- breakevenMarkdownService: inject(TYPES.breakevenMarkdownService),
23148
- outlineMarkdownService: inject(TYPES.outlineMarkdownService),
23149
- riskMarkdownService: inject(TYPES.riskMarkdownService),
23150
- };
23151
- const reportServices = {
23152
- backtestReportService: inject(TYPES.backtestReportService),
23153
- liveReportService: inject(TYPES.liveReportService),
23154
- scheduleReportService: inject(TYPES.scheduleReportService),
23155
- performanceReportService: inject(TYPES.performanceReportService),
23156
- walkerReportService: inject(TYPES.walkerReportService),
23157
- heatReportService: inject(TYPES.heatReportService),
23158
- partialReportService: inject(TYPES.partialReportService),
23159
- breakevenReportService: inject(TYPES.breakevenReportService),
23160
- riskReportService: inject(TYPES.riskReportService),
23161
- };
23162
- const validationServices = {
23163
- exchangeValidationService: inject(TYPES.exchangeValidationService),
23164
- strategyValidationService: inject(TYPES.strategyValidationService),
23165
- frameValidationService: inject(TYPES.frameValidationService),
23166
- walkerValidationService: inject(TYPES.walkerValidationService),
23167
- sizingValidationService: inject(TYPES.sizingValidationService),
23168
- riskValidationService: inject(TYPES.riskValidationService),
23169
- actionValidationService: inject(TYPES.actionValidationService),
23170
- optimizerValidationService: inject(TYPES.optimizerValidationService),
23171
- configValidationService: inject(TYPES.configValidationService),
23172
- columnValidationService: inject(TYPES.columnValidationService),
23173
- };
23174
- const templateServices = {
23175
- optimizerTemplateService: inject(TYPES.optimizerTemplateService),
23176
- };
23177
- const backtest = {
23178
- ...baseServices,
23179
- ...contextServices,
23180
- ...connectionServices,
23181
- ...schemaServices,
23182
- ...coreServices,
23183
- ...globalServices,
23184
- ...commandServices,
23185
- ...logicPrivateServices,
23186
- ...logicPublicServices,
23187
- ...markdownServices,
23188
- ...reportServices,
23189
- ...validationServices,
23190
- ...templateServices,
23191
- };
23192
- init();
23193
- var backtest$1 = backtest;
23194
-
23195
- const GET_TIMEFRAME_METHOD_NAME = "get.getBacktestTimeframe";
23196
- /**
23197
- * Retrieves current backtest timeframe for given symbol.
23198
- * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
23199
- * @returns Promise resolving to array of Date objects representing tick timestamps
23200
- * @throws Error if called outside of backtest execution context
23201
- */
23202
- async function getBacktestTimeframe(symbol) {
23203
- backtest$1.loggerService.info(GET_TIMEFRAME_METHOD_NAME, { symbol });
23204
- if (!ExecutionContextService.hasContext()) {
23205
- throw new Error("getBacktestTimeframe requires an execution context");
23206
- }
23207
- if (!MethodContextService.hasContext()) {
23208
- throw new Error("getBacktestTimeframe requires a method context");
23209
- }
23210
- if (!backtest$1.executionContextService.context.backtest) {
23211
- throw new Error("getBacktestTimeframe can only be used during backtest execution");
23212
- }
23213
- return await backtest$1.frameCoreService.getTimeframe(symbol, backtest$1.methodContextService.context.frameName);
23214
- }
23215
-
23216
- const METHOD_NAME = "validate.validate";
23001
+ const require$8 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
23217
23002
  /**
23218
- * Retrieves all registered exchanges as a map
23219
- * @private
23220
- * @returns Map of exchange names
23003
+ * Default fallback prompt configuration.
23004
+ * Used when signal.prompt.cjs file is not found.
23221
23005
  */
23222
- const getExchangeMap = async () => {
23223
- const exchangeMap = {};
23224
- for (const { exchangeName } of await backtest$1.exchangeValidationService.list()) {
23225
- Object.assign(exchangeMap, { [exchangeName]: exchangeName });
23226
- }
23227
- return exchangeMap;
23006
+ const DEFAULT_PROMPT$7 = {
23007
+ user: "",
23008
+ system: [],
23228
23009
  };
23229
23010
  /**
23230
- * Retrieves all registered frames as a map
23231
- * @private
23232
- * @returns Map of frame names
23011
+ * Lazy-loads and caches signal prompt configuration.
23012
+ * Attempts to load from config/prompt/signal.prompt.cjs, falls back to DEFAULT_PROMPT if not found.
23013
+ * Uses singleshot pattern to ensure configuration is loaded only once.
23014
+ * @returns Prompt configuration with system and user prompts
23233
23015
  */
23234
- const getFrameMap = async () => {
23235
- const frameMap = {};
23236
- for (const { frameName } of await backtest$1.frameValidationService.list()) {
23237
- Object.assign(frameMap, { [frameName]: frameName });
23016
+ const GET_PROMPT_FN$7 = functoolsKit.singleshot(() => {
23017
+ try {
23018
+ const modulePath = require$8.resolve(path.join(process.cwd(), `./config/prompt/signal.prompt.cjs`));
23019
+ console.log(`Using ${modulePath} implementation as signal.prompt.cjs`);
23020
+ return require$8(modulePath);
23238
23021
  }
23239
- return frameMap;
23240
- };
23022
+ catch (error) {
23023
+ console.log(`Using empty fallback for signal.prompt.cjs`, error);
23024
+ return DEFAULT_PROMPT$7;
23025
+ }
23026
+ });
23241
23027
  /**
23242
- * Retrieves all registered strategies as a map
23243
- * @private
23244
- * @returns Map of strategy names
23245
- */
23028
+ * Service for managing signal prompts for AI/LLM integrations.
23029
+ *
23030
+ * Provides access to system and user prompts configured in signal.prompt.cjs.
23031
+ * Supports both static prompt arrays and dynamic prompt functions.
23032
+ *
23033
+ * Key responsibilities:
23034
+ * - Lazy-loads prompt configuration from config/prompt/signal.prompt.cjs
23035
+ * - Resolves system prompts (static arrays or async functions)
23036
+ * - Provides user prompt strings
23037
+ * - Falls back to empty prompts if configuration is missing
23038
+ *
23039
+ * Used for AI-powered signal analysis and strategy recommendations.
23040
+ */
23041
+ class SignalPromptService {
23042
+ constructor() {
23043
+ this.loggerService = inject(TYPES.loggerService);
23044
+ /**
23045
+ * Retrieves system prompts for AI context.
23046
+ *
23047
+ * System prompts can be:
23048
+ * - Static array of strings (returned directly)
23049
+ * - Async/sync function returning string array (executed and awaited)
23050
+ * - Undefined (returns empty array)
23051
+ *
23052
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23053
+ * @param strategyName - Strategy identifier
23054
+ * @param exchangeName - Exchange identifier
23055
+ * @param frameName - Timeframe identifier
23056
+ * @param backtest - Whether running in backtest mode
23057
+ * @returns Promise resolving to array of system prompt strings
23058
+ */
23059
+ this.getSystemPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23060
+ this.loggerService.log("signalPromptService getSystemPrompt", {
23061
+ symbol,
23062
+ strategyName,
23063
+ exchangeName,
23064
+ frameName,
23065
+ backtest,
23066
+ });
23067
+ const { system } = GET_PROMPT_FN$7();
23068
+ if (Array.isArray(system)) {
23069
+ return system;
23070
+ }
23071
+ if (typeof system === "function") {
23072
+ return await system(symbol, strategyName, exchangeName, frameName, backtest);
23073
+ }
23074
+ return [];
23075
+ };
23076
+ /**
23077
+ * Retrieves user prompt string for AI input.
23078
+ *
23079
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23080
+ * @param strategyName - Strategy identifier
23081
+ * @param exchangeName - Exchange identifier
23082
+ * @param frameName - Timeframe identifier
23083
+ * @param backtest - Whether running in backtest mode
23084
+ * @returns Promise resolving to user prompt string
23085
+ */
23086
+ this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23087
+ this.loggerService.log("signalPromptService getUserPrompt", {
23088
+ symbol,
23089
+ strategyName,
23090
+ exchangeName,
23091
+ frameName,
23092
+ backtest,
23093
+ });
23094
+ const { user } = GET_PROMPT_FN$7();
23095
+ if (typeof user === "string") {
23096
+ return user;
23097
+ }
23098
+ if (typeof user === "function") {
23099
+ return await user(symbol, strategyName, exchangeName, frameName, backtest);
23100
+ }
23101
+ return "";
23102
+ };
23103
+ }
23104
+ }
23105
+
23106
+ const require$7 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
23107
+ /**
23108
+ * Default fallback prompt configuration.
23109
+ * Used when risk.prompt.cjs file is not found.
23110
+ */
23111
+ const DEFAULT_PROMPT$6 = {
23112
+ user: "",
23113
+ system: [],
23114
+ };
23115
+ /**
23116
+ * Lazy-loads and caches risk rejection prompt configuration.
23117
+ * Attempts to load from config/prompt/risk.prompt.cjs, falls back to DEFAULT_PROMPT if not found.
23118
+ * Uses singleshot pattern to ensure configuration is loaded only once.
23119
+ * @returns Prompt configuration with system and user prompts
23120
+ */
23121
+ const GET_PROMPT_FN$6 = functoolsKit.singleshot(() => {
23122
+ try {
23123
+ const modulePath = require$7.resolve(path.join(process.cwd(), `./config/prompt/risk.prompt.cjs`));
23124
+ console.log(`Using ${modulePath} implementation as risk.prompt.cjs`);
23125
+ return require$7(modulePath);
23126
+ }
23127
+ catch (error) {
23128
+ console.log(`Using empty fallback for risk.prompt.cjs`, error);
23129
+ return DEFAULT_PROMPT$6;
23130
+ }
23131
+ });
23132
+ /**
23133
+ * Service for managing risk rejection prompts for AI/LLM integrations.
23134
+ *
23135
+ * Provides access to system and user prompts configured in risk.prompt.cjs.
23136
+ * Supports both static prompt arrays and dynamic prompt functions.
23137
+ *
23138
+ * Key responsibilities:
23139
+ * - Lazy-loads prompt configuration from config/prompt/risk.prompt.cjs
23140
+ * - Resolves system prompts (static arrays or async functions)
23141
+ * - Provides user prompt strings
23142
+ * - Falls back to empty prompts if configuration is missing
23143
+ *
23144
+ * Used for AI-powered analysis when signals fail risk validation.
23145
+ * Triggered by: riskRejection() events in ActionBase
23146
+ * Use cases: Analyze rejection reasons, suggest risk adjustments, track rejection patterns
23147
+ */
23148
+ class RiskPromptService {
23149
+ constructor() {
23150
+ this.loggerService = inject(TYPES.loggerService);
23151
+ /**
23152
+ * Retrieves system prompts for AI context.
23153
+ *
23154
+ * System prompts can be:
23155
+ * - Static array of strings (returned directly)
23156
+ * - Async/sync function returning string array (executed and awaited)
23157
+ * - Undefined (returns empty array)
23158
+ *
23159
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23160
+ * @param strategyName - Strategy identifier
23161
+ * @param exchangeName - Exchange identifier
23162
+ * @param frameName - Timeframe identifier
23163
+ * @param backtest - Whether running in backtest mode
23164
+ * @returns Promise resolving to array of system prompt strings
23165
+ */
23166
+ this.getSystemPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23167
+ this.loggerService.log("riskPromptService getSystemPrompt", {
23168
+ symbol,
23169
+ strategyName,
23170
+ exchangeName,
23171
+ frameName,
23172
+ backtest,
23173
+ });
23174
+ const { system } = GET_PROMPT_FN$6();
23175
+ if (Array.isArray(system)) {
23176
+ return system;
23177
+ }
23178
+ if (typeof system === "function") {
23179
+ return await system(symbol, strategyName, exchangeName, frameName, backtest);
23180
+ }
23181
+ return [];
23182
+ };
23183
+ /**
23184
+ * Retrieves user prompt string for AI input.
23185
+ *
23186
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23187
+ * @param strategyName - Strategy identifier
23188
+ * @param exchangeName - Exchange identifier
23189
+ * @param frameName - Timeframe identifier
23190
+ * @param backtest - Whether running in backtest mode
23191
+ * @returns Promise resolving to user prompt string
23192
+ */
23193
+ this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23194
+ this.loggerService.log("riskPromptService getUserPrompt", {
23195
+ symbol,
23196
+ strategyName,
23197
+ exchangeName,
23198
+ frameName,
23199
+ backtest,
23200
+ });
23201
+ const { user } = GET_PROMPT_FN$6();
23202
+ if (typeof user === "string") {
23203
+ return user;
23204
+ }
23205
+ if (typeof user === "function") {
23206
+ return await user(symbol, strategyName, exchangeName, frameName, backtest);
23207
+ }
23208
+ return "";
23209
+ };
23210
+ }
23211
+ }
23212
+
23213
+ const require$6 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
23214
+ /**
23215
+ * Default fallback prompt configuration.
23216
+ * Used when trailing-take.prompt.cjs file is not found.
23217
+ */
23218
+ const DEFAULT_PROMPT$5 = {
23219
+ user: "",
23220
+ system: [],
23221
+ };
23222
+ /**
23223
+ * Lazy-loads and caches trailing take-profit prompt configuration.
23224
+ * Attempts to load from config/prompt/trailing-take.prompt.cjs, falls back to DEFAULT_PROMPT if not found.
23225
+ * Uses singleshot pattern to ensure configuration is loaded only once.
23226
+ * @returns Prompt configuration with system and user prompts
23227
+ */
23228
+ const GET_PROMPT_FN$5 = functoolsKit.singleshot(() => {
23229
+ try {
23230
+ const modulePath = require$6.resolve(path.join(process.cwd(), `./config/prompt/trailing-take.prompt.cjs`));
23231
+ console.log(`Using ${modulePath} implementation as trailing-take.prompt.cjs`);
23232
+ return require$6(modulePath);
23233
+ }
23234
+ catch (error) {
23235
+ console.log(`Using empty fallback for trailing-take.prompt.cjs`, error);
23236
+ return DEFAULT_PROMPT$5;
23237
+ }
23238
+ });
23239
+ /**
23240
+ * Service for managing trailing take-profit prompts for AI/LLM integrations.
23241
+ *
23242
+ * Provides access to system and user prompts configured in trailing-take.prompt.cjs.
23243
+ * Supports both static prompt arrays and dynamic prompt functions.
23244
+ *
23245
+ * Key responsibilities:
23246
+ * - Lazy-loads prompt configuration from config/prompt/trailing-take.prompt.cjs
23247
+ * - Resolves system prompts (static arrays or async functions)
23248
+ * - Provides user prompt strings
23249
+ * - Falls back to empty prompts if configuration is missing
23250
+ *
23251
+ * Used for AI-powered analysis of trailing take-profit adjustments.
23252
+ * Use cases: Suggest optimal trailing levels, analyze profit-taking strategies, optimize exit timing
23253
+ */
23254
+ class TrailingTakePromptService {
23255
+ constructor() {
23256
+ this.loggerService = inject(TYPES.loggerService);
23257
+ /**
23258
+ * Retrieves system prompts for AI context.
23259
+ *
23260
+ * System prompts can be:
23261
+ * - Static array of strings (returned directly)
23262
+ * - Async/sync function returning string array (executed and awaited)
23263
+ * - Undefined (returns empty array)
23264
+ *
23265
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23266
+ * @param strategyName - Strategy identifier
23267
+ * @param exchangeName - Exchange identifier
23268
+ * @param frameName - Timeframe identifier
23269
+ * @param backtest - Whether running in backtest mode
23270
+ * @returns Promise resolving to array of system prompt strings
23271
+ */
23272
+ this.getSystemPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23273
+ this.loggerService.log("trailingTakePromptService getSystemPrompt", {
23274
+ symbol,
23275
+ strategyName,
23276
+ exchangeName,
23277
+ frameName,
23278
+ backtest,
23279
+ });
23280
+ const { system } = GET_PROMPT_FN$5();
23281
+ if (Array.isArray(system)) {
23282
+ return system;
23283
+ }
23284
+ if (typeof system === "function") {
23285
+ return await system(symbol, strategyName, exchangeName, frameName, backtest);
23286
+ }
23287
+ return [];
23288
+ };
23289
+ /**
23290
+ * Retrieves user prompt string for AI input.
23291
+ *
23292
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23293
+ * @param strategyName - Strategy identifier
23294
+ * @param exchangeName - Exchange identifier
23295
+ * @param frameName - Timeframe identifier
23296
+ * @param backtest - Whether running in backtest mode
23297
+ * @returns Promise resolving to user prompt string
23298
+ */
23299
+ this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23300
+ this.loggerService.log("trailingTakePromptService getUserPrompt", {
23301
+ symbol,
23302
+ strategyName,
23303
+ exchangeName,
23304
+ frameName,
23305
+ backtest,
23306
+ });
23307
+ const { user } = GET_PROMPT_FN$5();
23308
+ if (typeof user === "string") {
23309
+ return user;
23310
+ }
23311
+ if (typeof user === "function") {
23312
+ return await user(symbol, strategyName, exchangeName, frameName, backtest);
23313
+ }
23314
+ return "";
23315
+ };
23316
+ }
23317
+ }
23318
+
23319
+ const require$5 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
23320
+ /**
23321
+ * Default fallback prompt configuration.
23322
+ * Used when trailing-stop.prompt.cjs file is not found.
23323
+ */
23324
+ const DEFAULT_PROMPT$4 = {
23325
+ user: "",
23326
+ system: [],
23327
+ };
23328
+ /**
23329
+ * Lazy-loads and caches trailing stop-loss prompt configuration.
23330
+ * Attempts to load from config/prompt/trailing-stop.prompt.cjs, falls back to DEFAULT_PROMPT if not found.
23331
+ * Uses singleshot pattern to ensure configuration is loaded only once.
23332
+ * @returns Prompt configuration with system and user prompts
23333
+ */
23334
+ const GET_PROMPT_FN$4 = functoolsKit.singleshot(() => {
23335
+ try {
23336
+ const modulePath = require$5.resolve(path.join(process.cwd(), `./config/prompt/trailing-stop.prompt.cjs`));
23337
+ console.log(`Using ${modulePath} implementation as trailing-stop.prompt.cjs`);
23338
+ return require$5(modulePath);
23339
+ }
23340
+ catch (error) {
23341
+ console.log(`Using empty fallback for trailing-stop.prompt.cjs`, error);
23342
+ return DEFAULT_PROMPT$4;
23343
+ }
23344
+ });
23345
+ /**
23346
+ * Service for managing trailing stop-loss prompts for AI/LLM integrations.
23347
+ *
23348
+ * Provides access to system and user prompts configured in trailing-stop.prompt.cjs.
23349
+ * Supports both static prompt arrays and dynamic prompt functions.
23350
+ *
23351
+ * Key responsibilities:
23352
+ * - Lazy-loads prompt configuration from config/prompt/trailing-stop.prompt.cjs
23353
+ * - Resolves system prompts (static arrays or async functions)
23354
+ * - Provides user prompt strings
23355
+ * - Falls back to empty prompts if configuration is missing
23356
+ *
23357
+ * Used for AI-powered analysis of trailing stop-loss adjustments.
23358
+ * Use cases: Suggest optimal trailing distances, analyze risk protection strategies, optimize stop placement
23359
+ */
23360
+ class TrailingStopPromptService {
23361
+ constructor() {
23362
+ this.loggerService = inject(TYPES.loggerService);
23363
+ /**
23364
+ * Retrieves system prompts for AI context.
23365
+ *
23366
+ * System prompts can be:
23367
+ * - Static array of strings (returned directly)
23368
+ * - Async/sync function returning string array (executed and awaited)
23369
+ * - Undefined (returns empty array)
23370
+ *
23371
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23372
+ * @param strategyName - Strategy identifier
23373
+ * @param exchangeName - Exchange identifier
23374
+ * @param frameName - Timeframe identifier
23375
+ * @param backtest - Whether running in backtest mode
23376
+ * @returns Promise resolving to array of system prompt strings
23377
+ */
23378
+ this.getSystemPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23379
+ this.loggerService.log("trailingStopPromptService getSystemPrompt", {
23380
+ symbol,
23381
+ strategyName,
23382
+ exchangeName,
23383
+ frameName,
23384
+ backtest,
23385
+ });
23386
+ const { system } = GET_PROMPT_FN$4();
23387
+ if (Array.isArray(system)) {
23388
+ return system;
23389
+ }
23390
+ if (typeof system === "function") {
23391
+ return await system(symbol, strategyName, exchangeName, frameName, backtest);
23392
+ }
23393
+ return [];
23394
+ };
23395
+ /**
23396
+ * Retrieves user prompt string for AI input.
23397
+ *
23398
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23399
+ * @param strategyName - Strategy identifier
23400
+ * @param exchangeName - Exchange identifier
23401
+ * @param frameName - Timeframe identifier
23402
+ * @param backtest - Whether running in backtest mode
23403
+ * @returns Promise resolving to user prompt string
23404
+ */
23405
+ this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23406
+ this.loggerService.log("trailingStopPromptService getUserPrompt", {
23407
+ symbol,
23408
+ strategyName,
23409
+ exchangeName,
23410
+ frameName,
23411
+ backtest,
23412
+ });
23413
+ const { user } = GET_PROMPT_FN$4();
23414
+ if (typeof user === "string") {
23415
+ return user;
23416
+ }
23417
+ if (typeof user === "function") {
23418
+ return await user(symbol, strategyName, exchangeName, frameName, backtest);
23419
+ }
23420
+ return "";
23421
+ };
23422
+ }
23423
+ }
23424
+
23425
+ const require$4 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
23426
+ /**
23427
+ * Default fallback prompt configuration.
23428
+ * Used when partial-profit.prompt.cjs file is not found.
23429
+ */
23430
+ const DEFAULT_PROMPT$3 = {
23431
+ user: "",
23432
+ system: [],
23433
+ };
23434
+ /**
23435
+ * Lazy-loads and caches partial profit prompt configuration.
23436
+ * Attempts to load from config/prompt/partial-profit.prompt.cjs, falls back to DEFAULT_PROMPT if not found.
23437
+ * Uses singleshot pattern to ensure configuration is loaded only once.
23438
+ * @returns Prompt configuration with system and user prompts
23439
+ */
23440
+ const GET_PROMPT_FN$3 = functoolsKit.singleshot(() => {
23441
+ try {
23442
+ const modulePath = require$4.resolve(path.join(process.cwd(), `./config/prompt/partial-profit.prompt.cjs`));
23443
+ console.log(`Using ${modulePath} implementation as partial-profit.prompt.cjs`);
23444
+ return require$4(modulePath);
23445
+ }
23446
+ catch (error) {
23447
+ console.log(`Using empty fallback for partial-profit.prompt.cjs`, error);
23448
+ return DEFAULT_PROMPT$3;
23449
+ }
23450
+ });
23451
+ /**
23452
+ * Service for managing partial profit prompts for AI/LLM integrations.
23453
+ *
23454
+ * Provides access to system and user prompts configured in partial-profit.prompt.cjs.
23455
+ * Supports both static prompt arrays and dynamic prompt functions.
23456
+ *
23457
+ * Key responsibilities:
23458
+ * - Lazy-loads prompt configuration from config/prompt/partial-profit.prompt.cjs
23459
+ * - Resolves system prompts (static arrays or async functions)
23460
+ * - Provides user prompt strings
23461
+ * - Falls back to empty prompts if configuration is missing
23462
+ *
23463
+ * Used for AI-powered analysis when profit milestones are reached (10%, 20%, 30%, etc).
23464
+ * Triggered by: partialProfitAvailable() events in ActionBase
23465
+ * Use cases: Suggest position adjustments, analyze profit-taking opportunities, optimize milestone actions
23466
+ */
23467
+ class PartialProfitPromptService {
23468
+ constructor() {
23469
+ this.loggerService = inject(TYPES.loggerService);
23470
+ /**
23471
+ * Retrieves system prompts for AI context.
23472
+ *
23473
+ * System prompts can be:
23474
+ * - Static array of strings (returned directly)
23475
+ * - Async/sync function returning string array (executed and awaited)
23476
+ * - Undefined (returns empty array)
23477
+ *
23478
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23479
+ * @param strategyName - Strategy identifier
23480
+ * @param exchangeName - Exchange identifier
23481
+ * @param frameName - Timeframe identifier
23482
+ * @param backtest - Whether running in backtest mode
23483
+ * @returns Promise resolving to array of system prompt strings
23484
+ */
23485
+ this.getSystemPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23486
+ this.loggerService.log("partialProfitPromptService getSystemPrompt", {
23487
+ symbol,
23488
+ strategyName,
23489
+ exchangeName,
23490
+ frameName,
23491
+ backtest,
23492
+ });
23493
+ const { system } = GET_PROMPT_FN$3();
23494
+ if (Array.isArray(system)) {
23495
+ return system;
23496
+ }
23497
+ if (typeof system === "function") {
23498
+ return await system(symbol, strategyName, exchangeName, frameName, backtest);
23499
+ }
23500
+ return [];
23501
+ };
23502
+ /**
23503
+ * Retrieves user prompt string for AI input.
23504
+ *
23505
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23506
+ * @param strategyName - Strategy identifier
23507
+ * @param exchangeName - Exchange identifier
23508
+ * @param frameName - Timeframe identifier
23509
+ * @param backtest - Whether running in backtest mode
23510
+ * @returns Promise resolving to user prompt string
23511
+ */
23512
+ this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23513
+ this.loggerService.log("partialProfitPromptService getUserPrompt", {
23514
+ symbol,
23515
+ strategyName,
23516
+ exchangeName,
23517
+ frameName,
23518
+ backtest,
23519
+ });
23520
+ const { user } = GET_PROMPT_FN$3();
23521
+ if (typeof user === "string") {
23522
+ return user;
23523
+ }
23524
+ if (typeof user === "function") {
23525
+ return await user(symbol, strategyName, exchangeName, frameName, backtest);
23526
+ }
23527
+ return "";
23528
+ };
23529
+ }
23530
+ }
23531
+
23532
+ const require$3 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
23533
+ /**
23534
+ * Default fallback prompt configuration.
23535
+ * Used when partial-loss.prompt.cjs file is not found.
23536
+ */
23537
+ const DEFAULT_PROMPT$2 = {
23538
+ user: "",
23539
+ system: [],
23540
+ };
23541
+ /**
23542
+ * Lazy-loads and caches partial loss prompt configuration.
23543
+ * Attempts to load from config/prompt/partial-loss.prompt.cjs, falls back to DEFAULT_PROMPT if not found.
23544
+ * Uses singleshot pattern to ensure configuration is loaded only once.
23545
+ * @returns Prompt configuration with system and user prompts
23546
+ */
23547
+ const GET_PROMPT_FN$2 = functoolsKit.singleshot(() => {
23548
+ try {
23549
+ const modulePath = require$3.resolve(path.join(process.cwd(), `./config/prompt/partial-loss.prompt.cjs`));
23550
+ console.log(`Using ${modulePath} implementation as partial-loss.prompt.cjs`);
23551
+ return require$3(modulePath);
23552
+ }
23553
+ catch (error) {
23554
+ console.log(`Using empty fallback for partial-loss.prompt.cjs`, error);
23555
+ return DEFAULT_PROMPT$2;
23556
+ }
23557
+ });
23558
+ /**
23559
+ * Service for managing partial loss prompts for AI/LLM integrations.
23560
+ *
23561
+ * Provides access to system and user prompts configured in partial-loss.prompt.cjs.
23562
+ * Supports both static prompt arrays and dynamic prompt functions.
23563
+ *
23564
+ * Key responsibilities:
23565
+ * - Lazy-loads prompt configuration from config/prompt/partial-loss.prompt.cjs
23566
+ * - Resolves system prompts (static arrays or async functions)
23567
+ * - Provides user prompt strings
23568
+ * - Falls back to empty prompts if configuration is missing
23569
+ *
23570
+ * Used for AI-powered analysis when loss milestones are reached (-10%, -20%, -30%, etc).
23571
+ * Triggered by: partialLossAvailable() events in ActionBase
23572
+ * Use cases: Suggest risk management actions, analyze loss mitigation strategies, optimize exit decisions
23573
+ */
23574
+ class PartialLossPromptService {
23575
+ constructor() {
23576
+ this.loggerService = inject(TYPES.loggerService);
23577
+ /**
23578
+ * Retrieves system prompts for AI context.
23579
+ *
23580
+ * System prompts can be:
23581
+ * - Static array of strings (returned directly)
23582
+ * - Async/sync function returning string array (executed and awaited)
23583
+ * - Undefined (returns empty array)
23584
+ *
23585
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23586
+ * @param strategyName - Strategy identifier
23587
+ * @param exchangeName - Exchange identifier
23588
+ * @param frameName - Timeframe identifier
23589
+ * @param backtest - Whether running in backtest mode
23590
+ * @returns Promise resolving to array of system prompt strings
23591
+ */
23592
+ this.getSystemPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23593
+ this.loggerService.log("partialLossPromptService getSystemPrompt", {
23594
+ symbol,
23595
+ strategyName,
23596
+ exchangeName,
23597
+ frameName,
23598
+ backtest,
23599
+ });
23600
+ const { system } = GET_PROMPT_FN$2();
23601
+ if (Array.isArray(system)) {
23602
+ return system;
23603
+ }
23604
+ if (typeof system === "function") {
23605
+ return await system(symbol, strategyName, exchangeName, frameName, backtest);
23606
+ }
23607
+ return [];
23608
+ };
23609
+ /**
23610
+ * Retrieves user prompt string for AI input.
23611
+ *
23612
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23613
+ * @param strategyName - Strategy identifier
23614
+ * @param exchangeName - Exchange identifier
23615
+ * @param frameName - Timeframe identifier
23616
+ * @param backtest - Whether running in backtest mode
23617
+ * @returns Promise resolving to user prompt string
23618
+ */
23619
+ this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23620
+ this.loggerService.log("partialLossPromptService getUserPrompt", {
23621
+ symbol,
23622
+ strategyName,
23623
+ exchangeName,
23624
+ frameName,
23625
+ backtest,
23626
+ });
23627
+ const { user } = GET_PROMPT_FN$2();
23628
+ if (typeof user === "string") {
23629
+ return user;
23630
+ }
23631
+ if (typeof user === "function") {
23632
+ return await user(symbol, strategyName, exchangeName, frameName, backtest);
23633
+ }
23634
+ return "";
23635
+ };
23636
+ }
23637
+ }
23638
+
23639
+ const require$2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
23640
+ /**
23641
+ * Default fallback prompt configuration.
23642
+ * Used when breakeven.prompt.cjs file is not found.
23643
+ */
23644
+ const DEFAULT_PROMPT$1 = {
23645
+ user: "",
23646
+ system: [],
23647
+ };
23648
+ /**
23649
+ * Lazy-loads and caches breakeven prompt configuration.
23650
+ * Attempts to load from config/prompt/breakeven.prompt.cjs, falls back to DEFAULT_PROMPT if not found.
23651
+ * Uses singleshot pattern to ensure configuration is loaded only once.
23652
+ * @returns Prompt configuration with system and user prompts
23653
+ */
23654
+ const GET_PROMPT_FN$1 = functoolsKit.singleshot(() => {
23655
+ try {
23656
+ const modulePath = require$2.resolve(path.join(process.cwd(), `./config/prompt/breakeven.prompt.cjs`));
23657
+ console.log(`Using ${modulePath} implementation as breakeven.prompt.cjs`);
23658
+ return require$2(modulePath);
23659
+ }
23660
+ catch (error) {
23661
+ console.log(`Using empty fallback for breakeven.prompt.cjs`, error);
23662
+ return DEFAULT_PROMPT$1;
23663
+ }
23664
+ });
23665
+ /**
23666
+ * Service for managing breakeven prompts for AI/LLM integrations.
23667
+ *
23668
+ * Provides access to system and user prompts configured in breakeven.prompt.cjs.
23669
+ * Supports both static prompt arrays and dynamic prompt functions.
23670
+ *
23671
+ * Key responsibilities:
23672
+ * - Lazy-loads prompt configuration from config/prompt/breakeven.prompt.cjs
23673
+ * - Resolves system prompts (static arrays or async functions)
23674
+ * - Provides user prompt strings
23675
+ * - Falls back to empty prompts if configuration is missing
23676
+ *
23677
+ * Used for AI-powered analysis when stop-loss is moved to entry price (risk-free position).
23678
+ * Triggered by: breakevenAvailable() events in ActionBase
23679
+ * Use cases: Suggest position management after breakeven, analyze profit potential, optimize trailing strategies
23680
+ */
23681
+ class BreakevenPromptService {
23682
+ constructor() {
23683
+ this.loggerService = inject(TYPES.loggerService);
23684
+ /**
23685
+ * Retrieves system prompts for AI context.
23686
+ *
23687
+ * System prompts can be:
23688
+ * - Static array of strings (returned directly)
23689
+ * - Async/sync function returning string array (executed and awaited)
23690
+ * - Undefined (returns empty array)
23691
+ *
23692
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23693
+ * @param strategyName - Strategy identifier
23694
+ * @param exchangeName - Exchange identifier
23695
+ * @param frameName - Timeframe identifier
23696
+ * @param backtest - Whether running in backtest mode
23697
+ * @returns Promise resolving to array of system prompt strings
23698
+ */
23699
+ this.getSystemPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23700
+ this.loggerService.log("breakevenPromptService getSystemPrompt", {
23701
+ symbol,
23702
+ strategyName,
23703
+ exchangeName,
23704
+ frameName,
23705
+ backtest,
23706
+ });
23707
+ const { system } = GET_PROMPT_FN$1();
23708
+ if (Array.isArray(system)) {
23709
+ return system;
23710
+ }
23711
+ if (typeof system === "function") {
23712
+ return await system(symbol, strategyName, exchangeName, frameName, backtest);
23713
+ }
23714
+ return [];
23715
+ };
23716
+ /**
23717
+ * Retrieves user prompt string for AI input.
23718
+ *
23719
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23720
+ * @param strategyName - Strategy identifier
23721
+ * @param exchangeName - Exchange identifier
23722
+ * @param frameName - Timeframe identifier
23723
+ * @param backtest - Whether running in backtest mode
23724
+ * @returns Promise resolving to user prompt string
23725
+ */
23726
+ this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23727
+ this.loggerService.log("breakevenPromptService getUserPrompt", {
23728
+ symbol,
23729
+ strategyName,
23730
+ exchangeName,
23731
+ frameName,
23732
+ backtest,
23733
+ });
23734
+ const { user } = GET_PROMPT_FN$1();
23735
+ if (typeof user === "string") {
23736
+ return user;
23737
+ }
23738
+ if (typeof user === "function") {
23739
+ return await user(symbol, strategyName, exchangeName, frameName, backtest);
23740
+ }
23741
+ return "";
23742
+ };
23743
+ }
23744
+ }
23745
+
23746
+ const require$1 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
23747
+ /**
23748
+ * Default fallback prompt configuration.
23749
+ * Used when schedule-cancel.prompt.cjs file is not found.
23750
+ */
23751
+ const DEFAULT_PROMPT = {
23752
+ user: "",
23753
+ system: [],
23754
+ };
23755
+ /**
23756
+ * Lazy-loads and caches schedule cancellation prompt configuration.
23757
+ * Attempts to load from config/prompt/schedule-cancel.prompt.cjs, falls back to DEFAULT_PROMPT if not found.
23758
+ * Uses singleshot pattern to ensure configuration is loaded only once.
23759
+ * @returns Prompt configuration with system and user prompts
23760
+ */
23761
+ const GET_PROMPT_FN = functoolsKit.singleshot(() => {
23762
+ try {
23763
+ const modulePath = require$1.resolve(path.join(process.cwd(), `./config/prompt/schedule-cancel.prompt.cjs`));
23764
+ console.log(`Using ${modulePath} implementation as schedule-cancel.prompt.cjs`);
23765
+ return require$1(modulePath);
23766
+ }
23767
+ catch (error) {
23768
+ console.log(`Using empty fallback for schedule-cancel.prompt.cjs`, error);
23769
+ return DEFAULT_PROMPT;
23770
+ }
23771
+ });
23772
+ /**
23773
+ * Service for managing schedule cancellation prompts for AI/LLM integrations.
23774
+ *
23775
+ * Provides access to system and user prompts configured in schedule-cancel.prompt.cjs.
23776
+ * Supports both static prompt arrays and dynamic prompt functions.
23777
+ *
23778
+ * Key responsibilities:
23779
+ * - Lazy-loads prompt configuration from config/prompt/schedule-cancel.prompt.cjs
23780
+ * - Resolves system prompts (static arrays or async functions)
23781
+ * - Provides user prompt strings
23782
+ * - Falls back to empty prompts if configuration is missing
23783
+ *
23784
+ * Used for AI-powered analysis when scheduled signals are cancelled before activation.
23785
+ * Triggered by: signal() events with action='cancelled' in ActionBase
23786
+ * Use cases: Analyze cancellation reasons, track signal invalidation patterns, optimize scheduling logic
23787
+ */
23788
+ class ScheduleCancelPromptService {
23789
+ constructor() {
23790
+ this.loggerService = inject(TYPES.loggerService);
23791
+ /**
23792
+ * Retrieves system prompts for AI context.
23793
+ *
23794
+ * System prompts can be:
23795
+ * - Static array of strings (returned directly)
23796
+ * - Async/sync function returning string array (executed and awaited)
23797
+ * - Undefined (returns empty array)
23798
+ *
23799
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23800
+ * @param strategyName - Strategy identifier
23801
+ * @param exchangeName - Exchange identifier
23802
+ * @param frameName - Timeframe identifier
23803
+ * @param backtest - Whether running in backtest mode
23804
+ * @returns Promise resolving to array of system prompt strings
23805
+ */
23806
+ this.getSystemPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23807
+ this.loggerService.log("scheduleCancelPromptService getSystemPrompt", {
23808
+ symbol,
23809
+ strategyName,
23810
+ exchangeName,
23811
+ frameName,
23812
+ backtest,
23813
+ });
23814
+ const { system } = GET_PROMPT_FN();
23815
+ if (Array.isArray(system)) {
23816
+ return system;
23817
+ }
23818
+ if (typeof system === "function") {
23819
+ return await system(symbol, strategyName, exchangeName, frameName, backtest);
23820
+ }
23821
+ return [];
23822
+ };
23823
+ /**
23824
+ * Retrieves user prompt string for AI input.
23825
+ *
23826
+ * @param symbol - Trading symbol (e.g., "BTCUSDT")
23827
+ * @param strategyName - Strategy identifier
23828
+ * @param exchangeName - Exchange identifier
23829
+ * @param frameName - Timeframe identifier
23830
+ * @param backtest - Whether running in backtest mode
23831
+ * @returns Promise resolving to user prompt string
23832
+ */
23833
+ this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
23834
+ this.loggerService.log("scheduleCancelPromptService getUserPrompt", {
23835
+ symbol,
23836
+ strategyName,
23837
+ exchangeName,
23838
+ frameName,
23839
+ backtest,
23840
+ });
23841
+ const { user } = GET_PROMPT_FN();
23842
+ if (typeof user === "string") {
23843
+ return user;
23844
+ }
23845
+ if (typeof user === "function") {
23846
+ return await user(symbol, strategyName, exchangeName, frameName, backtest);
23847
+ }
23848
+ return "";
23849
+ };
23850
+ }
23851
+ }
23852
+
23853
+ {
23854
+ provide(TYPES.loggerService, () => new LoggerService());
23855
+ }
23856
+ {
23857
+ provide(TYPES.executionContextService, () => new ExecutionContextService());
23858
+ provide(TYPES.methodContextService, () => new MethodContextService());
23859
+ }
23860
+ {
23861
+ provide(TYPES.exchangeConnectionService, () => new ExchangeConnectionService());
23862
+ provide(TYPES.strategyConnectionService, () => new StrategyConnectionService());
23863
+ provide(TYPES.frameConnectionService, () => new FrameConnectionService());
23864
+ provide(TYPES.sizingConnectionService, () => new SizingConnectionService());
23865
+ provide(TYPES.riskConnectionService, () => new RiskConnectionService());
23866
+ provide(TYPES.actionConnectionService, () => new ActionConnectionService());
23867
+ provide(TYPES.optimizerConnectionService, () => new OptimizerConnectionService());
23868
+ provide(TYPES.partialConnectionService, () => new PartialConnectionService());
23869
+ provide(TYPES.breakevenConnectionService, () => new BreakevenConnectionService());
23870
+ }
23871
+ {
23872
+ provide(TYPES.exchangeSchemaService, () => new ExchangeSchemaService());
23873
+ provide(TYPES.strategySchemaService, () => new StrategySchemaService());
23874
+ provide(TYPES.frameSchemaService, () => new FrameSchemaService());
23875
+ provide(TYPES.walkerSchemaService, () => new WalkerSchemaService());
23876
+ provide(TYPES.sizingSchemaService, () => new SizingSchemaService());
23877
+ provide(TYPES.riskSchemaService, () => new RiskSchemaService());
23878
+ provide(TYPES.actionSchemaService, () => new ActionSchemaService());
23879
+ provide(TYPES.optimizerSchemaService, () => new OptimizerSchemaService());
23880
+ }
23881
+ {
23882
+ provide(TYPES.exchangeCoreService, () => new ExchangeCoreService());
23883
+ provide(TYPES.strategyCoreService, () => new StrategyCoreService());
23884
+ provide(TYPES.actionCoreService, () => new ActionCoreService());
23885
+ provide(TYPES.frameCoreService, () => new FrameCoreService());
23886
+ }
23887
+ {
23888
+ provide(TYPES.sizingGlobalService, () => new SizingGlobalService());
23889
+ provide(TYPES.riskGlobalService, () => new RiskGlobalService());
23890
+ provide(TYPES.optimizerGlobalService, () => new OptimizerGlobalService());
23891
+ provide(TYPES.partialGlobalService, () => new PartialGlobalService());
23892
+ provide(TYPES.breakevenGlobalService, () => new BreakevenGlobalService());
23893
+ }
23894
+ {
23895
+ provide(TYPES.liveCommandService, () => new LiveCommandService());
23896
+ provide(TYPES.backtestCommandService, () => new BacktestCommandService());
23897
+ provide(TYPES.walkerCommandService, () => new WalkerCommandService());
23898
+ }
23899
+ {
23900
+ provide(TYPES.backtestLogicPrivateService, () => new BacktestLogicPrivateService());
23901
+ provide(TYPES.liveLogicPrivateService, () => new LiveLogicPrivateService());
23902
+ provide(TYPES.walkerLogicPrivateService, () => new WalkerLogicPrivateService());
23903
+ }
23904
+ {
23905
+ provide(TYPES.backtestLogicPublicService, () => new BacktestLogicPublicService());
23906
+ provide(TYPES.liveLogicPublicService, () => new LiveLogicPublicService());
23907
+ provide(TYPES.walkerLogicPublicService, () => new WalkerLogicPublicService());
23908
+ }
23909
+ {
23910
+ provide(TYPES.backtestMarkdownService, () => new BacktestMarkdownService());
23911
+ provide(TYPES.liveMarkdownService, () => new LiveMarkdownService());
23912
+ provide(TYPES.scheduleMarkdownService, () => new ScheduleMarkdownService());
23913
+ provide(TYPES.performanceMarkdownService, () => new PerformanceMarkdownService());
23914
+ provide(TYPES.walkerMarkdownService, () => new WalkerMarkdownService());
23915
+ provide(TYPES.heatMarkdownService, () => new HeatMarkdownService());
23916
+ provide(TYPES.partialMarkdownService, () => new PartialMarkdownService());
23917
+ provide(TYPES.breakevenMarkdownService, () => new BreakevenMarkdownService());
23918
+ provide(TYPES.outlineMarkdownService, () => new OutlineMarkdownService());
23919
+ provide(TYPES.riskMarkdownService, () => new RiskMarkdownService());
23920
+ }
23921
+ {
23922
+ provide(TYPES.backtestReportService, () => new BacktestReportService());
23923
+ provide(TYPES.liveReportService, () => new LiveReportService());
23924
+ provide(TYPES.scheduleReportService, () => new ScheduleReportService());
23925
+ provide(TYPES.performanceReportService, () => new PerformanceReportService());
23926
+ provide(TYPES.walkerReportService, () => new WalkerReportService());
23927
+ provide(TYPES.heatReportService, () => new HeatReportService());
23928
+ provide(TYPES.partialReportService, () => new PartialReportService());
23929
+ provide(TYPES.breakevenReportService, () => new BreakevenReportService());
23930
+ provide(TYPES.riskReportService, () => new RiskReportService());
23931
+ }
23932
+ {
23933
+ provide(TYPES.exchangeValidationService, () => new ExchangeValidationService());
23934
+ provide(TYPES.strategyValidationService, () => new StrategyValidationService());
23935
+ provide(TYPES.frameValidationService, () => new FrameValidationService());
23936
+ provide(TYPES.walkerValidationService, () => new WalkerValidationService());
23937
+ provide(TYPES.sizingValidationService, () => new SizingValidationService());
23938
+ provide(TYPES.riskValidationService, () => new RiskValidationService());
23939
+ provide(TYPES.actionValidationService, () => new ActionValidationService());
23940
+ provide(TYPES.optimizerValidationService, () => new OptimizerValidationService());
23941
+ provide(TYPES.configValidationService, () => new ConfigValidationService());
23942
+ provide(TYPES.columnValidationService, () => new ColumnValidationService());
23943
+ }
23944
+ {
23945
+ provide(TYPES.optimizerTemplateService, () => new OptimizerTemplateService());
23946
+ }
23947
+ {
23948
+ provide(TYPES.signalPromptService, () => new SignalPromptService());
23949
+ provide(TYPES.riskPromptService, () => new RiskPromptService());
23950
+ provide(TYPES.trailingTakePromptService, () => new TrailingTakePromptService());
23951
+ provide(TYPES.trailingStopPromptService, () => new TrailingStopPromptService());
23952
+ provide(TYPES.partialProfitPromptService, () => new PartialProfitPromptService());
23953
+ provide(TYPES.partialLossPromptService, () => new PartialLossPromptService());
23954
+ provide(TYPES.breakevenPromptService, () => new BreakevenPromptService());
23955
+ provide(TYPES.scheduleCancelPromptService, () => new ScheduleCancelPromptService());
23956
+ }
23957
+
23958
+ const baseServices = {
23959
+ loggerService: inject(TYPES.loggerService),
23960
+ };
23961
+ const contextServices = {
23962
+ executionContextService: inject(TYPES.executionContextService),
23963
+ methodContextService: inject(TYPES.methodContextService),
23964
+ };
23965
+ const connectionServices = {
23966
+ exchangeConnectionService: inject(TYPES.exchangeConnectionService),
23967
+ strategyConnectionService: inject(TYPES.strategyConnectionService),
23968
+ frameConnectionService: inject(TYPES.frameConnectionService),
23969
+ sizingConnectionService: inject(TYPES.sizingConnectionService),
23970
+ riskConnectionService: inject(TYPES.riskConnectionService),
23971
+ actionConnectionService: inject(TYPES.actionConnectionService),
23972
+ optimizerConnectionService: inject(TYPES.optimizerConnectionService),
23973
+ partialConnectionService: inject(TYPES.partialConnectionService),
23974
+ breakevenConnectionService: inject(TYPES.breakevenConnectionService),
23975
+ };
23976
+ const schemaServices = {
23977
+ exchangeSchemaService: inject(TYPES.exchangeSchemaService),
23978
+ strategySchemaService: inject(TYPES.strategySchemaService),
23979
+ frameSchemaService: inject(TYPES.frameSchemaService),
23980
+ walkerSchemaService: inject(TYPES.walkerSchemaService),
23981
+ sizingSchemaService: inject(TYPES.sizingSchemaService),
23982
+ riskSchemaService: inject(TYPES.riskSchemaService),
23983
+ actionSchemaService: inject(TYPES.actionSchemaService),
23984
+ optimizerSchemaService: inject(TYPES.optimizerSchemaService),
23985
+ };
23986
+ const coreServices = {
23987
+ exchangeCoreService: inject(TYPES.exchangeCoreService),
23988
+ strategyCoreService: inject(TYPES.strategyCoreService),
23989
+ actionCoreService: inject(TYPES.actionCoreService),
23990
+ frameCoreService: inject(TYPES.frameCoreService),
23991
+ };
23992
+ const globalServices = {
23993
+ sizingGlobalService: inject(TYPES.sizingGlobalService),
23994
+ riskGlobalService: inject(TYPES.riskGlobalService),
23995
+ optimizerGlobalService: inject(TYPES.optimizerGlobalService),
23996
+ partialGlobalService: inject(TYPES.partialGlobalService),
23997
+ breakevenGlobalService: inject(TYPES.breakevenGlobalService),
23998
+ };
23999
+ const commandServices = {
24000
+ liveCommandService: inject(TYPES.liveCommandService),
24001
+ backtestCommandService: inject(TYPES.backtestCommandService),
24002
+ walkerCommandService: inject(TYPES.walkerCommandService),
24003
+ };
24004
+ const logicPrivateServices = {
24005
+ backtestLogicPrivateService: inject(TYPES.backtestLogicPrivateService),
24006
+ liveLogicPrivateService: inject(TYPES.liveLogicPrivateService),
24007
+ walkerLogicPrivateService: inject(TYPES.walkerLogicPrivateService),
24008
+ };
24009
+ const logicPublicServices = {
24010
+ backtestLogicPublicService: inject(TYPES.backtestLogicPublicService),
24011
+ liveLogicPublicService: inject(TYPES.liveLogicPublicService),
24012
+ walkerLogicPublicService: inject(TYPES.walkerLogicPublicService),
24013
+ };
24014
+ const markdownServices = {
24015
+ backtestMarkdownService: inject(TYPES.backtestMarkdownService),
24016
+ liveMarkdownService: inject(TYPES.liveMarkdownService),
24017
+ scheduleMarkdownService: inject(TYPES.scheduleMarkdownService),
24018
+ performanceMarkdownService: inject(TYPES.performanceMarkdownService),
24019
+ walkerMarkdownService: inject(TYPES.walkerMarkdownService),
24020
+ heatMarkdownService: inject(TYPES.heatMarkdownService),
24021
+ partialMarkdownService: inject(TYPES.partialMarkdownService),
24022
+ breakevenMarkdownService: inject(TYPES.breakevenMarkdownService),
24023
+ outlineMarkdownService: inject(TYPES.outlineMarkdownService),
24024
+ riskMarkdownService: inject(TYPES.riskMarkdownService),
24025
+ };
24026
+ const reportServices = {
24027
+ backtestReportService: inject(TYPES.backtestReportService),
24028
+ liveReportService: inject(TYPES.liveReportService),
24029
+ scheduleReportService: inject(TYPES.scheduleReportService),
24030
+ performanceReportService: inject(TYPES.performanceReportService),
24031
+ walkerReportService: inject(TYPES.walkerReportService),
24032
+ heatReportService: inject(TYPES.heatReportService),
24033
+ partialReportService: inject(TYPES.partialReportService),
24034
+ breakevenReportService: inject(TYPES.breakevenReportService),
24035
+ riskReportService: inject(TYPES.riskReportService),
24036
+ };
24037
+ const validationServices = {
24038
+ exchangeValidationService: inject(TYPES.exchangeValidationService),
24039
+ strategyValidationService: inject(TYPES.strategyValidationService),
24040
+ frameValidationService: inject(TYPES.frameValidationService),
24041
+ walkerValidationService: inject(TYPES.walkerValidationService),
24042
+ sizingValidationService: inject(TYPES.sizingValidationService),
24043
+ riskValidationService: inject(TYPES.riskValidationService),
24044
+ actionValidationService: inject(TYPES.actionValidationService),
24045
+ optimizerValidationService: inject(TYPES.optimizerValidationService),
24046
+ configValidationService: inject(TYPES.configValidationService),
24047
+ columnValidationService: inject(TYPES.columnValidationService),
24048
+ };
24049
+ const templateServices = {
24050
+ optimizerTemplateService: inject(TYPES.optimizerTemplateService),
24051
+ };
24052
+ const promptServices = {
24053
+ signalPromptService: inject(TYPES.signalPromptService),
24054
+ riskPromptService: inject(TYPES.riskPromptService),
24055
+ trailingTakePromptService: inject(TYPES.trailingTakePromptService),
24056
+ trailingStopPromptService: inject(TYPES.trailingStopPromptService),
24057
+ partialProfitPromptService: inject(TYPES.partialProfitPromptService),
24058
+ partialLossPromptService: inject(TYPES.partialLossPromptService),
24059
+ breakevenPromptService: inject(TYPES.breakevenPromptService),
24060
+ scheduleCancelPromptService: inject(TYPES.scheduleCancelPromptService),
24061
+ };
24062
+ const backtest = {
24063
+ ...baseServices,
24064
+ ...contextServices,
24065
+ ...connectionServices,
24066
+ ...schemaServices,
24067
+ ...coreServices,
24068
+ ...globalServices,
24069
+ ...commandServices,
24070
+ ...logicPrivateServices,
24071
+ ...logicPublicServices,
24072
+ ...markdownServices,
24073
+ ...reportServices,
24074
+ ...validationServices,
24075
+ ...templateServices,
24076
+ ...promptServices,
24077
+ };
24078
+ init();
24079
+ var backtest$1 = backtest;
24080
+
24081
+ const GET_TIMEFRAME_METHOD_NAME = "get.getBacktestTimeframe";
24082
+ /**
24083
+ * Retrieves current backtest timeframe for given symbol.
24084
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
24085
+ * @returns Promise resolving to array of Date objects representing tick timestamps
24086
+ * @throws Error if called outside of backtest execution context
24087
+ */
24088
+ async function getBacktestTimeframe(symbol) {
24089
+ backtest$1.loggerService.info(GET_TIMEFRAME_METHOD_NAME, { symbol });
24090
+ if (!ExecutionContextService.hasContext()) {
24091
+ throw new Error("getBacktestTimeframe requires an execution context");
24092
+ }
24093
+ if (!MethodContextService.hasContext()) {
24094
+ throw new Error("getBacktestTimeframe requires a method context");
24095
+ }
24096
+ if (!backtest$1.executionContextService.context.backtest) {
24097
+ throw new Error("getBacktestTimeframe can only be used during backtest execution");
24098
+ }
24099
+ return await backtest$1.frameCoreService.getTimeframe(symbol, backtest$1.methodContextService.context.frameName);
24100
+ }
24101
+
24102
+ const METHOD_NAME = "validate.validate";
24103
+ /**
24104
+ * Retrieves all registered exchanges as a map
24105
+ * @private
24106
+ * @returns Map of exchange names
24107
+ */
24108
+ const getExchangeMap = async () => {
24109
+ const exchangeMap = {};
24110
+ for (const { exchangeName } of await backtest$1.exchangeValidationService.list()) {
24111
+ Object.assign(exchangeMap, { [exchangeName]: exchangeName });
24112
+ }
24113
+ return exchangeMap;
24114
+ };
24115
+ /**
24116
+ * Retrieves all registered frames as a map
24117
+ * @private
24118
+ * @returns Map of frame names
24119
+ */
24120
+ const getFrameMap = async () => {
24121
+ const frameMap = {};
24122
+ for (const { frameName } of await backtest$1.frameValidationService.list()) {
24123
+ Object.assign(frameMap, { [frameName]: frameName });
24124
+ }
24125
+ return frameMap;
24126
+ };
24127
+ /**
24128
+ * Retrieves all registered strategies as a map
24129
+ * @private
24130
+ * @returns Map of strategy names
24131
+ */
23246
24132
  const getStrategyMap = async () => {
23247
24133
  const strategyMap = {};
23248
24134
  for (const { strategyName } of await backtest$1.strategyValidationService.list()) {
@@ -26425,6 +27311,446 @@ function listenActivePingOnce(filterFn, fn) {
26425
27311
  return activePingSubject.filter(filterFn).once(fn);
26426
27312
  }
26427
27313
 
27314
+ const METHOD_NAME_SIGNAL = "history.commitSignalPromptHistory";
27315
+ const METHOD_NAME_RISK = "history.commitRiskPromptHistory";
27316
+ const METHOD_NAME_TRAILING_TAKE = "history.commitTrailingTakePromptHistory";
27317
+ const METHOD_NAME_TRAILING_STOP = "history.commitTrailingStopPromptHistory";
27318
+ const METHOD_NAME_PARTIAL_PROFIT = "history.commitPartialProfitPromptHistory";
27319
+ const METHOD_NAME_PARTIAL_LOSS = "history.commitPartialLossPromptHistory";
27320
+ const METHOD_NAME_BREAKEVEN = "history.commitBreakevenPromptHistory";
27321
+ const METHOD_NAME_SCHEDULE_CANCEL = "history.commitScheduleCancelPromptHistory";
27322
+ /**
27323
+ * Commits signal prompt history to the message array.
27324
+ *
27325
+ * Extracts trading context from ExecutionContext and MethodContext,
27326
+ * then adds signal-specific system prompts at the beginning and user prompt
27327
+ * at the end of the history array if they are not empty.
27328
+ *
27329
+ * Context extraction:
27330
+ * - symbol: Provided as parameter for debugging convenience
27331
+ * - backtest mode: From ExecutionContext
27332
+ * - strategyName, exchangeName, frameName: From MethodContext
27333
+ *
27334
+ * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
27335
+ * @param history - Message array to append prompts to
27336
+ * @returns Promise that resolves when prompts are added
27337
+ * @throws Error if ExecutionContext or MethodContext is not active
27338
+ *
27339
+ * @example
27340
+ * ```typescript
27341
+ * const messages: MessageModel[] = [];
27342
+ * await commitSignalPromptHistory("BTCUSDT", messages);
27343
+ * // messages now contains system prompts at start and user prompt at end
27344
+ * ```
27345
+ */
27346
+ async function commitSignalPromptHistory(symbol, history) {
27347
+ backtest$1.loggerService.log(METHOD_NAME_SIGNAL, {
27348
+ symbol,
27349
+ });
27350
+ if (!ExecutionContextService.hasContext()) {
27351
+ throw new Error("commitSignalPromptHistory requires an execution context");
27352
+ }
27353
+ if (!MethodContextService.hasContext()) {
27354
+ throw new Error("commitSignalPromptHistory requires a method context");
27355
+ }
27356
+ const { backtest: isBacktest } = backtest$1.executionContextService.context;
27357
+ const { strategyName, exchangeName, frameName } = backtest$1.methodContextService.context;
27358
+ const systemPrompts = await backtest$1.signalPromptService.getSystemPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27359
+ const userPrompt = await backtest$1.signalPromptService.getUserPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27360
+ if (systemPrompts.length > 0) {
27361
+ for (const content of systemPrompts) {
27362
+ history.unshift({
27363
+ role: "system",
27364
+ content,
27365
+ });
27366
+ }
27367
+ }
27368
+ if (userPrompt && userPrompt.trim() !== "") {
27369
+ history.push({
27370
+ role: "user",
27371
+ content: userPrompt,
27372
+ });
27373
+ }
27374
+ }
27375
+ /**
27376
+ * Commits risk rejection prompt history to the message array.
27377
+ *
27378
+ * Extracts trading context from ExecutionContext and MethodContext,
27379
+ * then adds risk-specific system prompts at the beginning and user prompt
27380
+ * at the end of the history array if they are not empty.
27381
+ *
27382
+ * Context extraction:
27383
+ * - symbol: Provided as parameter for debugging convenience
27384
+ * - backtest mode: From ExecutionContext
27385
+ * - strategyName, exchangeName, frameName: From MethodContext
27386
+ *
27387
+ * Used for AI-powered analysis when signals fail risk validation.
27388
+ *
27389
+ * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
27390
+ * @param history - Message array to append prompts to
27391
+ * @returns Promise that resolves when prompts are added
27392
+ * @throws Error if ExecutionContext or MethodContext is not active
27393
+ *
27394
+ * @example
27395
+ * ```typescript
27396
+ * const messages: MessageModel[] = [];
27397
+ * await commitRiskPromptHistory("BTCUSDT", messages);
27398
+ * ```
27399
+ */
27400
+ async function commitRiskPromptHistory(symbol, history) {
27401
+ backtest$1.loggerService.log(METHOD_NAME_RISK, {
27402
+ symbol,
27403
+ });
27404
+ if (!ExecutionContextService.hasContext()) {
27405
+ throw new Error("commitRiskPromptHistory requires an execution context");
27406
+ }
27407
+ if (!MethodContextService.hasContext()) {
27408
+ throw new Error("commitRiskPromptHistory requires a method context");
27409
+ }
27410
+ const { backtest: isBacktest } = backtest$1.executionContextService.context;
27411
+ const { strategyName, exchangeName, frameName } = backtest$1.methodContextService.context;
27412
+ const systemPrompts = await backtest$1.riskPromptService.getSystemPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27413
+ const userPrompt = await backtest$1.riskPromptService.getUserPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27414
+ if (systemPrompts.length > 0) {
27415
+ for (const content of systemPrompts) {
27416
+ history.unshift({
27417
+ role: "system",
27418
+ content,
27419
+ });
27420
+ }
27421
+ }
27422
+ if (userPrompt && userPrompt.trim() !== "") {
27423
+ history.push({
27424
+ role: "user",
27425
+ content: userPrompt,
27426
+ });
27427
+ }
27428
+ }
27429
+ /**
27430
+ * Commits trailing take-profit prompt history to the message array.
27431
+ *
27432
+ * Extracts trading context from ExecutionContext and MethodContext,
27433
+ * then adds trailing take-profit specific system prompts at the beginning
27434
+ * and user prompt at the end of the history array if they are not empty.
27435
+ *
27436
+ * Context extraction:
27437
+ * - symbol: Provided as parameter for debugging convenience
27438
+ * - backtest mode: From ExecutionContext
27439
+ * - strategyName, exchangeName, frameName: From MethodContext
27440
+ *
27441
+ * Used for AI-powered analysis of trailing take-profit adjustments.
27442
+ *
27443
+ * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
27444
+ * @param history - Message array to append prompts to
27445
+ * @returns Promise that resolves when prompts are added
27446
+ * @throws Error if ExecutionContext or MethodContext is not active
27447
+ *
27448
+ * @example
27449
+ * ```typescript
27450
+ * const messages: MessageModel[] = [];
27451
+ * await commitTrailingTakePromptHistory("BTCUSDT", messages);
27452
+ * ```
27453
+ */
27454
+ async function commitTrailingTakePromptHistory(symbol, history) {
27455
+ backtest$1.loggerService.log(METHOD_NAME_TRAILING_TAKE, {
27456
+ symbol,
27457
+ });
27458
+ if (!ExecutionContextService.hasContext()) {
27459
+ throw new Error("commitTrailingTakePromptHistory requires an execution context");
27460
+ }
27461
+ if (!MethodContextService.hasContext()) {
27462
+ throw new Error("commitTrailingTakePromptHistory requires a method context");
27463
+ }
27464
+ const { backtest: isBacktest } = backtest$1.executionContextService.context;
27465
+ const { strategyName, exchangeName, frameName } = backtest$1.methodContextService.context;
27466
+ const systemPrompts = await backtest$1.trailingTakePromptService.getSystemPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27467
+ const userPrompt = await backtest$1.trailingTakePromptService.getUserPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27468
+ if (systemPrompts.length > 0) {
27469
+ for (const content of systemPrompts) {
27470
+ history.unshift({
27471
+ role: "system",
27472
+ content,
27473
+ });
27474
+ }
27475
+ }
27476
+ if (userPrompt && userPrompt.trim() !== "") {
27477
+ history.push({
27478
+ role: "user",
27479
+ content: userPrompt,
27480
+ });
27481
+ }
27482
+ }
27483
+ /**
27484
+ * Commits trailing stop-loss prompt history to the message array.
27485
+ *
27486
+ * Extracts trading context from ExecutionContext and MethodContext,
27487
+ * then adds trailing stop-loss specific system prompts at the beginning
27488
+ * and user prompt at the end of the history array if they are not empty.
27489
+ *
27490
+ * Context extraction:
27491
+ * - symbol: Provided as parameter for debugging convenience
27492
+ * - backtest mode: From ExecutionContext
27493
+ * - strategyName, exchangeName, frameName: From MethodContext
27494
+ *
27495
+ * Used for AI-powered analysis of trailing stop-loss adjustments.
27496
+ *
27497
+ * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
27498
+ * @param history - Message array to append prompts to
27499
+ * @returns Promise that resolves when prompts are added
27500
+ * @throws Error if ExecutionContext or MethodContext is not active
27501
+ *
27502
+ * @example
27503
+ * ```typescript
27504
+ * const messages: MessageModel[] = [];
27505
+ * await commitTrailingStopPromptHistory("BTCUSDT", messages);
27506
+ * ```
27507
+ */
27508
+ async function commitTrailingStopPromptHistory(symbol, history) {
27509
+ backtest$1.loggerService.log(METHOD_NAME_TRAILING_STOP, {
27510
+ symbol,
27511
+ });
27512
+ if (!ExecutionContextService.hasContext()) {
27513
+ throw new Error("commitTrailingStopPromptHistory requires an execution context");
27514
+ }
27515
+ if (!MethodContextService.hasContext()) {
27516
+ throw new Error("commitTrailingStopPromptHistory requires a method context");
27517
+ }
27518
+ const { backtest: isBacktest } = backtest$1.executionContextService.context;
27519
+ const { strategyName, exchangeName, frameName } = backtest$1.methodContextService.context;
27520
+ const systemPrompts = await backtest$1.trailingStopPromptService.getSystemPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27521
+ const userPrompt = await backtest$1.trailingStopPromptService.getUserPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27522
+ if (systemPrompts.length > 0) {
27523
+ for (const content of systemPrompts) {
27524
+ history.unshift({
27525
+ role: "system",
27526
+ content,
27527
+ });
27528
+ }
27529
+ }
27530
+ if (userPrompt && userPrompt.trim() !== "") {
27531
+ history.push({
27532
+ role: "user",
27533
+ content: userPrompt,
27534
+ });
27535
+ }
27536
+ }
27537
+ /**
27538
+ * Commits partial profit prompt history to the message array.
27539
+ *
27540
+ * Extracts trading context from ExecutionContext and MethodContext,
27541
+ * then adds partial profit specific system prompts at the beginning
27542
+ * and user prompt at the end of the history array if they are not empty.
27543
+ *
27544
+ * Context extraction:
27545
+ * - symbol: Provided as parameter for debugging convenience
27546
+ * - backtest mode: From ExecutionContext
27547
+ * - strategyName, exchangeName, frameName: From MethodContext
27548
+ *
27549
+ * Used for AI-powered analysis of partial profit milestones.
27550
+ *
27551
+ * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
27552
+ * @param history - Message array to append prompts to
27553
+ * @returns Promise that resolves when prompts are added
27554
+ * @throws Error if ExecutionContext or MethodContext is not active
27555
+ *
27556
+ * @example
27557
+ * ```typescript
27558
+ * const messages: MessageModel[] = [];
27559
+ * await commitPartialProfitPromptHistory("BTCUSDT", messages);
27560
+ * ```
27561
+ */
27562
+ async function commitPartialProfitPromptHistory(symbol, history) {
27563
+ backtest$1.loggerService.log(METHOD_NAME_PARTIAL_PROFIT, {
27564
+ symbol,
27565
+ });
27566
+ if (!ExecutionContextService.hasContext()) {
27567
+ throw new Error("commitPartialProfitPromptHistory requires an execution context");
27568
+ }
27569
+ if (!MethodContextService.hasContext()) {
27570
+ throw new Error("commitPartialProfitPromptHistory requires a method context");
27571
+ }
27572
+ const { backtest: isBacktest } = backtest$1.executionContextService.context;
27573
+ const { strategyName, exchangeName, frameName } = backtest$1.methodContextService.context;
27574
+ const systemPrompts = await backtest$1.partialProfitPromptService.getSystemPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27575
+ const userPrompt = await backtest$1.partialProfitPromptService.getUserPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27576
+ if (systemPrompts.length > 0) {
27577
+ for (const content of systemPrompts) {
27578
+ history.unshift({
27579
+ role: "system",
27580
+ content,
27581
+ });
27582
+ }
27583
+ }
27584
+ if (userPrompt && userPrompt.trim() !== "") {
27585
+ history.push({
27586
+ role: "user",
27587
+ content: userPrompt,
27588
+ });
27589
+ }
27590
+ }
27591
+ /**
27592
+ * Commits partial loss prompt history to the message array.
27593
+ *
27594
+ * Extracts trading context from ExecutionContext and MethodContext,
27595
+ * then adds partial loss specific system prompts at the beginning
27596
+ * and user prompt at the end of the history array if they are not empty.
27597
+ *
27598
+ * Context extraction:
27599
+ * - symbol: Provided as parameter for debugging convenience
27600
+ * - backtest mode: From ExecutionContext
27601
+ * - strategyName, exchangeName, frameName: From MethodContext
27602
+ *
27603
+ * Used for AI-powered analysis of partial loss milestones.
27604
+ *
27605
+ * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
27606
+ * @param history - Message array to append prompts to
27607
+ * @returns Promise that resolves when prompts are added
27608
+ * @throws Error if ExecutionContext or MethodContext is not active
27609
+ *
27610
+ * @example
27611
+ * ```typescript
27612
+ * const messages: MessageModel[] = [];
27613
+ * await commitPartialLossPromptHistory("BTCUSDT", messages);
27614
+ * ```
27615
+ */
27616
+ async function commitPartialLossPromptHistory(symbol, history) {
27617
+ backtest$1.loggerService.log(METHOD_NAME_PARTIAL_LOSS, {
27618
+ symbol,
27619
+ });
27620
+ if (!ExecutionContextService.hasContext()) {
27621
+ throw new Error("commitPartialLossPromptHistory requires an execution context");
27622
+ }
27623
+ if (!MethodContextService.hasContext()) {
27624
+ throw new Error("commitPartialLossPromptHistory requires a method context");
27625
+ }
27626
+ const { backtest: isBacktest } = backtest$1.executionContextService.context;
27627
+ const { strategyName, exchangeName, frameName } = backtest$1.methodContextService.context;
27628
+ const systemPrompts = await backtest$1.partialLossPromptService.getSystemPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27629
+ const userPrompt = await backtest$1.partialLossPromptService.getUserPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27630
+ if (systemPrompts.length > 0) {
27631
+ for (const content of systemPrompts) {
27632
+ history.unshift({
27633
+ role: "system",
27634
+ content,
27635
+ });
27636
+ }
27637
+ }
27638
+ if (userPrompt && userPrompt.trim() !== "") {
27639
+ history.push({
27640
+ role: "user",
27641
+ content: userPrompt,
27642
+ });
27643
+ }
27644
+ }
27645
+ /**
27646
+ * Commits breakeven prompt history to the message array.
27647
+ *
27648
+ * Extracts trading context from ExecutionContext and MethodContext,
27649
+ * then adds breakeven specific system prompts at the beginning
27650
+ * and user prompt at the end of the history array if they are not empty.
27651
+ *
27652
+ * Context extraction:
27653
+ * - symbol: Provided as parameter for debugging convenience
27654
+ * - backtest mode: From ExecutionContext
27655
+ * - strategyName, exchangeName, frameName: From MethodContext
27656
+ *
27657
+ * Used for AI-powered analysis of breakeven events.
27658
+ *
27659
+ * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
27660
+ * @param history - Message array to append prompts to
27661
+ * @returns Promise that resolves when prompts are added
27662
+ * @throws Error if ExecutionContext or MethodContext is not active
27663
+ *
27664
+ * @example
27665
+ * ```typescript
27666
+ * const messages: MessageModel[] = [];
27667
+ * await commitBreakevenPromptHistory("BTCUSDT", messages);
27668
+ * ```
27669
+ */
27670
+ async function commitBreakevenPromptHistory(symbol, history) {
27671
+ backtest$1.loggerService.log(METHOD_NAME_BREAKEVEN, {
27672
+ symbol,
27673
+ });
27674
+ if (!ExecutionContextService.hasContext()) {
27675
+ throw new Error("commitBreakevenPromptHistory requires an execution context");
27676
+ }
27677
+ if (!MethodContextService.hasContext()) {
27678
+ throw new Error("commitBreakevenPromptHistory requires a method context");
27679
+ }
27680
+ const { backtest: isBacktest } = backtest$1.executionContextService.context;
27681
+ const { strategyName, exchangeName, frameName } = backtest$1.methodContextService.context;
27682
+ const systemPrompts = await backtest$1.breakevenPromptService.getSystemPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27683
+ const userPrompt = await backtest$1.breakevenPromptService.getUserPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27684
+ if (systemPrompts.length > 0) {
27685
+ for (const content of systemPrompts) {
27686
+ history.unshift({
27687
+ role: "system",
27688
+ content,
27689
+ });
27690
+ }
27691
+ }
27692
+ if (userPrompt && userPrompt.trim() !== "") {
27693
+ history.push({
27694
+ role: "user",
27695
+ content: userPrompt,
27696
+ });
27697
+ }
27698
+ }
27699
+ /**
27700
+ * Commits schedule cancellation prompt history to the message array.
27701
+ *
27702
+ * Extracts trading context from ExecutionContext and MethodContext,
27703
+ * then adds schedule cancellation specific system prompts at the beginning
27704
+ * and user prompt at the end of the history array if they are not empty.
27705
+ *
27706
+ * Context extraction:
27707
+ * - symbol: Provided as parameter for debugging convenience
27708
+ * - backtest mode: From ExecutionContext
27709
+ * - strategyName, exchangeName, frameName: From MethodContext
27710
+ *
27711
+ * Used for AI-powered analysis of schedule cancellation events.
27712
+ *
27713
+ * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
27714
+ * @param history - Message array to append prompts to
27715
+ * @returns Promise that resolves when prompts are added
27716
+ * @throws Error if ExecutionContext or MethodContext is not active
27717
+ *
27718
+ * @example
27719
+ * ```typescript
27720
+ * const messages: MessageModel[] = [];
27721
+ * await commitScheduleCancelPromptHistory("BTCUSDT", messages);
27722
+ * ```
27723
+ */
27724
+ async function commitScheduleCancelPromptHistory(symbol, history) {
27725
+ backtest$1.loggerService.log(METHOD_NAME_SCHEDULE_CANCEL, {
27726
+ symbol,
27727
+ });
27728
+ if (!ExecutionContextService.hasContext()) {
27729
+ throw new Error("commitScheduleCancelPromptHistory requires an execution context");
27730
+ }
27731
+ if (!MethodContextService.hasContext()) {
27732
+ throw new Error("commitScheduleCancelPromptHistory requires a method context");
27733
+ }
27734
+ const { backtest: isBacktest } = backtest$1.executionContextService.context;
27735
+ const { strategyName, exchangeName, frameName } = backtest$1.methodContextService.context;
27736
+ const systemPrompts = await backtest$1.scheduleCancelPromptService.getSystemPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27737
+ const userPrompt = await backtest$1.scheduleCancelPromptService.getUserPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
27738
+ if (systemPrompts.length > 0) {
27739
+ for (const content of systemPrompts) {
27740
+ history.unshift({
27741
+ role: "system",
27742
+ content,
27743
+ });
27744
+ }
27745
+ }
27746
+ if (userPrompt && userPrompt.trim() !== "") {
27747
+ history.push({
27748
+ role: "user",
27749
+ content: userPrompt,
27750
+ });
27751
+ }
27752
+ }
27753
+
26428
27754
  const DUMP_SIGNAL_METHOD_NAME = "dump.dumpSignal";
26429
27755
  /**
26430
27756
  * Dumps signal data and LLM conversation history to markdown files.
@@ -31931,11 +33257,19 @@ exports.addSizingSchema = addSizingSchema;
31931
33257
  exports.addStrategySchema = addStrategySchema;
31932
33258
  exports.addWalkerSchema = addWalkerSchema;
31933
33259
  exports.commitBreakeven = commitBreakeven;
33260
+ exports.commitBreakevenPromptHistory = commitBreakevenPromptHistory;
31934
33261
  exports.commitCancel = commitCancel;
31935
33262
  exports.commitPartialLoss = commitPartialLoss;
33263
+ exports.commitPartialLossPromptHistory = commitPartialLossPromptHistory;
31936
33264
  exports.commitPartialProfit = commitPartialProfit;
33265
+ exports.commitPartialProfitPromptHistory = commitPartialProfitPromptHistory;
33266
+ exports.commitRiskPromptHistory = commitRiskPromptHistory;
33267
+ exports.commitScheduleCancelPromptHistory = commitScheduleCancelPromptHistory;
33268
+ exports.commitSignalPromptHistory = commitSignalPromptHistory;
31937
33269
  exports.commitTrailingStop = commitTrailingStop;
33270
+ exports.commitTrailingStopPromptHistory = commitTrailingStopPromptHistory;
31938
33271
  exports.commitTrailingTake = commitTrailingTake;
33272
+ exports.commitTrailingTakePromptHistory = commitTrailingTakePromptHistory;
31939
33273
  exports.dumpSignalData = dumpSignalData;
31940
33274
  exports.emitters = emitters;
31941
33275
  exports.formatPrice = formatPrice;