backtest-kit 2.1.3 → 2.2.1
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 +121 -2252
- package/build/index.mjs +124 -2246
- package/package.json +1 -1
- package/types.d.ts +22 -1327
package/types.d.ts
CHANGED
|
@@ -58,11 +58,6 @@ interface ValidateArgs<T = Enum> {
|
|
|
58
58
|
* @example { FIXED_1000: "fixed-1000" }
|
|
59
59
|
*/
|
|
60
60
|
SizingName?: T;
|
|
61
|
-
/**
|
|
62
|
-
* Optimizer name enum to validate
|
|
63
|
-
* @example { GRID_SEARCH: "grid-search" }
|
|
64
|
-
*/
|
|
65
|
-
OptimizerName?: T;
|
|
66
61
|
/**
|
|
67
62
|
* Walker (parameter sweep) name enum to validate
|
|
68
63
|
* @example { RSI_SWEEP: "rsi-sweep" }
|
|
@@ -73,7 +68,7 @@ interface ValidateArgs<T = Enum> {
|
|
|
73
68
|
* Validates the existence of all provided entity names across validation services.
|
|
74
69
|
*
|
|
75
70
|
* This function accepts enum objects for various entity types (exchanges, frames,
|
|
76
|
-
* strategies, risks, sizings,
|
|
71
|
+
* strategies, risks, sizings, walkers) and validates that each entity
|
|
77
72
|
* name exists in its respective registry. Validation results are memoized for performance.
|
|
78
73
|
*
|
|
79
74
|
* If no arguments are provided (or specific entity types are omitted), the function
|
|
@@ -3266,418 +3261,6 @@ interface ISizing {
|
|
|
3266
3261
|
*/
|
|
3267
3262
|
type SizingName = string;
|
|
3268
3263
|
|
|
3269
|
-
/**
|
|
3270
|
-
* Message role type for LLM conversation context.
|
|
3271
|
-
* Defines the sender of a message in a chat-based interaction.
|
|
3272
|
-
*/
|
|
3273
|
-
type MessageRole = "assistant" | "system" | "user";
|
|
3274
|
-
/**
|
|
3275
|
-
* Message model for LLM conversation history.
|
|
3276
|
-
* Used in Optimizer to build prompts and maintain conversation context.
|
|
3277
|
-
*/
|
|
3278
|
-
interface MessageModel {
|
|
3279
|
-
/**
|
|
3280
|
-
* The sender of the message.
|
|
3281
|
-
* - "system": System instructions and context
|
|
3282
|
-
* - "user": User input and questions
|
|
3283
|
-
* - "assistant": LLM responses
|
|
3284
|
-
*/
|
|
3285
|
-
role: MessageRole;
|
|
3286
|
-
/**
|
|
3287
|
-
* The text content of the message.
|
|
3288
|
-
* Contains the actual message text sent or received.
|
|
3289
|
-
*/
|
|
3290
|
-
content: string;
|
|
3291
|
-
}
|
|
3292
|
-
|
|
3293
|
-
/**
|
|
3294
|
-
* Unique identifier for data rows in optimizer sources.
|
|
3295
|
-
* Can be either a string or numeric ID.
|
|
3296
|
-
*/
|
|
3297
|
-
type RowId = string | number;
|
|
3298
|
-
/**
|
|
3299
|
-
* Time range configuration for optimizer training or testing periods.
|
|
3300
|
-
* Used to define date boundaries for data collection.
|
|
3301
|
-
*/
|
|
3302
|
-
interface IOptimizerRange {
|
|
3303
|
-
/**
|
|
3304
|
-
* Optional description of this time range.
|
|
3305
|
-
* Example: "Bull market period 2024-Q1"
|
|
3306
|
-
*/
|
|
3307
|
-
note?: string;
|
|
3308
|
-
/**
|
|
3309
|
-
* Start date of the range (inclusive).
|
|
3310
|
-
*/
|
|
3311
|
-
startDate: Date;
|
|
3312
|
-
/**
|
|
3313
|
-
* End date of the range (inclusive).
|
|
3314
|
-
*/
|
|
3315
|
-
endDate: Date;
|
|
3316
|
-
}
|
|
3317
|
-
/**
|
|
3318
|
-
* Base interface for optimizer data sources.
|
|
3319
|
-
* All data fetched from sources must have a unique ID for deduplication.
|
|
3320
|
-
*/
|
|
3321
|
-
interface IOptimizerData {
|
|
3322
|
-
/**
|
|
3323
|
-
* Unique identifier for this data row.
|
|
3324
|
-
* Used for deduplication when paginating data sources.
|
|
3325
|
-
*/
|
|
3326
|
-
id: RowId;
|
|
3327
|
-
}
|
|
3328
|
-
/**
|
|
3329
|
-
* Filter arguments for data source queries without pagination.
|
|
3330
|
-
* Used internally to filter data by symbol and time range.
|
|
3331
|
-
*/
|
|
3332
|
-
interface IOptimizerFilterArgs {
|
|
3333
|
-
/**
|
|
3334
|
-
* Trading pair symbol (e.g., "BTCUSDT").
|
|
3335
|
-
*/
|
|
3336
|
-
symbol: string;
|
|
3337
|
-
/**
|
|
3338
|
-
* Start date of the data range (inclusive).
|
|
3339
|
-
*/
|
|
3340
|
-
startDate: Date;
|
|
3341
|
-
/**
|
|
3342
|
-
* End date of the data range (inclusive).
|
|
3343
|
-
*/
|
|
3344
|
-
endDate: Date;
|
|
3345
|
-
}
|
|
3346
|
-
/**
|
|
3347
|
-
* Fetch arguments for paginated data source queries.
|
|
3348
|
-
* Extends filter arguments with pagination parameters.
|
|
3349
|
-
*/
|
|
3350
|
-
interface IOptimizerFetchArgs extends IOptimizerFilterArgs {
|
|
3351
|
-
/**
|
|
3352
|
-
* Maximum number of records to fetch per request.
|
|
3353
|
-
* Default: 25 (ITERATION_LIMIT)
|
|
3354
|
-
*/
|
|
3355
|
-
limit: number;
|
|
3356
|
-
/**
|
|
3357
|
-
* Number of records to skip from the beginning.
|
|
3358
|
-
* Used for pagination (offset = page * limit).
|
|
3359
|
-
*/
|
|
3360
|
-
offset: number;
|
|
3361
|
-
}
|
|
3362
|
-
/**
|
|
3363
|
-
* Data source function for fetching optimizer training data.
|
|
3364
|
-
* Must support pagination and return data with unique IDs.
|
|
3365
|
-
*
|
|
3366
|
-
* @param args - Fetch arguments including symbol, dates, limit, offset
|
|
3367
|
-
* @returns Array of data rows or Promise resolving to data array
|
|
3368
|
-
*/
|
|
3369
|
-
interface IOptimizerSourceFn<Data extends IOptimizerData = any> {
|
|
3370
|
-
(args: IOptimizerFetchArgs): Data[] | Promise<Data[]>;
|
|
3371
|
-
}
|
|
3372
|
-
/**
|
|
3373
|
-
* Generated strategy data with LLM conversation history.
|
|
3374
|
-
* Contains the full context used to generate a trading strategy.
|
|
3375
|
-
*/
|
|
3376
|
-
interface IOptimizerStrategy {
|
|
3377
|
-
/**
|
|
3378
|
-
* Trading pair symbol this strategy was generated for.
|
|
3379
|
-
*/
|
|
3380
|
-
symbol: string;
|
|
3381
|
-
/**
|
|
3382
|
-
* Unique name taken from data source.
|
|
3383
|
-
* Used in callbacks and logging.
|
|
3384
|
-
*/
|
|
3385
|
-
name: string;
|
|
3386
|
-
/**
|
|
3387
|
-
* LLM conversation history used to generate the strategy.
|
|
3388
|
-
* Contains user prompts and assistant responses for each data source.
|
|
3389
|
-
*/
|
|
3390
|
-
messages: MessageModel[];
|
|
3391
|
-
/**
|
|
3392
|
-
* Generated strategy prompt/description.
|
|
3393
|
-
* Output from getPrompt() function, used as strategy logic.
|
|
3394
|
-
*/
|
|
3395
|
-
strategy: string;
|
|
3396
|
-
}
|
|
3397
|
-
/**
|
|
3398
|
-
* Data source configuration with custom message formatters.
|
|
3399
|
-
* Defines how to fetch data and format it for LLM conversation.
|
|
3400
|
-
*/
|
|
3401
|
-
interface IOptimizerSource<Data extends IOptimizerData = any> {
|
|
3402
|
-
/**
|
|
3403
|
-
* Optional description of this data source.
|
|
3404
|
-
* Example: "Historical backtest results for training"
|
|
3405
|
-
*/
|
|
3406
|
-
note?: string;
|
|
3407
|
-
/**
|
|
3408
|
-
* Unique name identifying this data source.
|
|
3409
|
-
* Used in callbacks and logging.
|
|
3410
|
-
*/
|
|
3411
|
-
name: string;
|
|
3412
|
-
/**
|
|
3413
|
-
* Function to fetch data from this source.
|
|
3414
|
-
* Must support pagination via limit/offset.
|
|
3415
|
-
*/
|
|
3416
|
-
fetch: IOptimizerSourceFn<Data>;
|
|
3417
|
-
/**
|
|
3418
|
-
* Optional custom formatter for user messages.
|
|
3419
|
-
* If not provided, uses default template from OptimizerTemplateService.
|
|
3420
|
-
*
|
|
3421
|
-
* @param symbol - Trading pair symbol
|
|
3422
|
-
* @param data - Fetched data array
|
|
3423
|
-
* @param name - Source name
|
|
3424
|
-
* @returns Formatted user message content
|
|
3425
|
-
*/
|
|
3426
|
-
user?: (symbol: string, data: Data[], name: string) => string | Promise<string>;
|
|
3427
|
-
/**
|
|
3428
|
-
* Optional custom formatter for assistant messages.
|
|
3429
|
-
* If not provided, uses default template from OptimizerTemplateService.
|
|
3430
|
-
*
|
|
3431
|
-
* @param symbol - Trading pair symbol
|
|
3432
|
-
* @param data - Fetched data array
|
|
3433
|
-
* @param name - Source name
|
|
3434
|
-
* @returns Formatted assistant message content
|
|
3435
|
-
*/
|
|
3436
|
-
assistant?: (symbol: string, data: Data[], name: string) => string | Promise<string>;
|
|
3437
|
-
}
|
|
3438
|
-
/**
|
|
3439
|
-
* Union type for data source configuration.
|
|
3440
|
-
* Can be either a simple fetch function or a full source configuration object.
|
|
3441
|
-
*/
|
|
3442
|
-
type Source<Data extends IOptimizerData = any> = IOptimizerSourceFn<Data> | IOptimizerSource<Data>;
|
|
3443
|
-
/**
|
|
3444
|
-
* Lifecycle callbacks for optimizer events.
|
|
3445
|
-
* Provides hooks for monitoring and validating optimizer operations.
|
|
3446
|
-
*/
|
|
3447
|
-
interface IOptimizerCallbacks {
|
|
3448
|
-
/**
|
|
3449
|
-
* Called after strategy data is generated for all train ranges.
|
|
3450
|
-
* Useful for logging or validating the generated strategies.
|
|
3451
|
-
*
|
|
3452
|
-
* @param symbol - Trading pair symbol
|
|
3453
|
-
* @param strategyData - Array of generated strategies with their messages
|
|
3454
|
-
*/
|
|
3455
|
-
onData?: (symbol: string, strategyData: IOptimizerStrategy[]) => void | Promise<void>;
|
|
3456
|
-
/**
|
|
3457
|
-
* Called after strategy code is generated.
|
|
3458
|
-
* Useful for logging or validating the generated code.
|
|
3459
|
-
*
|
|
3460
|
-
* @param symbol - Trading pair symbol
|
|
3461
|
-
* @param code - Generated strategy code
|
|
3462
|
-
*/
|
|
3463
|
-
onCode?: (symbol: string, code: string) => void | Promise<void>;
|
|
3464
|
-
/**
|
|
3465
|
-
* Called after strategy code is dumped to file.
|
|
3466
|
-
* Useful for logging or performing additional actions after file write.
|
|
3467
|
-
*
|
|
3468
|
-
* @param symbol - Trading pair symbol
|
|
3469
|
-
* @param filepath - Path where the file was saved
|
|
3470
|
-
*/
|
|
3471
|
-
onDump?: (symbol: string, filepath: string) => void | Promise<void>;
|
|
3472
|
-
/**
|
|
3473
|
-
* Called after data is fetched from a source.
|
|
3474
|
-
* Useful for logging or validating the fetched data.
|
|
3475
|
-
*
|
|
3476
|
-
* @param symbol - Trading pair symbol
|
|
3477
|
-
* @param sourceName - Name of the data source
|
|
3478
|
-
* @param data - Array of fetched data
|
|
3479
|
-
* @param startDate - Start date of the data range
|
|
3480
|
-
* @param endDate - End date of the data range
|
|
3481
|
-
*/
|
|
3482
|
-
onSourceData?: <Data extends IOptimizerData = any>(symbol: string, sourceName: string, data: Data[], startDate: Date, endDate: Date) => void | Promise<void>;
|
|
3483
|
-
}
|
|
3484
|
-
/**
|
|
3485
|
-
* Template interface for generating code snippets and LLM messages.
|
|
3486
|
-
* Each method returns TypeScript/JavaScript code as a string.
|
|
3487
|
-
*/
|
|
3488
|
-
interface IOptimizerTemplate {
|
|
3489
|
-
/**
|
|
3490
|
-
* Generates the top banner with imports and initialization.
|
|
3491
|
-
*
|
|
3492
|
-
* @param symbol - Trading pair symbol
|
|
3493
|
-
* @returns Generated import statements and setup code
|
|
3494
|
-
*/
|
|
3495
|
-
getTopBanner(symbol: string): string | Promise<string>;
|
|
3496
|
-
/**
|
|
3497
|
-
* Generates default user message content for LLM conversation.
|
|
3498
|
-
*
|
|
3499
|
-
* @param symbol - Trading pair symbol
|
|
3500
|
-
* @param data - Data array from source
|
|
3501
|
-
* @param name - Source name
|
|
3502
|
-
* @returns Formatted user message content
|
|
3503
|
-
*/
|
|
3504
|
-
getUserMessage<Data extends IOptimizerData = any>(symbol: string, data: Data[], name: string): string | Promise<string>;
|
|
3505
|
-
/**
|
|
3506
|
-
* Generates default assistant message content for LLM conversation.
|
|
3507
|
-
*
|
|
3508
|
-
* @param symbol - Trading pair symbol
|
|
3509
|
-
* @param data - Data array from source
|
|
3510
|
-
* @param name - Source name
|
|
3511
|
-
* @returns Formatted assistant message content
|
|
3512
|
-
*/
|
|
3513
|
-
getAssistantMessage<Data extends IOptimizerData = any>(symbol: string, data: Data[], name: string): string | Promise<string>;
|
|
3514
|
-
/**
|
|
3515
|
-
* Generates Walker configuration code.
|
|
3516
|
-
*
|
|
3517
|
-
* @param walkerName - Unique walker identifier
|
|
3518
|
-
* @param exchangeName - Exchange name to use
|
|
3519
|
-
* @param frameName - Frame name for testing
|
|
3520
|
-
* @param strategies - Array of strategy names to compare
|
|
3521
|
-
* @returns Generated addWalker() call
|
|
3522
|
-
*/
|
|
3523
|
-
getWalkerTemplate(walkerName: WalkerName, exchangeName: ExchangeName, frameName: FrameName, strategies: string[]): string | Promise<string>;
|
|
3524
|
-
/**
|
|
3525
|
-
* Generates Exchange configuration code.
|
|
3526
|
-
*
|
|
3527
|
-
* @param symbol - Trading pair symbol
|
|
3528
|
-
* @param exchangeName - Unique exchange identifier
|
|
3529
|
-
* @returns Generated addExchange() call with CCXT integration
|
|
3530
|
-
*/
|
|
3531
|
-
getExchangeTemplate(symbol: string, exchangeName: ExchangeName): string | Promise<string>;
|
|
3532
|
-
/**
|
|
3533
|
-
* Generates Frame (timeframe) configuration code.
|
|
3534
|
-
*
|
|
3535
|
-
* @param symbol - Trading pair symbol
|
|
3536
|
-
* @param frameName - Unique frame identifier
|
|
3537
|
-
* @param interval - Candle interval (e.g., "1m", "5m")
|
|
3538
|
-
* @param startDate - Frame start date
|
|
3539
|
-
* @param endDate - Frame end date
|
|
3540
|
-
* @returns Generated addFrame() call
|
|
3541
|
-
*/
|
|
3542
|
-
getFrameTemplate(symbol: string, frameName: FrameName, interval: CandleInterval, startDate: Date, endDate: Date): string | Promise<string>;
|
|
3543
|
-
/**
|
|
3544
|
-
* Generates Strategy configuration code with LLM integration.
|
|
3545
|
-
*
|
|
3546
|
-
* @param strategyName - Unique strategy identifier
|
|
3547
|
-
* @param interval - Signal throttling interval (e.g., "5m")
|
|
3548
|
-
* @param prompt - Strategy logic prompt from getPrompt()
|
|
3549
|
-
* @returns Generated addStrategy() call with getSignal() function
|
|
3550
|
-
*/
|
|
3551
|
-
getStrategyTemplate(strategyName: StrategyName, interval: CandleInterval, prompt: string): string | Promise<string>;
|
|
3552
|
-
/**
|
|
3553
|
-
* Generates launcher code to run Walker and listen to events.
|
|
3554
|
-
*
|
|
3555
|
-
* @param symbol - Trading pair symbol
|
|
3556
|
-
* @param walkerName - Walker name to launch
|
|
3557
|
-
* @returns Generated Walker.background() call with event listeners
|
|
3558
|
-
*/
|
|
3559
|
-
getLauncherTemplate(symbol: string, walkerName: WalkerName): string | Promise<string>;
|
|
3560
|
-
/**
|
|
3561
|
-
* Generates text() helper function for LLM text generation.
|
|
3562
|
-
*
|
|
3563
|
-
* @param symbol - Trading pair symbol
|
|
3564
|
-
* @returns Generated async text() function using Ollama
|
|
3565
|
-
*/
|
|
3566
|
-
getTextTemplate(symbol: string): string | Promise<string>;
|
|
3567
|
-
/**
|
|
3568
|
-
* Generates json() helper function for structured LLM output.
|
|
3569
|
-
*
|
|
3570
|
-
* @param symbol - Trading pair symbol
|
|
3571
|
-
* @returns Generated async json() function with signal schema
|
|
3572
|
-
*/
|
|
3573
|
-
getJsonTemplate(symbol: string): string | Promise<string>;
|
|
3574
|
-
/**
|
|
3575
|
-
* Generates dumpJson() helper function for debug output.
|
|
3576
|
-
*
|
|
3577
|
-
* @param symbol - Trading pair symbol
|
|
3578
|
-
* @returns Generated async dumpJson() function for file logging
|
|
3579
|
-
*/
|
|
3580
|
-
getJsonDumpTemplate: (symbol: string) => string | Promise<string>;
|
|
3581
|
-
}
|
|
3582
|
-
/**
|
|
3583
|
-
* Schema configuration for optimizer registration.
|
|
3584
|
-
* Defines how to collect data, generate strategies, and create executable code.
|
|
3585
|
-
*/
|
|
3586
|
-
interface IOptimizerSchema {
|
|
3587
|
-
/**
|
|
3588
|
-
* Optional description of this optimizer configuration.
|
|
3589
|
-
*/
|
|
3590
|
-
note?: string;
|
|
3591
|
-
/**
|
|
3592
|
-
* Unique identifier for this optimizer.
|
|
3593
|
-
* Used to retrieve optimizer instance from registry.
|
|
3594
|
-
*/
|
|
3595
|
-
optimizerName: OptimizerName;
|
|
3596
|
-
/**
|
|
3597
|
-
* Array of training time ranges.
|
|
3598
|
-
* Each range generates a separate strategy variant for comparison.
|
|
3599
|
-
*/
|
|
3600
|
-
rangeTrain: IOptimizerRange[];
|
|
3601
|
-
/**
|
|
3602
|
-
* Testing time range for strategy validation.
|
|
3603
|
-
* Used in generated Walker to evaluate strategy performance.
|
|
3604
|
-
*/
|
|
3605
|
-
rangeTest: IOptimizerRange;
|
|
3606
|
-
/**
|
|
3607
|
-
* Array of data sources for strategy generation.
|
|
3608
|
-
* Each source contributes to the LLM conversation context.
|
|
3609
|
-
*/
|
|
3610
|
-
source: Source[];
|
|
3611
|
-
/**
|
|
3612
|
-
* Function to generate strategy prompt from conversation history.
|
|
3613
|
-
* Called after all sources are processed for each training range.
|
|
3614
|
-
*
|
|
3615
|
-
* @param symbol - Trading pair symbol
|
|
3616
|
-
* @param messages - Complete conversation history with all sources
|
|
3617
|
-
* @returns Strategy prompt/logic description
|
|
3618
|
-
*/
|
|
3619
|
-
getPrompt: (symbol: string, messages: MessageModel[]) => string | Promise<string>;
|
|
3620
|
-
/**
|
|
3621
|
-
* Optional custom template overrides.
|
|
3622
|
-
* If not provided, uses defaults from OptimizerTemplateService.
|
|
3623
|
-
*/
|
|
3624
|
-
template?: Partial<IOptimizerTemplate>;
|
|
3625
|
-
/**
|
|
3626
|
-
* Optional lifecycle callbacks for monitoring.
|
|
3627
|
-
*/
|
|
3628
|
-
callbacks?: Partial<IOptimizerCallbacks>;
|
|
3629
|
-
}
|
|
3630
|
-
/**
|
|
3631
|
-
* Internal parameters for ClientOptimizer instantiation.
|
|
3632
|
-
* Extends schema with resolved dependencies (logger, complete template).
|
|
3633
|
-
*/
|
|
3634
|
-
interface IOptimizerParams extends IOptimizerSchema {
|
|
3635
|
-
/**
|
|
3636
|
-
* Logger instance for debug and info messages.
|
|
3637
|
-
* Injected by OptimizerConnectionService.
|
|
3638
|
-
*/
|
|
3639
|
-
logger: ILogger;
|
|
3640
|
-
/**
|
|
3641
|
-
* Complete template implementation with all methods.
|
|
3642
|
-
* Merged from schema.template and OptimizerTemplateService defaults.
|
|
3643
|
-
*/
|
|
3644
|
-
template: IOptimizerTemplate;
|
|
3645
|
-
}
|
|
3646
|
-
/**
|
|
3647
|
-
* Optimizer client interface for strategy generation and code export.
|
|
3648
|
-
* Implemented by ClientOptimizer class.
|
|
3649
|
-
*/
|
|
3650
|
-
interface IOptimizer {
|
|
3651
|
-
/**
|
|
3652
|
-
* Fetches data from all sources and generates strategy metadata.
|
|
3653
|
-
* Processes each training range and builds LLM conversation history.
|
|
3654
|
-
*
|
|
3655
|
-
* @param symbol - Trading pair symbol
|
|
3656
|
-
* @returns Array of generated strategies with conversation context
|
|
3657
|
-
*/
|
|
3658
|
-
getData(symbol: string): Promise<IOptimizerStrategy[]>;
|
|
3659
|
-
/**
|
|
3660
|
-
* Generates complete executable strategy code.
|
|
3661
|
-
* Includes imports, helpers, strategies, walker, and launcher.
|
|
3662
|
-
*
|
|
3663
|
-
* @param symbol - Trading pair symbol
|
|
3664
|
-
* @returns Generated TypeScript/JavaScript code as string
|
|
3665
|
-
*/
|
|
3666
|
-
getCode(symbol: string): Promise<string>;
|
|
3667
|
-
/**
|
|
3668
|
-
* Generates and saves strategy code to file.
|
|
3669
|
-
* Creates directory if needed, writes .mjs file.
|
|
3670
|
-
*
|
|
3671
|
-
* @param symbol - Trading pair symbol
|
|
3672
|
-
* @param path - Output directory path (default: "./")
|
|
3673
|
-
*/
|
|
3674
|
-
dump(symbol: string, path?: string): Promise<void>;
|
|
3675
|
-
}
|
|
3676
|
-
/**
|
|
3677
|
-
* Unique string identifier for registered optimizers.
|
|
3678
|
-
*/
|
|
3679
|
-
type OptimizerName = string;
|
|
3680
|
-
|
|
3681
3264
|
/**
|
|
3682
3265
|
* Retrieves a registered strategy schema by name.
|
|
3683
3266
|
*
|
|
@@ -3772,23 +3355,6 @@ declare function getSizingSchema(sizingName: SizingName): ISizingSchema;
|
|
|
3772
3355
|
* ```
|
|
3773
3356
|
*/
|
|
3774
3357
|
declare function getRiskSchema(riskName: RiskName): IRiskSchema;
|
|
3775
|
-
/**
|
|
3776
|
-
* Retrieves a registered optimizer schema by name.
|
|
3777
|
-
*
|
|
3778
|
-
* @param optimizerName - Unique optimizer identifier
|
|
3779
|
-
* @returns The optimizer schema configuration object
|
|
3780
|
-
* @throws Error if optimizer is not registered
|
|
3781
|
-
*
|
|
3782
|
-
* @example
|
|
3783
|
-
* ```typescript
|
|
3784
|
-
* const optimizer = getOptimizer("llm-strategy-generator");
|
|
3785
|
-
* console.log(optimizer.rangeTrain); // Array of training ranges
|
|
3786
|
-
* console.log(optimizer.rangeTest); // Testing range
|
|
3787
|
-
* console.log(optimizer.source); // Array of data sources
|
|
3788
|
-
* console.log(optimizer.getPrompt); // async function
|
|
3789
|
-
* ```
|
|
3790
|
-
*/
|
|
3791
|
-
declare function getOptimizerSchema(optimizerName: OptimizerName): IOptimizerSchema;
|
|
3792
3358
|
/**
|
|
3793
3359
|
* Retrieves a registered action schema by name.
|
|
3794
3360
|
*
|
|
@@ -4716,94 +4282,6 @@ declare function addSizingSchema(sizingSchema: ISizingSchema): void;
|
|
|
4716
4282
|
* ```
|
|
4717
4283
|
*/
|
|
4718
4284
|
declare function addRiskSchema(riskSchema: IRiskSchema): void;
|
|
4719
|
-
/**
|
|
4720
|
-
* Registers an optimizer configuration in the framework.
|
|
4721
|
-
*
|
|
4722
|
-
* The optimizer generates trading strategies by:
|
|
4723
|
-
* - Collecting data from multiple sources across training periods
|
|
4724
|
-
* - Building LLM conversation history with fetched data
|
|
4725
|
-
* - Generating strategy prompts using getPrompt()
|
|
4726
|
-
* - Creating executable backtest code with templates
|
|
4727
|
-
*
|
|
4728
|
-
* The optimizer produces a complete .mjs file containing:
|
|
4729
|
-
* - Exchange, Frame, Strategy, and Walker configurations
|
|
4730
|
-
* - Multi-timeframe analysis logic
|
|
4731
|
-
* - LLM integration for signal generation
|
|
4732
|
-
* - Event listeners for progress tracking
|
|
4733
|
-
*
|
|
4734
|
-
* @param optimizerSchema - Optimizer configuration object
|
|
4735
|
-
* @param optimizerSchema.optimizerName - Unique optimizer identifier
|
|
4736
|
-
* @param optimizerSchema.rangeTrain - Array of training time ranges (each generates a strategy variant)
|
|
4737
|
-
* @param optimizerSchema.rangeTest - Testing time range for strategy validation
|
|
4738
|
-
* @param optimizerSchema.source - Array of data sources (functions or source objects with custom formatters)
|
|
4739
|
-
* @param optimizerSchema.getPrompt - Function to generate strategy prompt from conversation history
|
|
4740
|
-
* @param optimizerSchema.template - Optional custom template overrides (top banner, helpers, strategy logic, etc.)
|
|
4741
|
-
* @param optimizerSchema.callbacks - Optional lifecycle callbacks (onData, onCode, onDump, onSourceData)
|
|
4742
|
-
*
|
|
4743
|
-
* @example
|
|
4744
|
-
* ```typescript
|
|
4745
|
-
* // Basic optimizer with single data source
|
|
4746
|
-
* addOptimizer({
|
|
4747
|
-
* optimizerName: "llm-strategy-generator",
|
|
4748
|
-
* rangeTrain: [
|
|
4749
|
-
* {
|
|
4750
|
-
* note: "Bull market period",
|
|
4751
|
-
* startDate: new Date("2024-01-01"),
|
|
4752
|
-
* endDate: new Date("2024-01-31"),
|
|
4753
|
-
* },
|
|
4754
|
-
* {
|
|
4755
|
-
* note: "Bear market period",
|
|
4756
|
-
* startDate: new Date("2024-02-01"),
|
|
4757
|
-
* endDate: new Date("2024-02-28"),
|
|
4758
|
-
* },
|
|
4759
|
-
* ],
|
|
4760
|
-
* rangeTest: {
|
|
4761
|
-
* note: "Validation period",
|
|
4762
|
-
* startDate: new Date("2024-03-01"),
|
|
4763
|
-
* endDate: new Date("2024-03-31"),
|
|
4764
|
-
* },
|
|
4765
|
-
* source: [
|
|
4766
|
-
* {
|
|
4767
|
-
* name: "historical-backtests",
|
|
4768
|
-
* fetch: async ({ symbol, startDate, endDate, limit, offset }) => {
|
|
4769
|
-
* // Fetch historical backtest results from database
|
|
4770
|
-
* return await db.backtests.find({
|
|
4771
|
-
* symbol,
|
|
4772
|
-
* date: { $gte: startDate, $lte: endDate },
|
|
4773
|
-
* })
|
|
4774
|
-
* .skip(offset)
|
|
4775
|
-
* .limit(limit);
|
|
4776
|
-
* },
|
|
4777
|
-
* user: async (symbol, data, name) => {
|
|
4778
|
-
* return `Analyze these ${data.length} backtest results for ${symbol}:\n${JSON.stringify(data)}`;
|
|
4779
|
-
* },
|
|
4780
|
-
* assistant: async (symbol, data, name) => {
|
|
4781
|
-
* return "Historical data analyzed successfully";
|
|
4782
|
-
* },
|
|
4783
|
-
* },
|
|
4784
|
-
* ],
|
|
4785
|
-
* getPrompt: async (symbol, messages) => {
|
|
4786
|
-
* // Generate strategy prompt from conversation
|
|
4787
|
-
* return `"Analyze ${symbol} using RSI and MACD. Enter LONG when RSI < 30 and MACD crosses above signal."`;
|
|
4788
|
-
* },
|
|
4789
|
-
* callbacks: {
|
|
4790
|
-
* onData: (symbol, strategyData) => {
|
|
4791
|
-
* console.log(`Generated ${strategyData.length} strategies for ${symbol}`);
|
|
4792
|
-
* },
|
|
4793
|
-
* onCode: (symbol, code) => {
|
|
4794
|
-
* console.log(`Generated ${code.length} characters of code for ${symbol}`);
|
|
4795
|
-
* },
|
|
4796
|
-
* onDump: (symbol, filepath) => {
|
|
4797
|
-
* console.log(`Saved strategy to ${filepath}`);
|
|
4798
|
-
* },
|
|
4799
|
-
* onSourceData: (symbol, sourceName, data, startDate, endDate) => {
|
|
4800
|
-
* console.log(`Fetched ${data.length} rows from ${sourceName} for ${symbol}`);
|
|
4801
|
-
* },
|
|
4802
|
-
* },
|
|
4803
|
-
* });
|
|
4804
|
-
* ```
|
|
4805
|
-
*/
|
|
4806
|
-
declare function addOptimizerSchema(optimizerSchema: IOptimizerSchema): void;
|
|
4807
4285
|
/**
|
|
4808
4286
|
* Registers an action handler in the framework.
|
|
4809
4287
|
*
|
|
@@ -5015,35 +4493,6 @@ type TSizingSchema = {
|
|
|
5015
4493
|
type TRiskSchema = {
|
|
5016
4494
|
riskName: IRiskSchema["riskName"];
|
|
5017
4495
|
} & Partial<IRiskSchema>;
|
|
5018
|
-
/**
|
|
5019
|
-
* Partial optimizer schema for override operations.
|
|
5020
|
-
*
|
|
5021
|
-
* Requires only the optimizer name identifier, all other fields are optional.
|
|
5022
|
-
* Used by overrideOptimizer() to perform partial updates without replacing entire configuration.
|
|
5023
|
-
*
|
|
5024
|
-
* @property optimizerName - Required: Unique optimizer identifier (must exist in registry)
|
|
5025
|
-
* @property rangeTrain - Optional: Updated training time ranges
|
|
5026
|
-
* @property rangeTest - Optional: Updated testing time range
|
|
5027
|
-
* @property source - Optional: Updated data sources array
|
|
5028
|
-
* @property getPrompt - Optional: New prompt generation function
|
|
5029
|
-
* @property template - Optional: Updated template overrides
|
|
5030
|
-
* @property callbacks - Optional: Updated optimizer callbacks
|
|
5031
|
-
*
|
|
5032
|
-
* @example
|
|
5033
|
-
* ```typescript
|
|
5034
|
-
* const partialUpdate: TOptimizerSchema = {
|
|
5035
|
-
* optimizerName: "llm-strategy-gen",
|
|
5036
|
-
* rangeTest: {
|
|
5037
|
-
* note: "Extended test period",
|
|
5038
|
-
* startDate: new Date("2024-04-01"),
|
|
5039
|
-
* endDate: new Date("2024-06-30")
|
|
5040
|
-
* }
|
|
5041
|
-
* };
|
|
5042
|
-
* ```
|
|
5043
|
-
*/
|
|
5044
|
-
type TOptimizerSchema = {
|
|
5045
|
-
optimizerName: IOptimizerSchema["optimizerName"];
|
|
5046
|
-
} & Partial<IOptimizerSchema>;
|
|
5047
4496
|
/**
|
|
5048
4497
|
* Partial action schema for override operations.
|
|
5049
4498
|
*
|
|
@@ -5204,34 +4653,6 @@ declare function overrideSizingSchema(sizingSchema: TSizingSchema): Promise<ISiz
|
|
|
5204
4653
|
* ```
|
|
5205
4654
|
*/
|
|
5206
4655
|
declare function overrideRiskSchema(riskSchema: TRiskSchema): Promise<IRiskSchema>;
|
|
5207
|
-
/**
|
|
5208
|
-
* Overrides an existing optimizer configuration in the framework.
|
|
5209
|
-
*
|
|
5210
|
-
* This function partially updates a previously registered optimizer with new configuration.
|
|
5211
|
-
* Only the provided fields will be updated, other fields remain unchanged.
|
|
5212
|
-
*
|
|
5213
|
-
* @param optimizerSchema - Partial optimizer configuration object
|
|
5214
|
-
* @param optimizerSchema.optimizerName - Unique optimizer identifier (must exist)
|
|
5215
|
-
* @param optimizerSchema.rangeTrain - Optional: Array of training time ranges
|
|
5216
|
-
* @param optimizerSchema.rangeTest - Optional: Testing time range
|
|
5217
|
-
* @param optimizerSchema.source - Optional: Array of data sources
|
|
5218
|
-
* @param optimizerSchema.getPrompt - Optional: Function to generate strategy prompt
|
|
5219
|
-
* @param optimizerSchema.template - Optional: Custom template overrides
|
|
5220
|
-
* @param optimizerSchema.callbacks - Optional: Lifecycle callbacks
|
|
5221
|
-
*
|
|
5222
|
-
* @example
|
|
5223
|
-
* ```typescript
|
|
5224
|
-
* overrideOptimizer({
|
|
5225
|
-
* optimizerName: "llm-strategy-generator",
|
|
5226
|
-
* rangeTest: {
|
|
5227
|
-
* note: "Updated validation period",
|
|
5228
|
-
* startDate: new Date("2024-04-01"),
|
|
5229
|
-
* endDate: new Date("2024-04-30"),
|
|
5230
|
-
* },
|
|
5231
|
-
* });
|
|
5232
|
-
* ```
|
|
5233
|
-
*/
|
|
5234
|
-
declare function overrideOptimizerSchema(optimizerSchema: TOptimizerSchema): Promise<IOptimizerSchema>;
|
|
5235
4656
|
/**
|
|
5236
4657
|
* Overrides an existing action handler configuration in the framework.
|
|
5237
4658
|
*
|
|
@@ -5473,43 +4894,6 @@ declare function listSizingSchema(): Promise<ISizingSchema[]>;
|
|
|
5473
4894
|
* ```
|
|
5474
4895
|
*/
|
|
5475
4896
|
declare function listRiskSchema(): Promise<IRiskSchema[]>;
|
|
5476
|
-
/**
|
|
5477
|
-
* Returns a list of all registered optimizer schemas.
|
|
5478
|
-
*
|
|
5479
|
-
* Retrieves all optimizers that have been registered via addOptimizer().
|
|
5480
|
-
* Useful for debugging, documentation, or building dynamic UIs.
|
|
5481
|
-
*
|
|
5482
|
-
* @returns Array of optimizer schemas with their configurations
|
|
5483
|
-
*
|
|
5484
|
-
* @example
|
|
5485
|
-
* ```typescript
|
|
5486
|
-
* import { listOptimizers, addOptimizer } from "backtest-kit";
|
|
5487
|
-
*
|
|
5488
|
-
* addOptimizer({
|
|
5489
|
-
* optimizerName: "llm-strategy-generator",
|
|
5490
|
-
* note: "Generates trading strategies using LLM",
|
|
5491
|
-
* rangeTrain: [
|
|
5492
|
-
* {
|
|
5493
|
-
* note: "Training period 1",
|
|
5494
|
-
* startDate: new Date("2024-01-01"),
|
|
5495
|
-
* endDate: new Date("2024-01-31"),
|
|
5496
|
-
* },
|
|
5497
|
-
* ],
|
|
5498
|
-
* rangeTest: {
|
|
5499
|
-
* note: "Testing period",
|
|
5500
|
-
* startDate: new Date("2024-02-01"),
|
|
5501
|
-
* endDate: new Date("2024-02-28"),
|
|
5502
|
-
* },
|
|
5503
|
-
* source: [],
|
|
5504
|
-
* getPrompt: async (symbol, messages) => "Generate strategy",
|
|
5505
|
-
* });
|
|
5506
|
-
*
|
|
5507
|
-
* const optimizers = listOptimizers();
|
|
5508
|
-
* console.log(optimizers);
|
|
5509
|
-
* // [{ optimizerName: "llm-strategy-generator", note: "Generates...", ... }]
|
|
5510
|
-
* ```
|
|
5511
|
-
*/
|
|
5512
|
-
declare function listOptimizerSchema(): Promise<IOptimizerSchema[]>;
|
|
5513
4897
|
|
|
5514
4898
|
/**
|
|
5515
4899
|
* Contract for background execution completion events.
|
|
@@ -5607,35 +4991,6 @@ interface ProgressWalkerContract {
|
|
|
5607
4991
|
progress: number;
|
|
5608
4992
|
}
|
|
5609
4993
|
|
|
5610
|
-
/**
|
|
5611
|
-
* Contract for optimizer progress events.
|
|
5612
|
-
*
|
|
5613
|
-
* Emitted during optimizer execution to track progress.
|
|
5614
|
-
* Contains information about total sources, processed sources, and completion percentage.
|
|
5615
|
-
*
|
|
5616
|
-
* @example
|
|
5617
|
-
* ```typescript
|
|
5618
|
-
* import { listenOptimizerProgress } from "backtest-kit";
|
|
5619
|
-
*
|
|
5620
|
-
* listenOptimizerProgress((event) => {
|
|
5621
|
-
* console.log(`Progress: ${(event.progress * 100).toFixed(2)}%`);
|
|
5622
|
-
* console.log(`Processed: ${event.processedSources} / ${event.totalSources}`);
|
|
5623
|
-
* });
|
|
5624
|
-
* ```
|
|
5625
|
-
*/
|
|
5626
|
-
interface ProgressOptimizerContract {
|
|
5627
|
-
/** optimizerName - Name of the optimizer being executed */
|
|
5628
|
-
optimizerName: string;
|
|
5629
|
-
/** symbol - Trading symbol (e.g., "BTCUSDT") */
|
|
5630
|
-
symbol: string;
|
|
5631
|
-
/** totalSources - Total number of sources to process */
|
|
5632
|
-
totalSources: number;
|
|
5633
|
-
/** processedSources - Number of sources processed so far */
|
|
5634
|
-
processedSources: number;
|
|
5635
|
-
/** progress - Completion percentage from 0.0 to 1.0 */
|
|
5636
|
-
progress: number;
|
|
5637
|
-
}
|
|
5638
|
-
|
|
5639
4994
|
/**
|
|
5640
4995
|
* Performance metric types tracked by the system.
|
|
5641
4996
|
*
|
|
@@ -6138,31 +5493,6 @@ declare function listenBacktestProgress(fn: (event: ProgressBacktestContract) =>
|
|
|
6138
5493
|
* ```
|
|
6139
5494
|
*/
|
|
6140
5495
|
declare function listenWalkerProgress(fn: (event: ProgressWalkerContract) => void): () => void;
|
|
6141
|
-
/**
|
|
6142
|
-
* Subscribes to optimizer progress events with queued async processing.
|
|
6143
|
-
*
|
|
6144
|
-
* Emits during optimizer execution to track data source processing progress.
|
|
6145
|
-
* Events are processed sequentially in order received, even if callback is async.
|
|
6146
|
-
* Uses queued wrapper to prevent concurrent execution of the callback.
|
|
6147
|
-
*
|
|
6148
|
-
* @param fn - Callback function to handle optimizer progress events
|
|
6149
|
-
* @returns Unsubscribe function to stop listening to events
|
|
6150
|
-
*
|
|
6151
|
-
* @example
|
|
6152
|
-
* ```typescript
|
|
6153
|
-
* import { listenOptimizerProgress } from "backtest-kit";
|
|
6154
|
-
*
|
|
6155
|
-
* const unsubscribe = listenOptimizerProgress((event) => {
|
|
6156
|
-
* console.log(`Progress: ${(event.progress * 100).toFixed(2)}%`);
|
|
6157
|
-
* console.log(`${event.processedSources} / ${event.totalSources} sources`);
|
|
6158
|
-
* console.log(`Optimizer: ${event.optimizerName}, Symbol: ${event.symbol}`);
|
|
6159
|
-
* });
|
|
6160
|
-
*
|
|
6161
|
-
* // Later: stop listening
|
|
6162
|
-
* unsubscribe();
|
|
6163
|
-
* ```
|
|
6164
|
-
*/
|
|
6165
|
-
declare function listenOptimizerProgress(fn: (event: ProgressOptimizerContract) => void): () => void;
|
|
6166
5496
|
/**
|
|
6167
5497
|
* Subscribes to performance metric events with queued async processing.
|
|
6168
5498
|
*
|
|
@@ -6850,127 +6180,33 @@ declare function getOrderBook(symbol: string, depth?: number): Promise<IOrderBoo
|
|
|
6850
6180
|
*
|
|
6851
6181
|
* All modes respect execution context and prevent look-ahead bias.
|
|
6852
6182
|
*
|
|
6853
|
-
* Parameter combinations:
|
|
6854
|
-
* 1. sDate + eDate + limit: fetches with explicit parameters, validates eDate <= when
|
|
6855
|
-
* 2. sDate + eDate: calculates limit from date range, validates eDate <= when
|
|
6856
|
-
* 3. eDate + limit: calculates sDate backward, validates eDate <= when
|
|
6857
|
-
* 4. sDate + limit: fetches forward, validates calculated endTimestamp <= when
|
|
6858
|
-
* 5. Only limit: uses execution.context.when as reference (backward)
|
|
6859
|
-
*
|
|
6860
|
-
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
6861
|
-
* @param interval - Candle interval ("1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h")
|
|
6862
|
-
* @param limit - Optional number of candles to fetch
|
|
6863
|
-
* @param sDate - Optional start date in milliseconds
|
|
6864
|
-
* @param eDate - Optional end date in milliseconds
|
|
6865
|
-
* @returns Promise resolving to array of candle data
|
|
6866
|
-
*
|
|
6867
|
-
* @example
|
|
6868
|
-
* ```typescript
|
|
6869
|
-
* // Fetch 100 candles backward from current context time
|
|
6870
|
-
* const candles = await getRawCandles("BTCUSDT", "1m", 100);
|
|
6871
|
-
*
|
|
6872
|
-
* // Fetch candles for specific date range
|
|
6873
|
-
* const rangeCandles = await getRawCandles("BTCUSDT", "1h", undefined, startMs, endMs);
|
|
6874
|
-
*
|
|
6875
|
-
* // Fetch with all parameters specified
|
|
6876
|
-
* const exactCandles = await getRawCandles("BTCUSDT", "1m", 100, startMs, endMs);
|
|
6877
|
-
* ```
|
|
6878
|
-
*/
|
|
6879
|
-
declare function getRawCandles(symbol: string, interval: CandleInterval, limit?: number, sDate?: number, eDate?: number): Promise<ICandleData[]>;
|
|
6880
|
-
|
|
6881
|
-
/**
|
|
6882
|
-
* Commits signal prompt history to the message array.
|
|
6883
|
-
*
|
|
6884
|
-
* Extracts trading context from ExecutionContext and MethodContext,
|
|
6885
|
-
* then adds signal-specific system prompts at the beginning and user prompt
|
|
6886
|
-
* at the end of the history array if they are not empty.
|
|
6887
|
-
*
|
|
6888
|
-
* Context extraction:
|
|
6889
|
-
* - symbol: Provided as parameter for debugging convenience
|
|
6890
|
-
* - backtest mode: From ExecutionContext
|
|
6891
|
-
* - strategyName, exchangeName, frameName: From MethodContext
|
|
6892
|
-
*
|
|
6893
|
-
* @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
|
|
6894
|
-
* @param history - Message array to append prompts to
|
|
6895
|
-
* @returns Promise that resolves when prompts are added
|
|
6896
|
-
* @throws Error if ExecutionContext or MethodContext is not active
|
|
6897
|
-
*
|
|
6898
|
-
* @example
|
|
6899
|
-
* ```typescript
|
|
6900
|
-
* const messages: MessageModel[] = [];
|
|
6901
|
-
* await commitSignalPromptHistory("BTCUSDT", messages);
|
|
6902
|
-
* // messages now contains system prompts at start and user prompt at end
|
|
6903
|
-
* ```
|
|
6904
|
-
*/
|
|
6905
|
-
declare function commitSignalPromptHistory(symbol: string, history: MessageModel[]): Promise<void>;
|
|
6906
|
-
|
|
6907
|
-
/**
|
|
6908
|
-
* Dumps signal data and LLM conversation history to markdown files.
|
|
6909
|
-
* Used by AI-powered strategies to save debug logs for analysis.
|
|
6910
|
-
*
|
|
6911
|
-
* Creates a directory structure with:
|
|
6912
|
-
* - 00_system_prompt.md - System messages and output summary
|
|
6913
|
-
* - XX_user_message.md - Each user message in separate file (numbered)
|
|
6914
|
-
* - XX_llm_output.md - Final LLM output with signal data
|
|
6915
|
-
*
|
|
6916
|
-
* Skips if directory already exists to avoid overwriting previous results.
|
|
6183
|
+
* Parameter combinations:
|
|
6184
|
+
* 1. sDate + eDate + limit: fetches with explicit parameters, validates eDate <= when
|
|
6185
|
+
* 2. sDate + eDate: calculates limit from date range, validates eDate <= when
|
|
6186
|
+
* 3. eDate + limit: calculates sDate backward, validates eDate <= when
|
|
6187
|
+
* 4. sDate + limit: fetches forward, validates calculated endTimestamp <= when
|
|
6188
|
+
* 5. Only limit: uses execution.context.when as reference (backward)
|
|
6917
6189
|
*
|
|
6918
|
-
* @param
|
|
6919
|
-
* @param
|
|
6920
|
-
* @param
|
|
6921
|
-
* @param
|
|
6922
|
-
* @
|
|
6190
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
6191
|
+
* @param interval - Candle interval ("1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h")
|
|
6192
|
+
* @param limit - Optional number of candles to fetch
|
|
6193
|
+
* @param sDate - Optional start date in milliseconds
|
|
6194
|
+
* @param eDate - Optional end date in milliseconds
|
|
6195
|
+
* @returns Promise resolving to array of candle data
|
|
6923
6196
|
*
|
|
6924
6197
|
* @example
|
|
6925
6198
|
* ```typescript
|
|
6926
|
-
*
|
|
6927
|
-
*
|
|
6928
|
-
*
|
|
6929
|
-
* addStrategy({
|
|
6930
|
-
* strategyName: "llm-strategy",
|
|
6931
|
-
* interval: "5m",
|
|
6932
|
-
* getSignal: async (symbol) => {
|
|
6933
|
-
* const messages = [];
|
|
6934
|
-
*
|
|
6935
|
-
* // Build multi-timeframe analysis conversation
|
|
6936
|
-
* const candles1h = await getCandles(symbol, "1h", 24);
|
|
6937
|
-
* messages.push(
|
|
6938
|
-
* { role: "user", content: `Analyze 1h trend:\n${formatCandles(candles1h)}` },
|
|
6939
|
-
* { role: "assistant", content: "Trend analyzed" }
|
|
6940
|
-
* );
|
|
6941
|
-
*
|
|
6942
|
-
* const candles5m = await getCandles(symbol, "5m", 24);
|
|
6943
|
-
* messages.push(
|
|
6944
|
-
* { role: "user", content: `Analyze 5m structure:\n${formatCandles(candles5m)}` },
|
|
6945
|
-
* { role: "assistant", content: "Structure analyzed" }
|
|
6946
|
-
* );
|
|
6947
|
-
*
|
|
6948
|
-
* // Request signal
|
|
6949
|
-
* messages.push({
|
|
6950
|
-
* role: "user",
|
|
6951
|
-
* content: "Generate trading signal. Use position: 'wait' if uncertain."
|
|
6952
|
-
* });
|
|
6953
|
-
*
|
|
6954
|
-
* const resultId = uuid();
|
|
6955
|
-
* const signal = await llmRequest(messages);
|
|
6956
|
-
*
|
|
6957
|
-
* // Save conversation and result for debugging
|
|
6958
|
-
* await dumpSignal(resultId, messages, signal);
|
|
6199
|
+
* // Fetch 100 candles backward from current context time
|
|
6200
|
+
* const candles = await getRawCandles("BTCUSDT", "1m", 100);
|
|
6959
6201
|
*
|
|
6960
|
-
*
|
|
6961
|
-
*
|
|
6962
|
-
* });
|
|
6202
|
+
* // Fetch candles for specific date range
|
|
6203
|
+
* const rangeCandles = await getRawCandles("BTCUSDT", "1h", undefined, startMs, endMs);
|
|
6963
6204
|
*
|
|
6964
|
-
* //
|
|
6965
|
-
*
|
|
6966
|
-
* // ./dump/strategy/{uuid}/02_assistant_message.md
|
|
6967
|
-
* // ./dump/strategy/{uuid}/03_user_message.md (5m analysis)
|
|
6968
|
-
* // ./dump/strategy/{uuid}/04_assistant_message.md
|
|
6969
|
-
* // ./dump/strategy/{uuid}/05_user_message.md (signal request)
|
|
6970
|
-
* // ./dump/strategy/{uuid}/06_llm_output.md (final signal)
|
|
6205
|
+
* // Fetch with all parameters specified
|
|
6206
|
+
* const exactCandles = await getRawCandles("BTCUSDT", "1m", 100, startMs, endMs);
|
|
6971
6207
|
* ```
|
|
6972
6208
|
*/
|
|
6973
|
-
declare function
|
|
6209
|
+
declare function getRawCandles(symbol: string, interval: CandleInterval, limit?: number, sDate?: number, eDate?: number): Promise<ICandleData[]>;
|
|
6974
6210
|
|
|
6975
6211
|
/**
|
|
6976
6212
|
* Portfolio heatmap statistics for a single symbol.
|
|
@@ -11868,83 +11104,6 @@ declare class PositionSizeUtils {
|
|
|
11868
11104
|
}
|
|
11869
11105
|
declare const PositionSize: typeof PositionSizeUtils;
|
|
11870
11106
|
|
|
11871
|
-
/**
|
|
11872
|
-
* Public API utilities for optimizer operations.
|
|
11873
|
-
* Provides high-level methods for strategy generation and code export.
|
|
11874
|
-
*
|
|
11875
|
-
* Usage:
|
|
11876
|
-
* ```typescript
|
|
11877
|
-
* import { Optimizer } from "backtest-kit";
|
|
11878
|
-
*
|
|
11879
|
-
* // Get strategy data
|
|
11880
|
-
* const strategies = await Optimizer.getData("BTCUSDT", {
|
|
11881
|
-
* optimizerName: "my-optimizer"
|
|
11882
|
-
* });
|
|
11883
|
-
*
|
|
11884
|
-
* // Generate code
|
|
11885
|
-
* const code = await Optimizer.getCode("BTCUSDT", {
|
|
11886
|
-
* optimizerName: "my-optimizer"
|
|
11887
|
-
* });
|
|
11888
|
-
*
|
|
11889
|
-
* // Save to file
|
|
11890
|
-
* await Optimizer.dump("BTCUSDT", {
|
|
11891
|
-
* optimizerName: "my-optimizer"
|
|
11892
|
-
* }, "./output");
|
|
11893
|
-
* ```
|
|
11894
|
-
*/
|
|
11895
|
-
declare class OptimizerUtils {
|
|
11896
|
-
/**
|
|
11897
|
-
* Fetches data from all sources and generates strategy metadata.
|
|
11898
|
-
* Processes each training range and builds LLM conversation history.
|
|
11899
|
-
*
|
|
11900
|
-
* @param symbol - Trading pair symbol
|
|
11901
|
-
* @param context - Context with optimizerName
|
|
11902
|
-
* @returns Array of generated strategies with conversation context
|
|
11903
|
-
* @throws Error if optimizer not found
|
|
11904
|
-
*/
|
|
11905
|
-
getData: (symbol: string, context: {
|
|
11906
|
-
optimizerName: OptimizerName;
|
|
11907
|
-
}) => Promise<IOptimizerStrategy[]>;
|
|
11908
|
-
/**
|
|
11909
|
-
* Generates complete executable strategy code.
|
|
11910
|
-
* Includes imports, helpers, strategies, walker, and launcher.
|
|
11911
|
-
*
|
|
11912
|
-
* @param symbol - Trading pair symbol
|
|
11913
|
-
* @param context - Context with optimizerName
|
|
11914
|
-
* @returns Generated TypeScript/JavaScript code as string
|
|
11915
|
-
* @throws Error if optimizer not found
|
|
11916
|
-
*/
|
|
11917
|
-
getCode: (symbol: string, context: {
|
|
11918
|
-
optimizerName: OptimizerName;
|
|
11919
|
-
}) => Promise<string>;
|
|
11920
|
-
/**
|
|
11921
|
-
* Generates and saves strategy code to file.
|
|
11922
|
-
* Creates directory if needed, writes .mjs file.
|
|
11923
|
-
*
|
|
11924
|
-
* Format: `{optimizerName}_{symbol}.mjs`
|
|
11925
|
-
*
|
|
11926
|
-
* @param symbol - Trading pair symbol
|
|
11927
|
-
* @param context - Context with optimizerName
|
|
11928
|
-
* @param path - Output directory path (default: "./")
|
|
11929
|
-
* @throws Error if optimizer not found or file write fails
|
|
11930
|
-
*/
|
|
11931
|
-
dump: (symbol: string, context: {
|
|
11932
|
-
optimizerName: string;
|
|
11933
|
-
}, path?: string) => Promise<void>;
|
|
11934
|
-
}
|
|
11935
|
-
/**
|
|
11936
|
-
* Singleton instance of OptimizerUtils.
|
|
11937
|
-
* Public API for optimizer operations.
|
|
11938
|
-
*
|
|
11939
|
-
* @example
|
|
11940
|
-
* ```typescript
|
|
11941
|
-
* import { Optimizer } from "backtest-kit";
|
|
11942
|
-
*
|
|
11943
|
-
* await Optimizer.dump("BTCUSDT", { optimizerName: "my-optimizer" });
|
|
11944
|
-
* ```
|
|
11945
|
-
*/
|
|
11946
|
-
declare const Optimizer: OptimizerUtils;
|
|
11947
|
-
|
|
11948
11107
|
/**
|
|
11949
11108
|
* Type alias for column configuration used in partial profit/loss markdown reports.
|
|
11950
11109
|
*
|
|
@@ -14153,11 +13312,6 @@ declare const progressBacktestEmitter: Subject<ProgressBacktestContract>;
|
|
|
14153
13312
|
* Emits progress updates during walker execution.
|
|
14154
13313
|
*/
|
|
14155
13314
|
declare const progressWalkerEmitter: Subject<ProgressWalkerContract>;
|
|
14156
|
-
/**
|
|
14157
|
-
* Progress emitter for optimizer execution progress.
|
|
14158
|
-
* Emits progress updates during optimizer execution.
|
|
14159
|
-
*/
|
|
14160
|
-
declare const progressOptimizerEmitter: Subject<ProgressOptimizerContract>;
|
|
14161
13315
|
/**
|
|
14162
13316
|
* Performance emitter for execution metrics.
|
|
14163
13317
|
* Emits performance metrics for profiling and bottleneck detection.
|
|
@@ -14230,7 +13384,6 @@ declare const emitters_partialLossSubject: typeof partialLossSubject;
|
|
|
14230
13384
|
declare const emitters_partialProfitSubject: typeof partialProfitSubject;
|
|
14231
13385
|
declare const emitters_performanceEmitter: typeof performanceEmitter;
|
|
14232
13386
|
declare const emitters_progressBacktestEmitter: typeof progressBacktestEmitter;
|
|
14233
|
-
declare const emitters_progressOptimizerEmitter: typeof progressOptimizerEmitter;
|
|
14234
13387
|
declare const emitters_progressWalkerEmitter: typeof progressWalkerEmitter;
|
|
14235
13388
|
declare const emitters_riskSubject: typeof riskSubject;
|
|
14236
13389
|
declare const emitters_schedulePingSubject: typeof schedulePingSubject;
|
|
@@ -14242,7 +13395,7 @@ declare const emitters_walkerCompleteSubject: typeof walkerCompleteSubject;
|
|
|
14242
13395
|
declare const emitters_walkerEmitter: typeof walkerEmitter;
|
|
14243
13396
|
declare const emitters_walkerStopSubject: typeof walkerStopSubject;
|
|
14244
13397
|
declare namespace emitters {
|
|
14245
|
-
export { emitters_activePingSubject as activePingSubject, emitters_breakevenSubject as breakevenSubject, emitters_doneBacktestSubject as doneBacktestSubject, emitters_doneLiveSubject as doneLiveSubject, emitters_doneWalkerSubject as doneWalkerSubject, emitters_errorEmitter as errorEmitter, emitters_exitEmitter as exitEmitter, emitters_partialLossSubject as partialLossSubject, emitters_partialProfitSubject as partialProfitSubject, emitters_performanceEmitter as performanceEmitter, emitters_progressBacktestEmitter as progressBacktestEmitter,
|
|
13398
|
+
export { emitters_activePingSubject as activePingSubject, emitters_breakevenSubject as breakevenSubject, emitters_doneBacktestSubject as doneBacktestSubject, emitters_doneLiveSubject as doneLiveSubject, emitters_doneWalkerSubject as doneWalkerSubject, emitters_errorEmitter as errorEmitter, emitters_exitEmitter as exitEmitter, emitters_partialLossSubject as partialLossSubject, emitters_partialProfitSubject as partialProfitSubject, emitters_performanceEmitter as performanceEmitter, emitters_progressBacktestEmitter as progressBacktestEmitter, emitters_progressWalkerEmitter as progressWalkerEmitter, emitters_riskSubject as riskSubject, emitters_schedulePingSubject as schedulePingSubject, emitters_signalBacktestEmitter as signalBacktestEmitter, emitters_signalEmitter as signalEmitter, emitters_signalLiveEmitter as signalLiveEmitter, emitters_validationSubject as validationSubject, emitters_walkerCompleteSubject as walkerCompleteSubject, emitters_walkerEmitter as walkerEmitter, emitters_walkerStopSubject as walkerStopSubject };
|
|
14246
13399
|
}
|
|
14247
13400
|
|
|
14248
13401
|
/**
|
|
@@ -18047,364 +17200,6 @@ declare class ActionValidationService {
|
|
|
18047
17200
|
list: () => Promise<IActionSchema[]>;
|
|
18048
17201
|
}
|
|
18049
17202
|
|
|
18050
|
-
/**
|
|
18051
|
-
* Default template service for generating optimizer code snippets.
|
|
18052
|
-
* Implements all IOptimizerTemplate methods with Ollama LLM integration.
|
|
18053
|
-
*
|
|
18054
|
-
* Features:
|
|
18055
|
-
* - Multi-timeframe analysis (1m, 5m, 15m, 1h)
|
|
18056
|
-
* - JSON structured output for signals
|
|
18057
|
-
* - Debug logging to ./dump/strategy
|
|
18058
|
-
* - CCXT exchange integration
|
|
18059
|
-
* - Walker-based strategy comparison
|
|
18060
|
-
*
|
|
18061
|
-
* Can be partially overridden in optimizer schema configuration.
|
|
18062
|
-
*/
|
|
18063
|
-
declare class OptimizerTemplateService implements IOptimizerTemplate {
|
|
18064
|
-
private readonly loggerService;
|
|
18065
|
-
/**
|
|
18066
|
-
* Generates the top banner with imports and constants.
|
|
18067
|
-
*
|
|
18068
|
-
* @param symbol - Trading pair symbol
|
|
18069
|
-
* @returns Shebang, imports, and WARN_KB constant
|
|
18070
|
-
*/
|
|
18071
|
-
getTopBanner: (symbol: string) => Promise<string>;
|
|
18072
|
-
/**
|
|
18073
|
-
* Generates default user message for LLM conversation.
|
|
18074
|
-
* Simple prompt to read and acknowledge data.
|
|
18075
|
-
*
|
|
18076
|
-
* @param symbol - Trading pair symbol
|
|
18077
|
-
* @param data - Fetched data array
|
|
18078
|
-
* @param name - Source name
|
|
18079
|
-
* @returns User message with JSON data
|
|
18080
|
-
*/
|
|
18081
|
-
getUserMessage: (symbol: string, data: IOptimizerData[], name: string) => Promise<string>;
|
|
18082
|
-
/**
|
|
18083
|
-
* Generates default assistant message for LLM conversation.
|
|
18084
|
-
* Simple acknowledgment response.
|
|
18085
|
-
*
|
|
18086
|
-
* @param symbol - Trading pair symbol
|
|
18087
|
-
* @param data - Fetched data array
|
|
18088
|
-
* @param name - Source name
|
|
18089
|
-
* @returns Assistant acknowledgment message
|
|
18090
|
-
*/
|
|
18091
|
-
getAssistantMessage: (symbol: string, data: IOptimizerData[], name: string) => Promise<string>;
|
|
18092
|
-
/**
|
|
18093
|
-
* Generates Walker configuration code.
|
|
18094
|
-
* Compares multiple strategies on test frame.
|
|
18095
|
-
*
|
|
18096
|
-
* @param walkerName - Unique walker identifier
|
|
18097
|
-
* @param exchangeName - Exchange to use for backtesting
|
|
18098
|
-
* @param frameName - Test frame name
|
|
18099
|
-
* @param strategies - Array of strategy names to compare
|
|
18100
|
-
* @returns Generated addWalker() call
|
|
18101
|
-
*/
|
|
18102
|
-
getWalkerTemplate: (walkerName: WalkerName, exchangeName: ExchangeName, frameName: FrameName, strategies: string[]) => Promise<string>;
|
|
18103
|
-
/**
|
|
18104
|
-
* Generates Strategy configuration with LLM integration.
|
|
18105
|
-
* Includes multi-timeframe analysis and signal generation.
|
|
18106
|
-
*
|
|
18107
|
-
* @param strategyName - Unique strategy identifier
|
|
18108
|
-
* @param interval - Signal throttling interval (e.g., "5m")
|
|
18109
|
-
* @param prompt - Strategy logic from getPrompt()
|
|
18110
|
-
* @returns Generated addStrategy() call with getSignal() function
|
|
18111
|
-
*/
|
|
18112
|
-
getStrategyTemplate: (strategyName: StrategyName, interval: CandleInterval, prompt: string) => Promise<string>;
|
|
18113
|
-
/**
|
|
18114
|
-
* Generates Exchange configuration code.
|
|
18115
|
-
* Uses CCXT Binance with standard formatters.
|
|
18116
|
-
*
|
|
18117
|
-
* @param symbol - Trading pair symbol (unused, for consistency)
|
|
18118
|
-
* @param exchangeName - Unique exchange identifier
|
|
18119
|
-
* @returns Generated addExchange() call with CCXT integration
|
|
18120
|
-
*/
|
|
18121
|
-
getExchangeTemplate: (symbol: string, exchangeName: ExchangeName) => Promise<string>;
|
|
18122
|
-
/**
|
|
18123
|
-
* Generates Frame (timeframe) configuration code.
|
|
18124
|
-
*
|
|
18125
|
-
* @param symbol - Trading pair symbol (unused, for consistency)
|
|
18126
|
-
* @param frameName - Unique frame identifier
|
|
18127
|
-
* @param interval - Candle interval (e.g., "1m")
|
|
18128
|
-
* @param startDate - Frame start date
|
|
18129
|
-
* @param endDate - Frame end date
|
|
18130
|
-
* @returns Generated addFrame() call
|
|
18131
|
-
*/
|
|
18132
|
-
getFrameTemplate: (symbol: string, frameName: FrameName, interval: CandleInterval, startDate: Date, endDate: Date) => Promise<string>;
|
|
18133
|
-
/**
|
|
18134
|
-
* Generates launcher code to run Walker with event listeners.
|
|
18135
|
-
* Includes progress tracking and completion handlers.
|
|
18136
|
-
*
|
|
18137
|
-
* @param symbol - Trading pair symbol
|
|
18138
|
-
* @param walkerName - Walker name to launch
|
|
18139
|
-
* @returns Generated Walker.background() call with listeners
|
|
18140
|
-
*/
|
|
18141
|
-
getLauncherTemplate: (symbol: string, walkerName: WalkerName) => Promise<string>;
|
|
18142
|
-
/**
|
|
18143
|
-
* Generates dumpJson() helper function for debug output.
|
|
18144
|
-
* Saves LLM conversations and results to ./dump/strategy/{resultId}/
|
|
18145
|
-
*
|
|
18146
|
-
* @param symbol - Trading pair symbol (unused, for consistency)
|
|
18147
|
-
* @returns Generated async dumpJson() function
|
|
18148
|
-
*/
|
|
18149
|
-
getJsonDumpTemplate: (symbol: string) => Promise<string>;
|
|
18150
|
-
/**
|
|
18151
|
-
* Generates text() helper for LLM text generation.
|
|
18152
|
-
* Uses Ollama deepseek-v3.1:671b model for market analysis.
|
|
18153
|
-
*
|
|
18154
|
-
* @param symbol - Trading pair symbol (used in prompt)
|
|
18155
|
-
* @returns Generated async text() function
|
|
18156
|
-
*/
|
|
18157
|
-
getTextTemplate: (symbol: string) => Promise<string>;
|
|
18158
|
-
/**
|
|
18159
|
-
* Generates json() helper for structured LLM output.
|
|
18160
|
-
* Uses Ollama with JSON schema for trading signals.
|
|
18161
|
-
*
|
|
18162
|
-
* Signal schema:
|
|
18163
|
-
* - position: "wait" | "long" | "short"
|
|
18164
|
-
* - note: strategy explanation
|
|
18165
|
-
* - priceOpen: entry price
|
|
18166
|
-
* - priceTakeProfit: target price
|
|
18167
|
-
* - priceStopLoss: stop price
|
|
18168
|
-
* - minuteEstimatedTime: expected duration (max 360 min)
|
|
18169
|
-
*
|
|
18170
|
-
* @param symbol - Trading pair symbol (unused, for consistency)
|
|
18171
|
-
* @returns Generated async json() function with signal schema
|
|
18172
|
-
*/
|
|
18173
|
-
getJsonTemplate: (symbol: string) => Promise<string>;
|
|
18174
|
-
}
|
|
18175
|
-
|
|
18176
|
-
/**
|
|
18177
|
-
* Service for managing optimizer schema registration and retrieval.
|
|
18178
|
-
* Provides validation and registry management for optimizer configurations.
|
|
18179
|
-
*
|
|
18180
|
-
* Uses ToolRegistry for immutable schema storage.
|
|
18181
|
-
*/
|
|
18182
|
-
declare class OptimizerSchemaService {
|
|
18183
|
-
readonly loggerService: LoggerService;
|
|
18184
|
-
private _registry;
|
|
18185
|
-
/**
|
|
18186
|
-
* Registers a new optimizer schema.
|
|
18187
|
-
* Validates required fields before registration.
|
|
18188
|
-
*
|
|
18189
|
-
* @param key - Unique optimizer name
|
|
18190
|
-
* @param value - Optimizer schema configuration
|
|
18191
|
-
* @throws Error if schema validation fails
|
|
18192
|
-
*/
|
|
18193
|
-
register: (key: OptimizerName, value: IOptimizerSchema) => void;
|
|
18194
|
-
/**
|
|
18195
|
-
* Validates optimizer schema structure.
|
|
18196
|
-
* Checks required fields: optimizerName, rangeTrain, source, getPrompt.
|
|
18197
|
-
*
|
|
18198
|
-
* @param optimizerSchema - Schema to validate
|
|
18199
|
-
* @throws Error if validation fails
|
|
18200
|
-
*/
|
|
18201
|
-
private validateShallow;
|
|
18202
|
-
/**
|
|
18203
|
-
* Partially overrides an existing optimizer schema.
|
|
18204
|
-
* Merges provided values with existing schema.
|
|
18205
|
-
*
|
|
18206
|
-
* @param key - Optimizer name to override
|
|
18207
|
-
* @param value - Partial schema values to merge
|
|
18208
|
-
* @returns Updated complete schema
|
|
18209
|
-
* @throws Error if optimizer not found
|
|
18210
|
-
*/
|
|
18211
|
-
override: (key: OptimizerName, value: Partial<IOptimizerSchema>) => IOptimizerSchema;
|
|
18212
|
-
/**
|
|
18213
|
-
* Retrieves optimizer schema by name.
|
|
18214
|
-
*
|
|
18215
|
-
* @param key - Optimizer name
|
|
18216
|
-
* @returns Complete optimizer schema
|
|
18217
|
-
* @throws Error if optimizer not found
|
|
18218
|
-
*/
|
|
18219
|
-
get: (key: OptimizerName) => IOptimizerSchema;
|
|
18220
|
-
}
|
|
18221
|
-
|
|
18222
|
-
/**
|
|
18223
|
-
* Service for validating optimizer existence and managing optimizer registry.
|
|
18224
|
-
* Maintains a Map of registered optimizers for validation purposes.
|
|
18225
|
-
*
|
|
18226
|
-
* Uses memoization for efficient repeated validation checks.
|
|
18227
|
-
*/
|
|
18228
|
-
declare class OptimizerValidationService {
|
|
18229
|
-
private readonly loggerService;
|
|
18230
|
-
private _optimizerMap;
|
|
18231
|
-
/**
|
|
18232
|
-
* Adds optimizer to validation registry.
|
|
18233
|
-
* Prevents duplicate optimizer names.
|
|
18234
|
-
*
|
|
18235
|
-
* @param optimizerName - Unique optimizer identifier
|
|
18236
|
-
* @param optimizerSchema - Complete optimizer schema
|
|
18237
|
-
* @throws Error if optimizer with same name already exists
|
|
18238
|
-
*/
|
|
18239
|
-
addOptimizer: (optimizerName: OptimizerName, optimizerSchema: IOptimizerSchema) => void;
|
|
18240
|
-
/**
|
|
18241
|
-
* Validates that optimizer exists in registry.
|
|
18242
|
-
* Memoized for performance on repeated checks.
|
|
18243
|
-
*
|
|
18244
|
-
* @param optimizerName - Optimizer name to validate
|
|
18245
|
-
* @param source - Source method name for error messages
|
|
18246
|
-
* @throws Error if optimizer not found
|
|
18247
|
-
*/
|
|
18248
|
-
validate: (optimizerName: OptimizerName, source: string) => void;
|
|
18249
|
-
/**
|
|
18250
|
-
* Lists all registered optimizer schemas.
|
|
18251
|
-
*
|
|
18252
|
-
* @returns Array of all optimizer schemas
|
|
18253
|
-
*/
|
|
18254
|
-
list: () => Promise<IOptimizerSchema[]>;
|
|
18255
|
-
}
|
|
18256
|
-
|
|
18257
|
-
/**
|
|
18258
|
-
* Client implementation for optimizer operations.
|
|
18259
|
-
*
|
|
18260
|
-
* Features:
|
|
18261
|
-
* - Data collection from multiple sources with pagination
|
|
18262
|
-
* - LLM conversation history building
|
|
18263
|
-
* - Strategy code generation with templates
|
|
18264
|
-
* - File export with callbacks
|
|
18265
|
-
*
|
|
18266
|
-
* Used by OptimizerConnectionService to create optimizer instances.
|
|
18267
|
-
*/
|
|
18268
|
-
declare class ClientOptimizer implements IOptimizer {
|
|
18269
|
-
readonly params: IOptimizerParams;
|
|
18270
|
-
readonly onProgress: (progress: ProgressOptimizerContract) => void;
|
|
18271
|
-
constructor(params: IOptimizerParams, onProgress: (progress: ProgressOptimizerContract) => void);
|
|
18272
|
-
/**
|
|
18273
|
-
* Fetches data from all sources and generates strategy metadata.
|
|
18274
|
-
* Processes each training range and builds LLM conversation history.
|
|
18275
|
-
*
|
|
18276
|
-
* @param symbol - Trading pair symbol
|
|
18277
|
-
* @returns Array of generated strategies with conversation context
|
|
18278
|
-
*/
|
|
18279
|
-
getData: (symbol: string) => Promise<IOptimizerStrategy[]>;
|
|
18280
|
-
/**
|
|
18281
|
-
* Generates complete executable strategy code.
|
|
18282
|
-
* Includes imports, helpers, strategies, walker, and launcher.
|
|
18283
|
-
*
|
|
18284
|
-
* @param symbol - Trading pair symbol
|
|
18285
|
-
* @returns Generated TypeScript/JavaScript code as string
|
|
18286
|
-
*/
|
|
18287
|
-
getCode: (symbol: string) => Promise<string>;
|
|
18288
|
-
/**
|
|
18289
|
-
* Generates and saves strategy code to file.
|
|
18290
|
-
* Creates directory if needed, writes .mjs file.
|
|
18291
|
-
*
|
|
18292
|
-
* @param symbol - Trading pair symbol
|
|
18293
|
-
* @param path - Output directory path (default: "./")
|
|
18294
|
-
*/
|
|
18295
|
-
dump: (symbol: string, path?: string) => Promise<void>;
|
|
18296
|
-
}
|
|
18297
|
-
|
|
18298
|
-
/**
|
|
18299
|
-
* Type helper for optimizer method signatures.
|
|
18300
|
-
* Maps IOptimizer interface methods to any return type.
|
|
18301
|
-
*/
|
|
18302
|
-
type TOptimizer$1 = {
|
|
18303
|
-
[key in keyof IOptimizer]: any;
|
|
18304
|
-
};
|
|
18305
|
-
/**
|
|
18306
|
-
* Service for creating and caching optimizer client instances.
|
|
18307
|
-
* Handles dependency injection and template merging.
|
|
18308
|
-
*
|
|
18309
|
-
* Features:
|
|
18310
|
-
* - Memoized optimizer instances (one per optimizerName)
|
|
18311
|
-
* - Template merging (custom + defaults)
|
|
18312
|
-
* - Logger injection
|
|
18313
|
-
* - Delegates to ClientOptimizer for actual operations
|
|
18314
|
-
*/
|
|
18315
|
-
declare class OptimizerConnectionService implements TOptimizer$1 {
|
|
18316
|
-
private readonly loggerService;
|
|
18317
|
-
private readonly optimizerSchemaService;
|
|
18318
|
-
private readonly optimizerTemplateService;
|
|
18319
|
-
/**
|
|
18320
|
-
* Creates or retrieves cached optimizer instance.
|
|
18321
|
-
* Memoized by optimizerName for performance.
|
|
18322
|
-
*
|
|
18323
|
-
* Merges custom templates from schema with defaults from OptimizerTemplateService.
|
|
18324
|
-
*
|
|
18325
|
-
* @param optimizerName - Unique optimizer identifier
|
|
18326
|
-
* @returns ClientOptimizer instance with resolved dependencies
|
|
18327
|
-
*/
|
|
18328
|
-
getOptimizer: ((optimizerName: OptimizerName) => ClientOptimizer) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientOptimizer>;
|
|
18329
|
-
/**
|
|
18330
|
-
* Fetches data from all sources and generates strategy metadata.
|
|
18331
|
-
*
|
|
18332
|
-
* @param symbol - Trading pair symbol
|
|
18333
|
-
* @param optimizerName - Optimizer identifier
|
|
18334
|
-
* @returns Array of generated strategies with conversation context
|
|
18335
|
-
*/
|
|
18336
|
-
getData: (symbol: string, optimizerName: string) => Promise<IOptimizerStrategy[]>;
|
|
18337
|
-
/**
|
|
18338
|
-
* Generates complete executable strategy code.
|
|
18339
|
-
*
|
|
18340
|
-
* @param symbol - Trading pair symbol
|
|
18341
|
-
* @param optimizerName - Optimizer identifier
|
|
18342
|
-
* @returns Generated TypeScript/JavaScript code as string
|
|
18343
|
-
*/
|
|
18344
|
-
getCode: (symbol: string, optimizerName: string) => Promise<string>;
|
|
18345
|
-
/**
|
|
18346
|
-
* Generates and saves strategy code to file.
|
|
18347
|
-
*
|
|
18348
|
-
* @param symbol - Trading pair symbol
|
|
18349
|
-
* @param optimizerName - Optimizer identifier
|
|
18350
|
-
* @param path - Output directory path (optional)
|
|
18351
|
-
*/
|
|
18352
|
-
dump: (symbol: string, optimizerName: string, path?: string) => Promise<void>;
|
|
18353
|
-
}
|
|
18354
|
-
|
|
18355
|
-
/**
|
|
18356
|
-
* Type definition for optimizer methods.
|
|
18357
|
-
* Maps all keys of IOptimizer to any type.
|
|
18358
|
-
* Used for dynamic method routing in OptimizerGlobalService.
|
|
18359
|
-
*/
|
|
18360
|
-
type TOptimizer = {
|
|
18361
|
-
[key in keyof IOptimizer]: any;
|
|
18362
|
-
};
|
|
18363
|
-
/**
|
|
18364
|
-
* Global service for optimizer operations with validation.
|
|
18365
|
-
* Entry point for public API, performs validation before delegating to ConnectionService.
|
|
18366
|
-
*
|
|
18367
|
-
* Workflow:
|
|
18368
|
-
* 1. Log operation
|
|
18369
|
-
* 2. Validate optimizer exists
|
|
18370
|
-
* 3. Delegate to OptimizerConnectionService
|
|
18371
|
-
*/
|
|
18372
|
-
declare class OptimizerGlobalService implements TOptimizer {
|
|
18373
|
-
private readonly loggerService;
|
|
18374
|
-
private readonly optimizerConnectionService;
|
|
18375
|
-
private readonly optimizerValidationService;
|
|
18376
|
-
/**
|
|
18377
|
-
* Fetches data from all sources and generates strategy metadata.
|
|
18378
|
-
* Validates optimizer existence before execution.
|
|
18379
|
-
*
|
|
18380
|
-
* @param symbol - Trading pair symbol
|
|
18381
|
-
* @param optimizerName - Optimizer identifier
|
|
18382
|
-
* @returns Array of generated strategies with conversation context
|
|
18383
|
-
* @throws Error if optimizer not found
|
|
18384
|
-
*/
|
|
18385
|
-
getData: (symbol: string, optimizerName: string) => Promise<IOptimizerStrategy[]>;
|
|
18386
|
-
/**
|
|
18387
|
-
* Generates complete executable strategy code.
|
|
18388
|
-
* Validates optimizer existence before execution.
|
|
18389
|
-
*
|
|
18390
|
-
* @param symbol - Trading pair symbol
|
|
18391
|
-
* @param optimizerName - Optimizer identifier
|
|
18392
|
-
* @returns Generated TypeScript/JavaScript code as string
|
|
18393
|
-
* @throws Error if optimizer not found
|
|
18394
|
-
*/
|
|
18395
|
-
getCode: (symbol: string, optimizerName: string) => Promise<string>;
|
|
18396
|
-
/**
|
|
18397
|
-
* Generates and saves strategy code to file.
|
|
18398
|
-
* Validates optimizer existence before execution.
|
|
18399
|
-
*
|
|
18400
|
-
* @param symbol - Trading pair symbol
|
|
18401
|
-
* @param optimizerName - Optimizer identifier
|
|
18402
|
-
* @param path - Output directory path (optional)
|
|
18403
|
-
* @throws Error if optimizer not found
|
|
18404
|
-
*/
|
|
18405
|
-
dump: (symbol: string, optimizerName: string, path?: string) => Promise<void>;
|
|
18406
|
-
}
|
|
18407
|
-
|
|
18408
17203
|
/**
|
|
18409
17204
|
* Type definition for partial methods.
|
|
18410
17205
|
* Maps all keys of IPartial to any type.
|
|
@@ -18625,54 +17420,6 @@ declare class BreakevenGlobalService implements TBreakeven {
|
|
|
18625
17420
|
clear: (symbol: string, data: IPublicSignalRow, priceClose: number, backtest: boolean) => Promise<void>;
|
|
18626
17421
|
}
|
|
18627
17422
|
|
|
18628
|
-
/**
|
|
18629
|
-
* Unique identifier for outline result.
|
|
18630
|
-
* Can be string or number for flexible ID formats.
|
|
18631
|
-
*/
|
|
18632
|
-
type ResultId = string | number;
|
|
18633
|
-
/**
|
|
18634
|
-
* Service for generating markdown documentation from LLM outline results.
|
|
18635
|
-
* Used by AI Strategy Optimizer to save debug logs and conversation history.
|
|
18636
|
-
*
|
|
18637
|
-
* Creates directory structure:
|
|
18638
|
-
* - ./dump/strategy/{signalId}/00_system_prompt.md - System messages and output data
|
|
18639
|
-
* - ./dump/strategy/{signalId}/01_user_message.md - First user input
|
|
18640
|
-
* - ./dump/strategy/{signalId}/02_user_message.md - Second user input
|
|
18641
|
-
* - ./dump/strategy/{signalId}/XX_llm_output.md - Final LLM output
|
|
18642
|
-
*/
|
|
18643
|
-
declare class OutlineMarkdownService {
|
|
18644
|
-
/** Logger service injected via DI */
|
|
18645
|
-
private readonly loggerService;
|
|
18646
|
-
/**
|
|
18647
|
-
* Dumps signal data and conversation history to markdown files.
|
|
18648
|
-
* Skips if directory already exists to avoid overwriting previous results.
|
|
18649
|
-
*
|
|
18650
|
-
* Generated files:
|
|
18651
|
-
* - 00_system_prompt.md - System messages and output summary
|
|
18652
|
-
* - XX_user_message.md - Each user message in separate file (numbered)
|
|
18653
|
-
* - XX_llm_output.md - Final LLM output with signal data
|
|
18654
|
-
*
|
|
18655
|
-
* @param signalId - Unique identifier for the result (used as directory name)
|
|
18656
|
-
* @param history - Array of message models from LLM conversation
|
|
18657
|
-
* @param signal - Signal DTO with trade parameters (priceOpen, TP, SL, etc.)
|
|
18658
|
-
* @param outputDir - Output directory path (default: "./dump/strategy")
|
|
18659
|
-
* @returns Promise that resolves when all files are written
|
|
18660
|
-
*
|
|
18661
|
-
* @example
|
|
18662
|
-
* ```typescript
|
|
18663
|
-
* await outlineService.dumpSignal(
|
|
18664
|
-
* "strategy-1",
|
|
18665
|
-
* conversationHistory,
|
|
18666
|
-
* { position: "long", priceTakeProfit: 51000, priceStopLoss: 49000, minuteEstimatedTime: 60 }
|
|
18667
|
-
* );
|
|
18668
|
-
* // Creates: ./dump/strategy/strategy-1/00_system_prompt.md
|
|
18669
|
-
* // ./dump/strategy/strategy-1/01_user_message.md
|
|
18670
|
-
* // ./dump/strategy/strategy-1/02_llm_output.md
|
|
18671
|
-
* ```
|
|
18672
|
-
*/
|
|
18673
|
-
dumpSignal: (signalId: ResultId, history: MessageModel[], signal: ISignalDto, outputDir?: string) => Promise<void>;
|
|
18674
|
-
}
|
|
18675
|
-
|
|
18676
17423
|
/**
|
|
18677
17424
|
* Service for validating GLOBAL_CONFIG parameters to ensure mathematical correctness
|
|
18678
17425
|
* and prevent unprofitable trading configurations.
|
|
@@ -19425,54 +18172,7 @@ declare class RiskReportService {
|
|
|
19425
18172
|
unsubscribe: () => Promise<void>;
|
|
19426
18173
|
}
|
|
19427
18174
|
|
|
19428
|
-
/**
|
|
19429
|
-
* Service for managing signal prompts for AI/LLM integrations.
|
|
19430
|
-
*
|
|
19431
|
-
* Provides access to system and user prompts configured in signal.prompt.cjs.
|
|
19432
|
-
* Supports both static prompt arrays and dynamic prompt functions.
|
|
19433
|
-
*
|
|
19434
|
-
* Key responsibilities:
|
|
19435
|
-
* - Lazy-loads prompt configuration from config/prompt/signal.prompt.cjs
|
|
19436
|
-
* - Resolves system prompts (static arrays or async functions)
|
|
19437
|
-
* - Provides user prompt strings
|
|
19438
|
-
* - Falls back to empty prompts if configuration is missing
|
|
19439
|
-
*
|
|
19440
|
-
* Used for AI-powered signal analysis and strategy recommendations.
|
|
19441
|
-
*/
|
|
19442
|
-
declare class SignalPromptService {
|
|
19443
|
-
private readonly loggerService;
|
|
19444
|
-
/**
|
|
19445
|
-
* Retrieves system prompts for AI context.
|
|
19446
|
-
*
|
|
19447
|
-
* System prompts can be:
|
|
19448
|
-
* - Static array of strings (returned directly)
|
|
19449
|
-
* - Async/sync function returning string array (executed and awaited)
|
|
19450
|
-
* - Undefined (returns empty array)
|
|
19451
|
-
*
|
|
19452
|
-
* @param symbol - Trading symbol (e.g., "BTCUSDT")
|
|
19453
|
-
* @param strategyName - Strategy identifier
|
|
19454
|
-
* @param exchangeName - Exchange identifier
|
|
19455
|
-
* @param frameName - Timeframe identifier
|
|
19456
|
-
* @param backtest - Whether running in backtest mode
|
|
19457
|
-
* @returns Promise resolving to array of system prompt strings
|
|
19458
|
-
*/
|
|
19459
|
-
getSystemPrompt: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<string[]>;
|
|
19460
|
-
/**
|
|
19461
|
-
* Retrieves user prompt string for AI input.
|
|
19462
|
-
*
|
|
19463
|
-
* @param symbol - Trading symbol (e.g., "BTCUSDT")
|
|
19464
|
-
* @param strategyName - Strategy identifier
|
|
19465
|
-
* @param exchangeName - Exchange identifier
|
|
19466
|
-
* @param frameName - Timeframe identifier
|
|
19467
|
-
* @param backtest - Whether running in backtest mode
|
|
19468
|
-
* @returns Promise resolving to user prompt string
|
|
19469
|
-
*/
|
|
19470
|
-
getUserPrompt: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<string>;
|
|
19471
|
-
}
|
|
19472
|
-
|
|
19473
18175
|
declare const backtest: {
|
|
19474
|
-
signalPromptService: SignalPromptService;
|
|
19475
|
-
optimizerTemplateService: OptimizerTemplateService;
|
|
19476
18176
|
exchangeValidationService: ExchangeValidationService;
|
|
19477
18177
|
strategyValidationService: StrategyValidationService;
|
|
19478
18178
|
frameValidationService: FrameValidationService;
|
|
@@ -19480,7 +18180,6 @@ declare const backtest: {
|
|
|
19480
18180
|
sizingValidationService: SizingValidationService;
|
|
19481
18181
|
riskValidationService: RiskValidationService;
|
|
19482
18182
|
actionValidationService: ActionValidationService;
|
|
19483
|
-
optimizerValidationService: OptimizerValidationService;
|
|
19484
18183
|
configValidationService: ConfigValidationService;
|
|
19485
18184
|
columnValidationService: ColumnValidationService;
|
|
19486
18185
|
backtestReportService: BacktestReportService;
|
|
@@ -19500,7 +18199,6 @@ declare const backtest: {
|
|
|
19500
18199
|
heatMarkdownService: HeatMarkdownService;
|
|
19501
18200
|
partialMarkdownService: PartialMarkdownService;
|
|
19502
18201
|
breakevenMarkdownService: BreakevenMarkdownService;
|
|
19503
|
-
outlineMarkdownService: OutlineMarkdownService;
|
|
19504
18202
|
riskMarkdownService: RiskMarkdownService;
|
|
19505
18203
|
backtestLogicPublicService: BacktestLogicPublicService;
|
|
19506
18204
|
liveLogicPublicService: LiveLogicPublicService;
|
|
@@ -19513,7 +18211,6 @@ declare const backtest: {
|
|
|
19513
18211
|
walkerCommandService: WalkerCommandService;
|
|
19514
18212
|
sizingGlobalService: SizingGlobalService;
|
|
19515
18213
|
riskGlobalService: RiskGlobalService;
|
|
19516
|
-
optimizerGlobalService: OptimizerGlobalService;
|
|
19517
18214
|
partialGlobalService: PartialGlobalService;
|
|
19518
18215
|
breakevenGlobalService: BreakevenGlobalService;
|
|
19519
18216
|
exchangeCoreService: ExchangeCoreService;
|
|
@@ -19527,14 +18224,12 @@ declare const backtest: {
|
|
|
19527
18224
|
sizingSchemaService: SizingSchemaService;
|
|
19528
18225
|
riskSchemaService: RiskSchemaService;
|
|
19529
18226
|
actionSchemaService: ActionSchemaService;
|
|
19530
|
-
optimizerSchemaService: OptimizerSchemaService;
|
|
19531
18227
|
exchangeConnectionService: ExchangeConnectionService;
|
|
19532
18228
|
strategyConnectionService: StrategyConnectionService;
|
|
19533
18229
|
frameConnectionService: FrameConnectionService;
|
|
19534
18230
|
sizingConnectionService: SizingConnectionService;
|
|
19535
18231
|
riskConnectionService: RiskConnectionService;
|
|
19536
18232
|
actionConnectionService: ActionConnectionService;
|
|
19537
|
-
optimizerConnectionService: OptimizerConnectionService;
|
|
19538
18233
|
partialConnectionService: PartialConnectionService;
|
|
19539
18234
|
breakevenConnectionService: BreakevenConnectionService;
|
|
19540
18235
|
executionContextService: {
|
|
@@ -19546,4 +18241,4 @@ declare const backtest: {
|
|
|
19546
18241
|
loggerService: LoggerService;
|
|
19547
18242
|
};
|
|
19548
18243
|
|
|
19549
|
-
export { ActionBase, type ActivePingContract, Backtest, type BacktestDoneNotification, type BacktestStatisticsModel, Breakeven, type BreakevenContract, type BreakevenData, Cache, type CandleData, type CandleInterval, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type IBidData, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IMarkdownDumpOptions, type
|
|
18244
|
+
export { ActionBase, type ActivePingContract, Backtest, type BacktestDoneNotification, type BacktestStatisticsModel, Breakeven, type BreakevenContract, type BreakevenData, Cache, type CandleData, type CandleInterval, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type IBidData, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IMarkdownDumpOptions, type IOrderBookData, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IPublicSignalRow, type IReportDumpOptions, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, type IScheduledSignalCancelRow, type IScheduledSignalRow, type ISignalDto, type ISignalRow, type ISizingCalculateParams, type ISizingCalculateParamsATR, type ISizingCalculateParamsFixedPercentage, type ISizingCalculateParamsKelly, type ISizingSchema, type ISizingSchemaATR, type ISizingSchemaFixedPercentage, type ISizingSchemaKelly, type IStrategyPnL, type IStrategyResult, type IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, type InfoErrorNotification, Live, type LiveDoneNotification, type LiveStatisticsModel, Markdown, MarkdownFileBase, MarkdownFolderBase, type MarkdownName, MethodContextService, type MetricStats, Notification, type NotificationModel, Partial$1 as Partial, type PartialData, type PartialEvent, type PartialLossContract, type PartialLossNotification, type PartialProfitContract, type PartialProfitNotification, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistBreakevenAdapter, PersistCandleAdapter, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, PositionSize, type ProgressBacktestContract, type ProgressBacktestNotification, type ProgressWalkerContract, Report, ReportBase, type ReportName, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, Schedule, type ScheduleData, type SchedulePingContract, type ScheduleStatisticsModel, type ScheduledEvent, type SignalCancelledNotification, type SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenedNotification, type SignalScheduledNotification, type TMarkdownBase, type TPersistBase, type TPersistBaseCtor, type TReportBase, type TickEvent, type ValidationErrorNotification, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type SignalData$1 as WalkerSignalData, type WalkerStatisticsModel, addActionSchema, addExchangeSchema, addFrameSchema, addRiskSchema, addSizingSchema, addStrategySchema, addWalkerSchema, commitBreakeven, commitCancelScheduled, commitClosePending, commitPartialLoss, commitPartialProfit, commitTrailingStop, commitTrailingTake, emitters, formatPrice, formatQuantity, get, getActionSchema, getAveragePrice, getBacktestTimeframe, getCandles, getColumns, getConfig, getContext, getDate, getDefaultColumns, getDefaultConfig, getExchangeSchema, getFrameSchema, getMode, getOrderBook, getRawCandles, getRiskSchema, getSizingSchema, getStrategySchema, getSymbol, getWalkerSchema, hasTradeContext, backtest as lib, listExchangeSchema, listFrameSchema, listRiskSchema, listSizingSchema, listStrategySchema, listWalkerSchema, listenActivePing, listenActivePingOnce, listenBacktestProgress, listenBreakevenAvailable, listenBreakevenAvailableOnce, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenPartialLossAvailable, listenPartialLossAvailableOnce, listenPartialProfitAvailable, listenPartialProfitAvailableOnce, listenPerformance, listenRisk, listenRiskOnce, listenSchedulePing, listenSchedulePingOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, overrideActionSchema, overrideExchangeSchema, overrideFrameSchema, overrideRiskSchema, overrideSizingSchema, overrideStrategySchema, overrideWalkerSchema, parseArgs, roundTicks, set, setColumns, setConfig, setLogger, stopStrategy, validate };
|