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