backtest-kit 2.0.9 → 2.0.11

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
@@ -155,13 +155,6 @@ const templateServices$1 = {
155
155
  };
156
156
  const promptServices$1 = {
157
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
158
  };
166
159
  const TYPES = {
167
160
  ...baseServices$1,
@@ -24048,12 +24041,12 @@ class RiskReportService {
24048
24041
  }
24049
24042
  }
24050
24043
 
24051
- 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)));
24044
+ 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)));
24052
24045
  /**
24053
24046
  * Default fallback prompt configuration.
24054
24047
  * Used when signal.prompt.cjs file is not found.
24055
24048
  */
24056
- const DEFAULT_PROMPT$7 = {
24049
+ const DEFAULT_PROMPT = {
24057
24050
  user: "",
24058
24051
  system: [],
24059
24052
  };
@@ -24063,15 +24056,15 @@ const DEFAULT_PROMPT$7 = {
24063
24056
  * Uses singleshot pattern to ensure configuration is loaded only once.
24064
24057
  * @returns Prompt configuration with system and user prompts
24065
24058
  */
24066
- const GET_PROMPT_FN$7 = functoolsKit.singleshot(() => {
24059
+ const GET_PROMPT_FN = functoolsKit.singleshot(() => {
24067
24060
  try {
24068
- const modulePath = require$8.resolve(path.join(process.cwd(), `./config/prompt/signal.prompt.cjs`));
24061
+ const modulePath = require$1.resolve(path.join(process.cwd(), `./config/prompt/signal.prompt.cjs`));
24069
24062
  console.log(`Using ${modulePath} implementation as signal.prompt.cjs`);
24070
- return require$8(modulePath);
24063
+ return require$1(modulePath);
24071
24064
  }
24072
24065
  catch (error) {
24073
24066
  console.log(`Using empty fallback for signal.prompt.cjs`, error);
24074
- return DEFAULT_PROMPT$7;
24067
+ return DEFAULT_PROMPT;
24075
24068
  }
24076
24069
  });
24077
24070
  /**
@@ -24114,753 +24107,6 @@ class SignalPromptService {
24114
24107
  frameName,
24115
24108
  backtest,
24116
24109
  });
24117
- const { system } = GET_PROMPT_FN$7();
24118
- if (Array.isArray(system)) {
24119
- return system;
24120
- }
24121
- if (typeof system === "function") {
24122
- return await system(symbol, strategyName, exchangeName, frameName, backtest);
24123
- }
24124
- return [];
24125
- };
24126
- /**
24127
- * Retrieves user prompt string for AI input.
24128
- *
24129
- * @param symbol - Trading symbol (e.g., "BTCUSDT")
24130
- * @param strategyName - Strategy identifier
24131
- * @param exchangeName - Exchange identifier
24132
- * @param frameName - Timeframe identifier
24133
- * @param backtest - Whether running in backtest mode
24134
- * @returns Promise resolving to user prompt string
24135
- */
24136
- this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
24137
- this.loggerService.log("signalPromptService getUserPrompt", {
24138
- symbol,
24139
- strategyName,
24140
- exchangeName,
24141
- frameName,
24142
- backtest,
24143
- });
24144
- const { user } = GET_PROMPT_FN$7();
24145
- if (typeof user === "string") {
24146
- return user;
24147
- }
24148
- if (typeof user === "function") {
24149
- return await user(symbol, strategyName, exchangeName, frameName, backtest);
24150
- }
24151
- return "";
24152
- };
24153
- }
24154
- }
24155
-
24156
- 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)));
24157
- /**
24158
- * Default fallback prompt configuration.
24159
- * Used when risk.prompt.cjs file is not found.
24160
- */
24161
- const DEFAULT_PROMPT$6 = {
24162
- user: "",
24163
- system: [],
24164
- };
24165
- /**
24166
- * Lazy-loads and caches risk rejection prompt configuration.
24167
- * Attempts to load from config/prompt/risk.prompt.cjs, falls back to DEFAULT_PROMPT if not found.
24168
- * Uses singleshot pattern to ensure configuration is loaded only once.
24169
- * @returns Prompt configuration with system and user prompts
24170
- */
24171
- const GET_PROMPT_FN$6 = functoolsKit.singleshot(() => {
24172
- try {
24173
- const modulePath = require$7.resolve(path.join(process.cwd(), `./config/prompt/risk.prompt.cjs`));
24174
- console.log(`Using ${modulePath} implementation as risk.prompt.cjs`);
24175
- return require$7(modulePath);
24176
- }
24177
- catch (error) {
24178
- console.log(`Using empty fallback for risk.prompt.cjs`, error);
24179
- return DEFAULT_PROMPT$6;
24180
- }
24181
- });
24182
- /**
24183
- * Service for managing risk rejection prompts for AI/LLM integrations.
24184
- *
24185
- * Provides access to system and user prompts configured in risk.prompt.cjs.
24186
- * Supports both static prompt arrays and dynamic prompt functions.
24187
- *
24188
- * Key responsibilities:
24189
- * - Lazy-loads prompt configuration from config/prompt/risk.prompt.cjs
24190
- * - Resolves system prompts (static arrays or async functions)
24191
- * - Provides user prompt strings
24192
- * - Falls back to empty prompts if configuration is missing
24193
- *
24194
- * Used for AI-powered analysis when signals fail risk validation.
24195
- * Triggered by: riskRejection() events in ActionBase
24196
- * Use cases: Analyze rejection reasons, suggest risk adjustments, track rejection patterns
24197
- */
24198
- class RiskPromptService {
24199
- constructor() {
24200
- this.loggerService = inject(TYPES.loggerService);
24201
- /**
24202
- * Retrieves system prompts for AI context.
24203
- *
24204
- * System prompts can be:
24205
- * - Static array of strings (returned directly)
24206
- * - Async/sync function returning string array (executed and awaited)
24207
- * - Undefined (returns empty array)
24208
- *
24209
- * @param symbol - Trading symbol (e.g., "BTCUSDT")
24210
- * @param strategyName - Strategy identifier
24211
- * @param exchangeName - Exchange identifier
24212
- * @param frameName - Timeframe identifier
24213
- * @param backtest - Whether running in backtest mode
24214
- * @returns Promise resolving to array of system prompt strings
24215
- */
24216
- this.getSystemPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
24217
- this.loggerService.log("riskPromptService getSystemPrompt", {
24218
- symbol,
24219
- strategyName,
24220
- exchangeName,
24221
- frameName,
24222
- backtest,
24223
- });
24224
- const { system } = GET_PROMPT_FN$6();
24225
- if (Array.isArray(system)) {
24226
- return system;
24227
- }
24228
- if (typeof system === "function") {
24229
- return await system(symbol, strategyName, exchangeName, frameName, backtest);
24230
- }
24231
- return [];
24232
- };
24233
- /**
24234
- * Retrieves user prompt string for AI input.
24235
- *
24236
- * @param symbol - Trading symbol (e.g., "BTCUSDT")
24237
- * @param strategyName - Strategy identifier
24238
- * @param exchangeName - Exchange identifier
24239
- * @param frameName - Timeframe identifier
24240
- * @param backtest - Whether running in backtest mode
24241
- * @returns Promise resolving to user prompt string
24242
- */
24243
- this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
24244
- this.loggerService.log("riskPromptService getUserPrompt", {
24245
- symbol,
24246
- strategyName,
24247
- exchangeName,
24248
- frameName,
24249
- backtest,
24250
- });
24251
- const { user } = GET_PROMPT_FN$6();
24252
- if (typeof user === "string") {
24253
- return user;
24254
- }
24255
- if (typeof user === "function") {
24256
- return await user(symbol, strategyName, exchangeName, frameName, backtest);
24257
- }
24258
- return "";
24259
- };
24260
- }
24261
- }
24262
-
24263
- 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)));
24264
- /**
24265
- * Default fallback prompt configuration.
24266
- * Used when trailing-take.prompt.cjs file is not found.
24267
- */
24268
- const DEFAULT_PROMPT$5 = {
24269
- user: "",
24270
- system: [],
24271
- };
24272
- /**
24273
- * Lazy-loads and caches trailing take-profit prompt configuration.
24274
- * Attempts to load from config/prompt/trailing-take.prompt.cjs, falls back to DEFAULT_PROMPT if not found.
24275
- * Uses singleshot pattern to ensure configuration is loaded only once.
24276
- * @returns Prompt configuration with system and user prompts
24277
- */
24278
- const GET_PROMPT_FN$5 = functoolsKit.singleshot(() => {
24279
- try {
24280
- const modulePath = require$6.resolve(path.join(process.cwd(), `./config/prompt/trailing-take.prompt.cjs`));
24281
- console.log(`Using ${modulePath} implementation as trailing-take.prompt.cjs`);
24282
- return require$6(modulePath);
24283
- }
24284
- catch (error) {
24285
- console.log(`Using empty fallback for trailing-take.prompt.cjs`, error);
24286
- return DEFAULT_PROMPT$5;
24287
- }
24288
- });
24289
- /**
24290
- * Service for managing trailing take-profit prompts for AI/LLM integrations.
24291
- *
24292
- * Provides access to system and user prompts configured in trailing-take.prompt.cjs.
24293
- * Supports both static prompt arrays and dynamic prompt functions.
24294
- *
24295
- * Key responsibilities:
24296
- * - Lazy-loads prompt configuration from config/prompt/trailing-take.prompt.cjs
24297
- * - Resolves system prompts (static arrays or async functions)
24298
- * - Provides user prompt strings
24299
- * - Falls back to empty prompts if configuration is missing
24300
- *
24301
- * Used for AI-powered analysis of trailing take-profit adjustments.
24302
- * Use cases: Suggest optimal trailing levels, analyze profit-taking strategies, optimize exit timing
24303
- */
24304
- class TrailingTakePromptService {
24305
- constructor() {
24306
- this.loggerService = inject(TYPES.loggerService);
24307
- /**
24308
- * Retrieves system prompts for AI context.
24309
- *
24310
- * System prompts can be:
24311
- * - Static array of strings (returned directly)
24312
- * - Async/sync function returning string array (executed and awaited)
24313
- * - Undefined (returns empty array)
24314
- *
24315
- * @param symbol - Trading symbol (e.g., "BTCUSDT")
24316
- * @param strategyName - Strategy identifier
24317
- * @param exchangeName - Exchange identifier
24318
- * @param frameName - Timeframe identifier
24319
- * @param backtest - Whether running in backtest mode
24320
- * @returns Promise resolving to array of system prompt strings
24321
- */
24322
- this.getSystemPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
24323
- this.loggerService.log("trailingTakePromptService getSystemPrompt", {
24324
- symbol,
24325
- strategyName,
24326
- exchangeName,
24327
- frameName,
24328
- backtest,
24329
- });
24330
- const { system } = GET_PROMPT_FN$5();
24331
- if (Array.isArray(system)) {
24332
- return system;
24333
- }
24334
- if (typeof system === "function") {
24335
- return await system(symbol, strategyName, exchangeName, frameName, backtest);
24336
- }
24337
- return [];
24338
- };
24339
- /**
24340
- * Retrieves user prompt string for AI input.
24341
- *
24342
- * @param symbol - Trading symbol (e.g., "BTCUSDT")
24343
- * @param strategyName - Strategy identifier
24344
- * @param exchangeName - Exchange identifier
24345
- * @param frameName - Timeframe identifier
24346
- * @param backtest - Whether running in backtest mode
24347
- * @returns Promise resolving to user prompt string
24348
- */
24349
- this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
24350
- this.loggerService.log("trailingTakePromptService getUserPrompt", {
24351
- symbol,
24352
- strategyName,
24353
- exchangeName,
24354
- frameName,
24355
- backtest,
24356
- });
24357
- const { user } = GET_PROMPT_FN$5();
24358
- if (typeof user === "string") {
24359
- return user;
24360
- }
24361
- if (typeof user === "function") {
24362
- return await user(symbol, strategyName, exchangeName, frameName, backtest);
24363
- }
24364
- return "";
24365
- };
24366
- }
24367
- }
24368
-
24369
- 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)));
24370
- /**
24371
- * Default fallback prompt configuration.
24372
- * Used when trailing-stop.prompt.cjs file is not found.
24373
- */
24374
- const DEFAULT_PROMPT$4 = {
24375
- user: "",
24376
- system: [],
24377
- };
24378
- /**
24379
- * Lazy-loads and caches trailing stop-loss prompt configuration.
24380
- * Attempts to load from config/prompt/trailing-stop.prompt.cjs, falls back to DEFAULT_PROMPT if not found.
24381
- * Uses singleshot pattern to ensure configuration is loaded only once.
24382
- * @returns Prompt configuration with system and user prompts
24383
- */
24384
- const GET_PROMPT_FN$4 = functoolsKit.singleshot(() => {
24385
- try {
24386
- const modulePath = require$5.resolve(path.join(process.cwd(), `./config/prompt/trailing-stop.prompt.cjs`));
24387
- console.log(`Using ${modulePath} implementation as trailing-stop.prompt.cjs`);
24388
- return require$5(modulePath);
24389
- }
24390
- catch (error) {
24391
- console.log(`Using empty fallback for trailing-stop.prompt.cjs`, error);
24392
- return DEFAULT_PROMPT$4;
24393
- }
24394
- });
24395
- /**
24396
- * Service for managing trailing stop-loss prompts for AI/LLM integrations.
24397
- *
24398
- * Provides access to system and user prompts configured in trailing-stop.prompt.cjs.
24399
- * Supports both static prompt arrays and dynamic prompt functions.
24400
- *
24401
- * Key responsibilities:
24402
- * - Lazy-loads prompt configuration from config/prompt/trailing-stop.prompt.cjs
24403
- * - Resolves system prompts (static arrays or async functions)
24404
- * - Provides user prompt strings
24405
- * - Falls back to empty prompts if configuration is missing
24406
- *
24407
- * Used for AI-powered analysis of trailing stop-loss adjustments.
24408
- * Use cases: Suggest optimal trailing distances, analyze risk protection strategies, optimize stop placement
24409
- */
24410
- class TrailingStopPromptService {
24411
- constructor() {
24412
- this.loggerService = inject(TYPES.loggerService);
24413
- /**
24414
- * Retrieves system prompts for AI context.
24415
- *
24416
- * System prompts can be:
24417
- * - Static array of strings (returned directly)
24418
- * - Async/sync function returning string array (executed and awaited)
24419
- * - Undefined (returns empty array)
24420
- *
24421
- * @param symbol - Trading symbol (e.g., "BTCUSDT")
24422
- * @param strategyName - Strategy identifier
24423
- * @param exchangeName - Exchange identifier
24424
- * @param frameName - Timeframe identifier
24425
- * @param backtest - Whether running in backtest mode
24426
- * @returns Promise resolving to array of system prompt strings
24427
- */
24428
- this.getSystemPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
24429
- this.loggerService.log("trailingStopPromptService getSystemPrompt", {
24430
- symbol,
24431
- strategyName,
24432
- exchangeName,
24433
- frameName,
24434
- backtest,
24435
- });
24436
- const { system } = GET_PROMPT_FN$4();
24437
- if (Array.isArray(system)) {
24438
- return system;
24439
- }
24440
- if (typeof system === "function") {
24441
- return await system(symbol, strategyName, exchangeName, frameName, backtest);
24442
- }
24443
- return [];
24444
- };
24445
- /**
24446
- * Retrieves user prompt string for AI input.
24447
- *
24448
- * @param symbol - Trading symbol (e.g., "BTCUSDT")
24449
- * @param strategyName - Strategy identifier
24450
- * @param exchangeName - Exchange identifier
24451
- * @param frameName - Timeframe identifier
24452
- * @param backtest - Whether running in backtest mode
24453
- * @returns Promise resolving to user prompt string
24454
- */
24455
- this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
24456
- this.loggerService.log("trailingStopPromptService getUserPrompt", {
24457
- symbol,
24458
- strategyName,
24459
- exchangeName,
24460
- frameName,
24461
- backtest,
24462
- });
24463
- const { user } = GET_PROMPT_FN$4();
24464
- if (typeof user === "string") {
24465
- return user;
24466
- }
24467
- if (typeof user === "function") {
24468
- return await user(symbol, strategyName, exchangeName, frameName, backtest);
24469
- }
24470
- return "";
24471
- };
24472
- }
24473
- }
24474
-
24475
- 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)));
24476
- /**
24477
- * Default fallback prompt configuration.
24478
- * Used when partial-profit.prompt.cjs file is not found.
24479
- */
24480
- const DEFAULT_PROMPT$3 = {
24481
- user: "",
24482
- system: [],
24483
- };
24484
- /**
24485
- * Lazy-loads and caches partial profit prompt configuration.
24486
- * Attempts to load from config/prompt/partial-profit.prompt.cjs, falls back to DEFAULT_PROMPT if not found.
24487
- * Uses singleshot pattern to ensure configuration is loaded only once.
24488
- * @returns Prompt configuration with system and user prompts
24489
- */
24490
- const GET_PROMPT_FN$3 = functoolsKit.singleshot(() => {
24491
- try {
24492
- const modulePath = require$4.resolve(path.join(process.cwd(), `./config/prompt/partial-profit.prompt.cjs`));
24493
- console.log(`Using ${modulePath} implementation as partial-profit.prompt.cjs`);
24494
- return require$4(modulePath);
24495
- }
24496
- catch (error) {
24497
- console.log(`Using empty fallback for partial-profit.prompt.cjs`, error);
24498
- return DEFAULT_PROMPT$3;
24499
- }
24500
- });
24501
- /**
24502
- * Service for managing partial profit prompts for AI/LLM integrations.
24503
- *
24504
- * Provides access to system and user prompts configured in partial-profit.prompt.cjs.
24505
- * Supports both static prompt arrays and dynamic prompt functions.
24506
- *
24507
- * Key responsibilities:
24508
- * - Lazy-loads prompt configuration from config/prompt/partial-profit.prompt.cjs
24509
- * - Resolves system prompts (static arrays or async functions)
24510
- * - Provides user prompt strings
24511
- * - Falls back to empty prompts if configuration is missing
24512
- *
24513
- * Used for AI-powered analysis when profit milestones are reached (10%, 20%, 30%, etc).
24514
- * Triggered by: partialProfitAvailable() events in ActionBase
24515
- * Use cases: Suggest position adjustments, analyze profit-taking opportunities, optimize milestone actions
24516
- */
24517
- class PartialProfitPromptService {
24518
- constructor() {
24519
- this.loggerService = inject(TYPES.loggerService);
24520
- /**
24521
- * Retrieves system prompts for AI context.
24522
- *
24523
- * System prompts can be:
24524
- * - Static array of strings (returned directly)
24525
- * - Async/sync function returning string array (executed and awaited)
24526
- * - Undefined (returns empty array)
24527
- *
24528
- * @param symbol - Trading symbol (e.g., "BTCUSDT")
24529
- * @param strategyName - Strategy identifier
24530
- * @param exchangeName - Exchange identifier
24531
- * @param frameName - Timeframe identifier
24532
- * @param backtest - Whether running in backtest mode
24533
- * @returns Promise resolving to array of system prompt strings
24534
- */
24535
- this.getSystemPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
24536
- this.loggerService.log("partialProfitPromptService getSystemPrompt", {
24537
- symbol,
24538
- strategyName,
24539
- exchangeName,
24540
- frameName,
24541
- backtest,
24542
- });
24543
- const { system } = GET_PROMPT_FN$3();
24544
- if (Array.isArray(system)) {
24545
- return system;
24546
- }
24547
- if (typeof system === "function") {
24548
- return await system(symbol, strategyName, exchangeName, frameName, backtest);
24549
- }
24550
- return [];
24551
- };
24552
- /**
24553
- * Retrieves user prompt string for AI input.
24554
- *
24555
- * @param symbol - Trading symbol (e.g., "BTCUSDT")
24556
- * @param strategyName - Strategy identifier
24557
- * @param exchangeName - Exchange identifier
24558
- * @param frameName - Timeframe identifier
24559
- * @param backtest - Whether running in backtest mode
24560
- * @returns Promise resolving to user prompt string
24561
- */
24562
- this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
24563
- this.loggerService.log("partialProfitPromptService getUserPrompt", {
24564
- symbol,
24565
- strategyName,
24566
- exchangeName,
24567
- frameName,
24568
- backtest,
24569
- });
24570
- const { user } = GET_PROMPT_FN$3();
24571
- if (typeof user === "string") {
24572
- return user;
24573
- }
24574
- if (typeof user === "function") {
24575
- return await user(symbol, strategyName, exchangeName, frameName, backtest);
24576
- }
24577
- return "";
24578
- };
24579
- }
24580
- }
24581
-
24582
- 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)));
24583
- /**
24584
- * Default fallback prompt configuration.
24585
- * Used when partial-loss.prompt.cjs file is not found.
24586
- */
24587
- const DEFAULT_PROMPT$2 = {
24588
- user: "",
24589
- system: [],
24590
- };
24591
- /**
24592
- * Lazy-loads and caches partial loss prompt configuration.
24593
- * Attempts to load from config/prompt/partial-loss.prompt.cjs, falls back to DEFAULT_PROMPT if not found.
24594
- * Uses singleshot pattern to ensure configuration is loaded only once.
24595
- * @returns Prompt configuration with system and user prompts
24596
- */
24597
- const GET_PROMPT_FN$2 = functoolsKit.singleshot(() => {
24598
- try {
24599
- const modulePath = require$3.resolve(path.join(process.cwd(), `./config/prompt/partial-loss.prompt.cjs`));
24600
- console.log(`Using ${modulePath} implementation as partial-loss.prompt.cjs`);
24601
- return require$3(modulePath);
24602
- }
24603
- catch (error) {
24604
- console.log(`Using empty fallback for partial-loss.prompt.cjs`, error);
24605
- return DEFAULT_PROMPT$2;
24606
- }
24607
- });
24608
- /**
24609
- * Service for managing partial loss prompts for AI/LLM integrations.
24610
- *
24611
- * Provides access to system and user prompts configured in partial-loss.prompt.cjs.
24612
- * Supports both static prompt arrays and dynamic prompt functions.
24613
- *
24614
- * Key responsibilities:
24615
- * - Lazy-loads prompt configuration from config/prompt/partial-loss.prompt.cjs
24616
- * - Resolves system prompts (static arrays or async functions)
24617
- * - Provides user prompt strings
24618
- * - Falls back to empty prompts if configuration is missing
24619
- *
24620
- * Used for AI-powered analysis when loss milestones are reached (-10%, -20%, -30%, etc).
24621
- * Triggered by: partialLossAvailable() events in ActionBase
24622
- * Use cases: Suggest risk management actions, analyze loss mitigation strategies, optimize exit decisions
24623
- */
24624
- class PartialLossPromptService {
24625
- constructor() {
24626
- this.loggerService = inject(TYPES.loggerService);
24627
- /**
24628
- * Retrieves system prompts for AI context.
24629
- *
24630
- * System prompts can be:
24631
- * - Static array of strings (returned directly)
24632
- * - Async/sync function returning string array (executed and awaited)
24633
- * - Undefined (returns empty array)
24634
- *
24635
- * @param symbol - Trading symbol (e.g., "BTCUSDT")
24636
- * @param strategyName - Strategy identifier
24637
- * @param exchangeName - Exchange identifier
24638
- * @param frameName - Timeframe identifier
24639
- * @param backtest - Whether running in backtest mode
24640
- * @returns Promise resolving to array of system prompt strings
24641
- */
24642
- this.getSystemPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
24643
- this.loggerService.log("partialLossPromptService getSystemPrompt", {
24644
- symbol,
24645
- strategyName,
24646
- exchangeName,
24647
- frameName,
24648
- backtest,
24649
- });
24650
- const { system } = GET_PROMPT_FN$2();
24651
- if (Array.isArray(system)) {
24652
- return system;
24653
- }
24654
- if (typeof system === "function") {
24655
- return await system(symbol, strategyName, exchangeName, frameName, backtest);
24656
- }
24657
- return [];
24658
- };
24659
- /**
24660
- * Retrieves user prompt string for AI input.
24661
- *
24662
- * @param symbol - Trading symbol (e.g., "BTCUSDT")
24663
- * @param strategyName - Strategy identifier
24664
- * @param exchangeName - Exchange identifier
24665
- * @param frameName - Timeframe identifier
24666
- * @param backtest - Whether running in backtest mode
24667
- * @returns Promise resolving to user prompt string
24668
- */
24669
- this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
24670
- this.loggerService.log("partialLossPromptService getUserPrompt", {
24671
- symbol,
24672
- strategyName,
24673
- exchangeName,
24674
- frameName,
24675
- backtest,
24676
- });
24677
- const { user } = GET_PROMPT_FN$2();
24678
- if (typeof user === "string") {
24679
- return user;
24680
- }
24681
- if (typeof user === "function") {
24682
- return await user(symbol, strategyName, exchangeName, frameName, backtest);
24683
- }
24684
- return "";
24685
- };
24686
- }
24687
- }
24688
-
24689
- 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)));
24690
- /**
24691
- * Default fallback prompt configuration.
24692
- * Used when breakeven.prompt.cjs file is not found.
24693
- */
24694
- const DEFAULT_PROMPT$1 = {
24695
- user: "",
24696
- system: [],
24697
- };
24698
- /**
24699
- * Lazy-loads and caches breakeven prompt configuration.
24700
- * Attempts to load from config/prompt/breakeven.prompt.cjs, falls back to DEFAULT_PROMPT if not found.
24701
- * Uses singleshot pattern to ensure configuration is loaded only once.
24702
- * @returns Prompt configuration with system and user prompts
24703
- */
24704
- const GET_PROMPT_FN$1 = functoolsKit.singleshot(() => {
24705
- try {
24706
- const modulePath = require$2.resolve(path.join(process.cwd(), `./config/prompt/breakeven.prompt.cjs`));
24707
- console.log(`Using ${modulePath} implementation as breakeven.prompt.cjs`);
24708
- return require$2(modulePath);
24709
- }
24710
- catch (error) {
24711
- console.log(`Using empty fallback for breakeven.prompt.cjs`, error);
24712
- return DEFAULT_PROMPT$1;
24713
- }
24714
- });
24715
- /**
24716
- * Service for managing breakeven prompts for AI/LLM integrations.
24717
- *
24718
- * Provides access to system and user prompts configured in breakeven.prompt.cjs.
24719
- * Supports both static prompt arrays and dynamic prompt functions.
24720
- *
24721
- * Key responsibilities:
24722
- * - Lazy-loads prompt configuration from config/prompt/breakeven.prompt.cjs
24723
- * - Resolves system prompts (static arrays or async functions)
24724
- * - Provides user prompt strings
24725
- * - Falls back to empty prompts if configuration is missing
24726
- *
24727
- * Used for AI-powered analysis when stop-loss is moved to entry price (risk-free position).
24728
- * Triggered by: breakevenAvailable() events in ActionBase
24729
- * Use cases: Suggest position management after breakeven, analyze profit potential, optimize trailing strategies
24730
- */
24731
- class BreakevenPromptService {
24732
- constructor() {
24733
- this.loggerService = inject(TYPES.loggerService);
24734
- /**
24735
- * Retrieves system prompts for AI context.
24736
- *
24737
- * System prompts can be:
24738
- * - Static array of strings (returned directly)
24739
- * - Async/sync function returning string array (executed and awaited)
24740
- * - Undefined (returns empty array)
24741
- *
24742
- * @param symbol - Trading symbol (e.g., "BTCUSDT")
24743
- * @param strategyName - Strategy identifier
24744
- * @param exchangeName - Exchange identifier
24745
- * @param frameName - Timeframe identifier
24746
- * @param backtest - Whether running in backtest mode
24747
- * @returns Promise resolving to array of system prompt strings
24748
- */
24749
- this.getSystemPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
24750
- this.loggerService.log("breakevenPromptService getSystemPrompt", {
24751
- symbol,
24752
- strategyName,
24753
- exchangeName,
24754
- frameName,
24755
- backtest,
24756
- });
24757
- const { system } = GET_PROMPT_FN$1();
24758
- if (Array.isArray(system)) {
24759
- return system;
24760
- }
24761
- if (typeof system === "function") {
24762
- return await system(symbol, strategyName, exchangeName, frameName, backtest);
24763
- }
24764
- return [];
24765
- };
24766
- /**
24767
- * Retrieves user prompt string for AI input.
24768
- *
24769
- * @param symbol - Trading symbol (e.g., "BTCUSDT")
24770
- * @param strategyName - Strategy identifier
24771
- * @param exchangeName - Exchange identifier
24772
- * @param frameName - Timeframe identifier
24773
- * @param backtest - Whether running in backtest mode
24774
- * @returns Promise resolving to user prompt string
24775
- */
24776
- this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
24777
- this.loggerService.log("breakevenPromptService getUserPrompt", {
24778
- symbol,
24779
- strategyName,
24780
- exchangeName,
24781
- frameName,
24782
- backtest,
24783
- });
24784
- const { user } = GET_PROMPT_FN$1();
24785
- if (typeof user === "string") {
24786
- return user;
24787
- }
24788
- if (typeof user === "function") {
24789
- return await user(symbol, strategyName, exchangeName, frameName, backtest);
24790
- }
24791
- return "";
24792
- };
24793
- }
24794
- }
24795
-
24796
- 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)));
24797
- /**
24798
- * Default fallback prompt configuration.
24799
- * Used when schedule-cancel.prompt.cjs file is not found.
24800
- */
24801
- const DEFAULT_PROMPT = {
24802
- user: "",
24803
- system: [],
24804
- };
24805
- /**
24806
- * Lazy-loads and caches schedule cancellation prompt configuration.
24807
- * Attempts to load from config/prompt/schedule-cancel.prompt.cjs, falls back to DEFAULT_PROMPT if not found.
24808
- * Uses singleshot pattern to ensure configuration is loaded only once.
24809
- * @returns Prompt configuration with system and user prompts
24810
- */
24811
- const GET_PROMPT_FN = functoolsKit.singleshot(() => {
24812
- try {
24813
- const modulePath = require$1.resolve(path.join(process.cwd(), `./config/prompt/schedule-cancel.prompt.cjs`));
24814
- console.log(`Using ${modulePath} implementation as schedule-cancel.prompt.cjs`);
24815
- return require$1(modulePath);
24816
- }
24817
- catch (error) {
24818
- console.log(`Using empty fallback for schedule-cancel.prompt.cjs`, error);
24819
- return DEFAULT_PROMPT;
24820
- }
24821
- });
24822
- /**
24823
- * Service for managing schedule cancellation prompts for AI/LLM integrations.
24824
- *
24825
- * Provides access to system and user prompts configured in schedule-cancel.prompt.cjs.
24826
- * Supports both static prompt arrays and dynamic prompt functions.
24827
- *
24828
- * Key responsibilities:
24829
- * - Lazy-loads prompt configuration from config/prompt/schedule-cancel.prompt.cjs
24830
- * - Resolves system prompts (static arrays or async functions)
24831
- * - Provides user prompt strings
24832
- * - Falls back to empty prompts if configuration is missing
24833
- *
24834
- * Used for AI-powered analysis when scheduled signals are cancelled before activation.
24835
- * Triggered by: signal() events with action='cancelled' in ActionBase
24836
- * Use cases: Analyze cancellation reasons, track signal invalidation patterns, optimize scheduling logic
24837
- */
24838
- class ScheduleCancelPromptService {
24839
- constructor() {
24840
- this.loggerService = inject(TYPES.loggerService);
24841
- /**
24842
- * Retrieves system prompts for AI context.
24843
- *
24844
- * System prompts can be:
24845
- * - Static array of strings (returned directly)
24846
- * - Async/sync function returning string array (executed and awaited)
24847
- * - Undefined (returns empty array)
24848
- *
24849
- * @param symbol - Trading symbol (e.g., "BTCUSDT")
24850
- * @param strategyName - Strategy identifier
24851
- * @param exchangeName - Exchange identifier
24852
- * @param frameName - Timeframe identifier
24853
- * @param backtest - Whether running in backtest mode
24854
- * @returns Promise resolving to array of system prompt strings
24855
- */
24856
- this.getSystemPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
24857
- this.loggerService.log("scheduleCancelPromptService getSystemPrompt", {
24858
- symbol,
24859
- strategyName,
24860
- exchangeName,
24861
- frameName,
24862
- backtest,
24863
- });
24864
24110
  const { system } = GET_PROMPT_FN();
24865
24111
  if (Array.isArray(system)) {
24866
24112
  return system;
@@ -24881,7 +24127,7 @@ class ScheduleCancelPromptService {
24881
24127
  * @returns Promise resolving to user prompt string
24882
24128
  */
24883
24129
  this.getUserPrompt = async (symbol, strategyName, exchangeName, frameName, backtest) => {
24884
- this.loggerService.log("scheduleCancelPromptService getUserPrompt", {
24130
+ this.loggerService.log("signalPromptService getUserPrompt", {
24885
24131
  symbol,
24886
24132
  strategyName,
24887
24133
  exchangeName,
@@ -24996,13 +24242,6 @@ class ScheduleCancelPromptService {
24996
24242
  }
24997
24243
  {
24998
24244
  provide(TYPES.signalPromptService, () => new SignalPromptService());
24999
- provide(TYPES.riskPromptService, () => new RiskPromptService());
25000
- provide(TYPES.trailingTakePromptService, () => new TrailingTakePromptService());
25001
- provide(TYPES.trailingStopPromptService, () => new TrailingStopPromptService());
25002
- provide(TYPES.partialProfitPromptService, () => new PartialProfitPromptService());
25003
- provide(TYPES.partialLossPromptService, () => new PartialLossPromptService());
25004
- provide(TYPES.breakevenPromptService, () => new BreakevenPromptService());
25005
- provide(TYPES.scheduleCancelPromptService, () => new ScheduleCancelPromptService());
25006
24245
  }
25007
24246
 
25008
24247
  const baseServices = {
@@ -25101,13 +24340,6 @@ const templateServices = {
25101
24340
  };
25102
24341
  const promptServices = {
25103
24342
  signalPromptService: inject(TYPES.signalPromptService),
25104
- riskPromptService: inject(TYPES.riskPromptService),
25105
- trailingTakePromptService: inject(TYPES.trailingTakePromptService),
25106
- trailingStopPromptService: inject(TYPES.trailingStopPromptService),
25107
- partialProfitPromptService: inject(TYPES.partialProfitPromptService),
25108
- partialLossPromptService: inject(TYPES.partialLossPromptService),
25109
- breakevenPromptService: inject(TYPES.breakevenPromptService),
25110
- scheduleCancelPromptService: inject(TYPES.scheduleCancelPromptService),
25111
24343
  };
25112
24344
  const backtest = {
25113
24345
  ...baseServices,
@@ -28362,13 +27594,6 @@ function listenActivePingOnce(filterFn, fn) {
28362
27594
  }
28363
27595
 
28364
27596
  const METHOD_NAME_SIGNAL = "history.commitSignalPromptHistory";
28365
- const METHOD_NAME_RISK = "history.commitRiskPromptHistory";
28366
- const METHOD_NAME_TRAILING_TAKE = "history.commitTrailingTakePromptHistory";
28367
- const METHOD_NAME_TRAILING_STOP = "history.commitTrailingStopPromptHistory";
28368
- const METHOD_NAME_PARTIAL_PROFIT = "history.commitPartialProfitPromptHistory";
28369
- const METHOD_NAME_PARTIAL_LOSS = "history.commitPartialLossPromptHistory";
28370
- const METHOD_NAME_BREAKEVEN = "history.commitBreakevenPromptHistory";
28371
- const METHOD_NAME_SCHEDULE_CANCEL = "history.commitScheduleCancelPromptHistory";
28372
27597
  /**
28373
27598
  * Commits signal prompt history to the message array.
28374
27599
  *
@@ -28422,384 +27647,6 @@ async function commitSignalPromptHistory(symbol, history) {
28422
27647
  });
28423
27648
  }
28424
27649
  }
28425
- /**
28426
- * Commits risk rejection prompt history to the message array.
28427
- *
28428
- * Extracts trading context from ExecutionContext and MethodContext,
28429
- * then adds risk-specific system prompts at the beginning and user prompt
28430
- * at the end of the history array if they are not empty.
28431
- *
28432
- * Context extraction:
28433
- * - symbol: Provided as parameter for debugging convenience
28434
- * - backtest mode: From ExecutionContext
28435
- * - strategyName, exchangeName, frameName: From MethodContext
28436
- *
28437
- * Used for AI-powered analysis when signals fail risk validation.
28438
- *
28439
- * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
28440
- * @param history - Message array to append prompts to
28441
- * @returns Promise that resolves when prompts are added
28442
- * @throws Error if ExecutionContext or MethodContext is not active
28443
- *
28444
- * @example
28445
- * ```typescript
28446
- * const messages: MessageModel[] = [];
28447
- * await commitRiskPromptHistory("BTCUSDT", messages);
28448
- * ```
28449
- */
28450
- async function commitRiskPromptHistory(symbol, history) {
28451
- bt.loggerService.log(METHOD_NAME_RISK, {
28452
- symbol,
28453
- });
28454
- if (!ExecutionContextService.hasContext()) {
28455
- throw new Error("commitRiskPromptHistory requires an execution context");
28456
- }
28457
- if (!MethodContextService.hasContext()) {
28458
- throw new Error("commitRiskPromptHistory requires a method context");
28459
- }
28460
- const { backtest: isBacktest } = bt.executionContextService.context;
28461
- const { strategyName, exchangeName, frameName } = bt.methodContextService.context;
28462
- const systemPrompts = await bt.riskPromptService.getSystemPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
28463
- const userPrompt = await bt.riskPromptService.getUserPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
28464
- if (systemPrompts.length > 0) {
28465
- for (const content of systemPrompts) {
28466
- history.unshift({
28467
- role: "system",
28468
- content,
28469
- });
28470
- }
28471
- }
28472
- if (userPrompt && userPrompt.trim() !== "") {
28473
- history.push({
28474
- role: "user",
28475
- content: userPrompt,
28476
- });
28477
- }
28478
- }
28479
- /**
28480
- * Commits trailing take-profit prompt history to the message array.
28481
- *
28482
- * Extracts trading context from ExecutionContext and MethodContext,
28483
- * then adds trailing take-profit specific system prompts at the beginning
28484
- * and user prompt at the end of the history array if they are not empty.
28485
- *
28486
- * Context extraction:
28487
- * - symbol: Provided as parameter for debugging convenience
28488
- * - backtest mode: From ExecutionContext
28489
- * - strategyName, exchangeName, frameName: From MethodContext
28490
- *
28491
- * Used for AI-powered analysis of trailing take-profit adjustments.
28492
- *
28493
- * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
28494
- * @param history - Message array to append prompts to
28495
- * @returns Promise that resolves when prompts are added
28496
- * @throws Error if ExecutionContext or MethodContext is not active
28497
- *
28498
- * @example
28499
- * ```typescript
28500
- * const messages: MessageModel[] = [];
28501
- * await commitTrailingTakePromptHistory("BTCUSDT", messages);
28502
- * ```
28503
- */
28504
- async function commitTrailingTakePromptHistory(symbol, history) {
28505
- bt.loggerService.log(METHOD_NAME_TRAILING_TAKE, {
28506
- symbol,
28507
- });
28508
- if (!ExecutionContextService.hasContext()) {
28509
- throw new Error("commitTrailingTakePromptHistory requires an execution context");
28510
- }
28511
- if (!MethodContextService.hasContext()) {
28512
- throw new Error("commitTrailingTakePromptHistory requires a method context");
28513
- }
28514
- const { backtest: isBacktest } = bt.executionContextService.context;
28515
- const { strategyName, exchangeName, frameName } = bt.methodContextService.context;
28516
- const systemPrompts = await bt.trailingTakePromptService.getSystemPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
28517
- const userPrompt = await bt.trailingTakePromptService.getUserPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
28518
- if (systemPrompts.length > 0) {
28519
- for (const content of systemPrompts) {
28520
- history.unshift({
28521
- role: "system",
28522
- content,
28523
- });
28524
- }
28525
- }
28526
- if (userPrompt && userPrompt.trim() !== "") {
28527
- history.push({
28528
- role: "user",
28529
- content: userPrompt,
28530
- });
28531
- }
28532
- }
28533
- /**
28534
- * Commits trailing stop-loss prompt history to the message array.
28535
- *
28536
- * Extracts trading context from ExecutionContext and MethodContext,
28537
- * then adds trailing stop-loss specific system prompts at the beginning
28538
- * and user prompt at the end of the history array if they are not empty.
28539
- *
28540
- * Context extraction:
28541
- * - symbol: Provided as parameter for debugging convenience
28542
- * - backtest mode: From ExecutionContext
28543
- * - strategyName, exchangeName, frameName: From MethodContext
28544
- *
28545
- * Used for AI-powered analysis of trailing stop-loss adjustments.
28546
- *
28547
- * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
28548
- * @param history - Message array to append prompts to
28549
- * @returns Promise that resolves when prompts are added
28550
- * @throws Error if ExecutionContext or MethodContext is not active
28551
- *
28552
- * @example
28553
- * ```typescript
28554
- * const messages: MessageModel[] = [];
28555
- * await commitTrailingStopPromptHistory("BTCUSDT", messages);
28556
- * ```
28557
- */
28558
- async function commitTrailingStopPromptHistory(symbol, history) {
28559
- bt.loggerService.log(METHOD_NAME_TRAILING_STOP, {
28560
- symbol,
28561
- });
28562
- if (!ExecutionContextService.hasContext()) {
28563
- throw new Error("commitTrailingStopPromptHistory requires an execution context");
28564
- }
28565
- if (!MethodContextService.hasContext()) {
28566
- throw new Error("commitTrailingStopPromptHistory requires a method context");
28567
- }
28568
- const { backtest: isBacktest } = bt.executionContextService.context;
28569
- const { strategyName, exchangeName, frameName } = bt.methodContextService.context;
28570
- const systemPrompts = await bt.trailingStopPromptService.getSystemPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
28571
- const userPrompt = await bt.trailingStopPromptService.getUserPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
28572
- if (systemPrompts.length > 0) {
28573
- for (const content of systemPrompts) {
28574
- history.unshift({
28575
- role: "system",
28576
- content,
28577
- });
28578
- }
28579
- }
28580
- if (userPrompt && userPrompt.trim() !== "") {
28581
- history.push({
28582
- role: "user",
28583
- content: userPrompt,
28584
- });
28585
- }
28586
- }
28587
- /**
28588
- * Commits partial profit prompt history to the message array.
28589
- *
28590
- * Extracts trading context from ExecutionContext and MethodContext,
28591
- * then adds partial profit specific system prompts at the beginning
28592
- * and user prompt at the end of the history array if they are not empty.
28593
- *
28594
- * Context extraction:
28595
- * - symbol: Provided as parameter for debugging convenience
28596
- * - backtest mode: From ExecutionContext
28597
- * - strategyName, exchangeName, frameName: From MethodContext
28598
- *
28599
- * Used for AI-powered analysis of partial profit milestones.
28600
- *
28601
- * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
28602
- * @param history - Message array to append prompts to
28603
- * @returns Promise that resolves when prompts are added
28604
- * @throws Error if ExecutionContext or MethodContext is not active
28605
- *
28606
- * @example
28607
- * ```typescript
28608
- * const messages: MessageModel[] = [];
28609
- * await commitPartialProfitPromptHistory("BTCUSDT", messages);
28610
- * ```
28611
- */
28612
- async function commitPartialProfitPromptHistory(symbol, history) {
28613
- bt.loggerService.log(METHOD_NAME_PARTIAL_PROFIT, {
28614
- symbol,
28615
- });
28616
- if (!ExecutionContextService.hasContext()) {
28617
- throw new Error("commitPartialProfitPromptHistory requires an execution context");
28618
- }
28619
- if (!MethodContextService.hasContext()) {
28620
- throw new Error("commitPartialProfitPromptHistory requires a method context");
28621
- }
28622
- const { backtest: isBacktest } = bt.executionContextService.context;
28623
- const { strategyName, exchangeName, frameName } = bt.methodContextService.context;
28624
- const systemPrompts = await bt.partialProfitPromptService.getSystemPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
28625
- const userPrompt = await bt.partialProfitPromptService.getUserPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
28626
- if (systemPrompts.length > 0) {
28627
- for (const content of systemPrompts) {
28628
- history.unshift({
28629
- role: "system",
28630
- content,
28631
- });
28632
- }
28633
- }
28634
- if (userPrompt && userPrompt.trim() !== "") {
28635
- history.push({
28636
- role: "user",
28637
- content: userPrompt,
28638
- });
28639
- }
28640
- }
28641
- /**
28642
- * Commits partial loss prompt history to the message array.
28643
- *
28644
- * Extracts trading context from ExecutionContext and MethodContext,
28645
- * then adds partial loss specific system prompts at the beginning
28646
- * and user prompt at the end of the history array if they are not empty.
28647
- *
28648
- * Context extraction:
28649
- * - symbol: Provided as parameter for debugging convenience
28650
- * - backtest mode: From ExecutionContext
28651
- * - strategyName, exchangeName, frameName: From MethodContext
28652
- *
28653
- * Used for AI-powered analysis of partial loss milestones.
28654
- *
28655
- * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
28656
- * @param history - Message array to append prompts to
28657
- * @returns Promise that resolves when prompts are added
28658
- * @throws Error if ExecutionContext or MethodContext is not active
28659
- *
28660
- * @example
28661
- * ```typescript
28662
- * const messages: MessageModel[] = [];
28663
- * await commitPartialLossPromptHistory("BTCUSDT", messages);
28664
- * ```
28665
- */
28666
- async function commitPartialLossPromptHistory(symbol, history) {
28667
- bt.loggerService.log(METHOD_NAME_PARTIAL_LOSS, {
28668
- symbol,
28669
- });
28670
- if (!ExecutionContextService.hasContext()) {
28671
- throw new Error("commitPartialLossPromptHistory requires an execution context");
28672
- }
28673
- if (!MethodContextService.hasContext()) {
28674
- throw new Error("commitPartialLossPromptHistory requires a method context");
28675
- }
28676
- const { backtest: isBacktest } = bt.executionContextService.context;
28677
- const { strategyName, exchangeName, frameName } = bt.methodContextService.context;
28678
- const systemPrompts = await bt.partialLossPromptService.getSystemPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
28679
- const userPrompt = await bt.partialLossPromptService.getUserPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
28680
- if (systemPrompts.length > 0) {
28681
- for (const content of systemPrompts) {
28682
- history.unshift({
28683
- role: "system",
28684
- content,
28685
- });
28686
- }
28687
- }
28688
- if (userPrompt && userPrompt.trim() !== "") {
28689
- history.push({
28690
- role: "user",
28691
- content: userPrompt,
28692
- });
28693
- }
28694
- }
28695
- /**
28696
- * Commits breakeven prompt history to the message array.
28697
- *
28698
- * Extracts trading context from ExecutionContext and MethodContext,
28699
- * then adds breakeven specific system prompts at the beginning
28700
- * and user prompt at the end of the history array if they are not empty.
28701
- *
28702
- * Context extraction:
28703
- * - symbol: Provided as parameter for debugging convenience
28704
- * - backtest mode: From ExecutionContext
28705
- * - strategyName, exchangeName, frameName: From MethodContext
28706
- *
28707
- * Used for AI-powered analysis of breakeven events.
28708
- *
28709
- * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
28710
- * @param history - Message array to append prompts to
28711
- * @returns Promise that resolves when prompts are added
28712
- * @throws Error if ExecutionContext or MethodContext is not active
28713
- *
28714
- * @example
28715
- * ```typescript
28716
- * const messages: MessageModel[] = [];
28717
- * await commitBreakevenPromptHistory("BTCUSDT", messages);
28718
- * ```
28719
- */
28720
- async function commitBreakevenPromptHistory(symbol, history) {
28721
- bt.loggerService.log(METHOD_NAME_BREAKEVEN, {
28722
- symbol,
28723
- });
28724
- if (!ExecutionContextService.hasContext()) {
28725
- throw new Error("commitBreakevenPromptHistory requires an execution context");
28726
- }
28727
- if (!MethodContextService.hasContext()) {
28728
- throw new Error("commitBreakevenPromptHistory requires a method context");
28729
- }
28730
- const { backtest: isBacktest } = bt.executionContextService.context;
28731
- const { strategyName, exchangeName, frameName } = bt.methodContextService.context;
28732
- const systemPrompts = await bt.breakevenPromptService.getSystemPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
28733
- const userPrompt = await bt.breakevenPromptService.getUserPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
28734
- if (systemPrompts.length > 0) {
28735
- for (const content of systemPrompts) {
28736
- history.unshift({
28737
- role: "system",
28738
- content,
28739
- });
28740
- }
28741
- }
28742
- if (userPrompt && userPrompt.trim() !== "") {
28743
- history.push({
28744
- role: "user",
28745
- content: userPrompt,
28746
- });
28747
- }
28748
- }
28749
- /**
28750
- * Commits schedule cancellation prompt history to the message array.
28751
- *
28752
- * Extracts trading context from ExecutionContext and MethodContext,
28753
- * then adds schedule cancellation specific system prompts at the beginning
28754
- * and user prompt at the end of the history array if they are not empty.
28755
- *
28756
- * Context extraction:
28757
- * - symbol: Provided as parameter for debugging convenience
28758
- * - backtest mode: From ExecutionContext
28759
- * - strategyName, exchangeName, frameName: From MethodContext
28760
- *
28761
- * Used for AI-powered analysis of schedule cancellation events.
28762
- *
28763
- * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
28764
- * @param history - Message array to append prompts to
28765
- * @returns Promise that resolves when prompts are added
28766
- * @throws Error if ExecutionContext or MethodContext is not active
28767
- *
28768
- * @example
28769
- * ```typescript
28770
- * const messages: MessageModel[] = [];
28771
- * await commitScheduleCancelPromptHistory("BTCUSDT", messages);
28772
- * ```
28773
- */
28774
- async function commitScheduleCancelPromptHistory(symbol, history) {
28775
- bt.loggerService.log(METHOD_NAME_SCHEDULE_CANCEL, {
28776
- symbol,
28777
- });
28778
- if (!ExecutionContextService.hasContext()) {
28779
- throw new Error("commitScheduleCancelPromptHistory requires an execution context");
28780
- }
28781
- if (!MethodContextService.hasContext()) {
28782
- throw new Error("commitScheduleCancelPromptHistory requires a method context");
28783
- }
28784
- const { backtest: isBacktest } = bt.executionContextService.context;
28785
- const { strategyName, exchangeName, frameName } = bt.methodContextService.context;
28786
- const systemPrompts = await bt.scheduleCancelPromptService.getSystemPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
28787
- const userPrompt = await bt.scheduleCancelPromptService.getUserPrompt(symbol, strategyName, exchangeName, frameName, isBacktest);
28788
- if (systemPrompts.length > 0) {
28789
- for (const content of systemPrompts) {
28790
- history.unshift({
28791
- role: "system",
28792
- content,
28793
- });
28794
- }
28795
- }
28796
- if (userPrompt && userPrompt.trim() !== "") {
28797
- history.push({
28798
- role: "user",
28799
- content: userPrompt,
28800
- });
28801
- }
28802
- }
28803
27650
 
28804
27651
  const DUMP_SIGNAL_METHOD_NAME = "dump.dumpSignal";
28805
27652
  /**
@@ -33840,19 +32687,12 @@ exports.addSizingSchema = addSizingSchema;
33840
32687
  exports.addStrategySchema = addStrategySchema;
33841
32688
  exports.addWalkerSchema = addWalkerSchema;
33842
32689
  exports.commitBreakeven = commitBreakeven;
33843
- exports.commitBreakevenPromptHistory = commitBreakevenPromptHistory;
33844
32690
  exports.commitCancel = commitCancel;
33845
32691
  exports.commitPartialLoss = commitPartialLoss;
33846
- exports.commitPartialLossPromptHistory = commitPartialLossPromptHistory;
33847
32692
  exports.commitPartialProfit = commitPartialProfit;
33848
- exports.commitPartialProfitPromptHistory = commitPartialProfitPromptHistory;
33849
- exports.commitRiskPromptHistory = commitRiskPromptHistory;
33850
- exports.commitScheduleCancelPromptHistory = commitScheduleCancelPromptHistory;
33851
32693
  exports.commitSignalPromptHistory = commitSignalPromptHistory;
33852
32694
  exports.commitTrailingStop = commitTrailingStop;
33853
- exports.commitTrailingStopPromptHistory = commitTrailingStopPromptHistory;
33854
32695
  exports.commitTrailingTake = commitTrailingTake;
33855
- exports.commitTrailingTakePromptHistory = commitTrailingTakePromptHistory;
33856
32696
  exports.dumpSignalData = dumpSignalData;
33857
32697
  exports.emitters = emitters;
33858
32698
  exports.formatPrice = formatPrice;