backtest-kit 1.4.11 → 1.4.13
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 +328 -84
- package/build/index.mjs +328 -85
- package/package.json +1 -1
- package/types.d.ts +182 -53
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -3616,6 +3616,74 @@ declare function getDate(): Promise<Date>;
|
|
|
3616
3616
|
*/
|
|
3617
3617
|
declare function getMode(): Promise<"backtest" | "live">;
|
|
3618
3618
|
|
|
3619
|
+
/**
|
|
3620
|
+
* Dumps signal data and LLM conversation history to markdown files.
|
|
3621
|
+
* Used by AI-powered strategies to save debug logs for analysis.
|
|
3622
|
+
*
|
|
3623
|
+
* Creates a directory structure with:
|
|
3624
|
+
* - 00_system_prompt.md - System messages and output summary
|
|
3625
|
+
* - XX_user_message.md - Each user message in separate file (numbered)
|
|
3626
|
+
* - XX_llm_output.md - Final LLM output with signal data
|
|
3627
|
+
*
|
|
3628
|
+
* Skips if directory already exists to avoid overwriting previous results.
|
|
3629
|
+
*
|
|
3630
|
+
* @param signalId - Unique identifier for the result (used as directory name, e.g., UUID)
|
|
3631
|
+
* @param history - Array of message models from LLM conversation
|
|
3632
|
+
* @param signal - Signal DTO returned by LLM (position, priceOpen, TP, SL, etc.)
|
|
3633
|
+
* @param outputDir - Output directory path (default: "./dump/strategy")
|
|
3634
|
+
* @returns Promise that resolves when all files are written
|
|
3635
|
+
*
|
|
3636
|
+
* @example
|
|
3637
|
+
* ```typescript
|
|
3638
|
+
* import { dumpSignal, getCandles } from "backtest-kit";
|
|
3639
|
+
* import { v4 as uuid } from "uuid";
|
|
3640
|
+
*
|
|
3641
|
+
* addStrategy({
|
|
3642
|
+
* strategyName: "llm-strategy",
|
|
3643
|
+
* interval: "5m",
|
|
3644
|
+
* getSignal: async (symbol) => {
|
|
3645
|
+
* const messages = [];
|
|
3646
|
+
*
|
|
3647
|
+
* // Build multi-timeframe analysis conversation
|
|
3648
|
+
* const candles1h = await getCandles(symbol, "1h", 24);
|
|
3649
|
+
* messages.push(
|
|
3650
|
+
* { role: "user", content: `Analyze 1h trend:\n${formatCandles(candles1h)}` },
|
|
3651
|
+
* { role: "assistant", content: "Trend analyzed" }
|
|
3652
|
+
* );
|
|
3653
|
+
*
|
|
3654
|
+
* const candles5m = await getCandles(symbol, "5m", 24);
|
|
3655
|
+
* messages.push(
|
|
3656
|
+
* { role: "user", content: `Analyze 5m structure:\n${formatCandles(candles5m)}` },
|
|
3657
|
+
* { role: "assistant", content: "Structure analyzed" }
|
|
3658
|
+
* );
|
|
3659
|
+
*
|
|
3660
|
+
* // Request signal
|
|
3661
|
+
* messages.push({
|
|
3662
|
+
* role: "user",
|
|
3663
|
+
* content: "Generate trading signal. Use position: 'wait' if uncertain."
|
|
3664
|
+
* });
|
|
3665
|
+
*
|
|
3666
|
+
* const resultId = uuid();
|
|
3667
|
+
* const signal = await llmRequest(messages);
|
|
3668
|
+
*
|
|
3669
|
+
* // Save conversation and result for debugging
|
|
3670
|
+
* await dumpSignal(resultId, messages, signal);
|
|
3671
|
+
*
|
|
3672
|
+
* return signal;
|
|
3673
|
+
* }
|
|
3674
|
+
* });
|
|
3675
|
+
*
|
|
3676
|
+
* // Creates: ./dump/strategy/{uuid}/00_system_prompt.md
|
|
3677
|
+
* // ./dump/strategy/{uuid}/01_user_message.md (1h analysis)
|
|
3678
|
+
* // ./dump/strategy/{uuid}/02_assistant_message.md
|
|
3679
|
+
* // ./dump/strategy/{uuid}/03_user_message.md (5m analysis)
|
|
3680
|
+
* // ./dump/strategy/{uuid}/04_assistant_message.md
|
|
3681
|
+
* // ./dump/strategy/{uuid}/05_user_message.md (signal request)
|
|
3682
|
+
* // ./dump/strategy/{uuid}/06_llm_output.md (final signal)
|
|
3683
|
+
* ```
|
|
3684
|
+
*/
|
|
3685
|
+
declare function dumpSignal(signalId: string | number, history: MessageModel[], signal: ISignalDto, outputDir?: string): Promise<void>;
|
|
3686
|
+
|
|
3619
3687
|
/**
|
|
3620
3688
|
* Portfolio heatmap statistics for a single symbol.
|
|
3621
3689
|
* Aggregated metrics across all strategies for one trading pair.
|
|
@@ -4425,6 +4493,8 @@ interface PartialEvent {
|
|
|
4425
4493
|
action: "profit" | "loss";
|
|
4426
4494
|
/** Trading pair symbol */
|
|
4427
4495
|
symbol: string;
|
|
4496
|
+
/** Strategy name */
|
|
4497
|
+
strategyName: string;
|
|
4428
4498
|
/** Signal ID */
|
|
4429
4499
|
signalId: string;
|
|
4430
4500
|
/** Position type */
|
|
@@ -4443,7 +4513,7 @@ interface PartialEvent {
|
|
|
4443
4513
|
*
|
|
4444
4514
|
* @example
|
|
4445
4515
|
* ```typescript
|
|
4446
|
-
* const stats = await Partial.getData("my-strategy");
|
|
4516
|
+
* const stats = await Partial.getData("BTCUSDT", "my-strategy");
|
|
4447
4517
|
*
|
|
4448
4518
|
* console.log(`Total events: ${stats.totalEvents}`);
|
|
4449
4519
|
* console.log(`Profit events: ${stats.totalProfit}`);
|
|
@@ -4465,10 +4535,10 @@ interface PartialStatistics {
|
|
|
4465
4535
|
*
|
|
4466
4536
|
* Features:
|
|
4467
4537
|
* - Listens to partial profit and loss events via partialProfitSubject/partialLossSubject
|
|
4468
|
-
* - Accumulates all events (profit, loss) per symbol
|
|
4538
|
+
* - Accumulates all events (profit, loss) per symbol-strategy pair
|
|
4469
4539
|
* - Generates markdown tables with detailed event information
|
|
4470
4540
|
* - Provides statistics (total profit/loss events)
|
|
4471
|
-
* - Saves reports to disk in dump/partial/{symbol}.md
|
|
4541
|
+
* - Saves reports to disk in dump/partial/{symbol}_{strategyName}.md
|
|
4472
4542
|
*
|
|
4473
4543
|
* @example
|
|
4474
4544
|
* ```typescript
|
|
@@ -4478,15 +4548,15 @@ interface PartialStatistics {
|
|
|
4478
4548
|
* // No manual callback setup needed
|
|
4479
4549
|
*
|
|
4480
4550
|
* // Later: generate and save report
|
|
4481
|
-
* await service.dump("BTCUSDT");
|
|
4551
|
+
* await service.dump("BTCUSDT", "my-strategy");
|
|
4482
4552
|
* ```
|
|
4483
4553
|
*/
|
|
4484
4554
|
declare class PartialMarkdownService {
|
|
4485
4555
|
/** Logger service for debug output */
|
|
4486
4556
|
private readonly loggerService;
|
|
4487
4557
|
/**
|
|
4488
|
-
* Memoized function to get or create ReportStorage for a symbol.
|
|
4489
|
-
* Each symbol gets its own isolated storage instance.
|
|
4558
|
+
* Memoized function to get or create ReportStorage for a symbol-strategy pair.
|
|
4559
|
+
* Each symbol-strategy combination gets its own isolated storage instance.
|
|
4490
4560
|
*/
|
|
4491
4561
|
private getStorage;
|
|
4492
4562
|
/**
|
|
@@ -4516,74 +4586,80 @@ declare class PartialMarkdownService {
|
|
|
4516
4586
|
*/
|
|
4517
4587
|
private tickLoss;
|
|
4518
4588
|
/**
|
|
4519
|
-
* Gets statistical data from all partial profit/loss events for a symbol.
|
|
4589
|
+
* Gets statistical data from all partial profit/loss events for a symbol-strategy pair.
|
|
4520
4590
|
* Delegates to ReportStorage.getData().
|
|
4521
4591
|
*
|
|
4522
4592
|
* @param symbol - Trading pair symbol to get data for
|
|
4593
|
+
* @param strategyName - Strategy name to get data for
|
|
4523
4594
|
* @returns Statistical data object with all metrics
|
|
4524
4595
|
*
|
|
4525
4596
|
* @example
|
|
4526
4597
|
* ```typescript
|
|
4527
4598
|
* const service = new PartialMarkdownService();
|
|
4528
|
-
* const stats = await service.getData("BTCUSDT");
|
|
4599
|
+
* const stats = await service.getData("BTCUSDT", "my-strategy");
|
|
4529
4600
|
* console.log(stats.totalProfit, stats.totalLoss);
|
|
4530
4601
|
* ```
|
|
4531
4602
|
*/
|
|
4532
|
-
getData: (symbol: string) => Promise<PartialStatistics>;
|
|
4603
|
+
getData: (symbol: string, strategyName: string) => Promise<PartialStatistics>;
|
|
4533
4604
|
/**
|
|
4534
|
-
* Generates markdown report with all partial events for a symbol.
|
|
4605
|
+
* Generates markdown report with all partial events for a symbol-strategy pair.
|
|
4535
4606
|
* Delegates to ReportStorage.getReport().
|
|
4536
4607
|
*
|
|
4537
4608
|
* @param symbol - Trading pair symbol to generate report for
|
|
4609
|
+
* @param strategyName - Strategy name to generate report for
|
|
4538
4610
|
* @returns Markdown formatted report string with table of all events
|
|
4539
4611
|
*
|
|
4540
4612
|
* @example
|
|
4541
4613
|
* ```typescript
|
|
4542
4614
|
* const service = new PartialMarkdownService();
|
|
4543
|
-
* const markdown = await service.getReport("BTCUSDT");
|
|
4615
|
+
* const markdown = await service.getReport("BTCUSDT", "my-strategy");
|
|
4544
4616
|
* console.log(markdown);
|
|
4545
4617
|
* ```
|
|
4546
4618
|
*/
|
|
4547
|
-
getReport: (symbol: string) => Promise<string>;
|
|
4619
|
+
getReport: (symbol: string, strategyName: string) => Promise<string>;
|
|
4548
4620
|
/**
|
|
4549
|
-
* Saves symbol report to disk.
|
|
4621
|
+
* Saves symbol-strategy report to disk.
|
|
4550
4622
|
* Creates directory if it doesn't exist.
|
|
4551
4623
|
* Delegates to ReportStorage.dump().
|
|
4552
4624
|
*
|
|
4553
4625
|
* @param symbol - Trading pair symbol to save report for
|
|
4626
|
+
* @param strategyName - Strategy name to save report for
|
|
4554
4627
|
* @param path - Directory path to save report (default: "./dump/partial")
|
|
4555
4628
|
*
|
|
4556
4629
|
* @example
|
|
4557
4630
|
* ```typescript
|
|
4558
4631
|
* const service = new PartialMarkdownService();
|
|
4559
4632
|
*
|
|
4560
|
-
* // Save to default path: ./dump/partial/
|
|
4561
|
-
* await service.dump("BTCUSDT");
|
|
4633
|
+
* // Save to default path: ./dump/partial/BTCUSDT_my-strategy.md
|
|
4634
|
+
* await service.dump("BTCUSDT", "my-strategy");
|
|
4562
4635
|
*
|
|
4563
|
-
* // Save to custom path: ./custom/path/
|
|
4564
|
-
* await service.dump("BTCUSDT", "./custom/path");
|
|
4636
|
+
* // Save to custom path: ./custom/path/BTCUSDT_my-strategy.md
|
|
4637
|
+
* await service.dump("BTCUSDT", "my-strategy", "./custom/path");
|
|
4565
4638
|
* ```
|
|
4566
4639
|
*/
|
|
4567
|
-
dump: (symbol: string, path?: string) => Promise<void>;
|
|
4640
|
+
dump: (symbol: string, strategyName: string, path?: string) => Promise<void>;
|
|
4568
4641
|
/**
|
|
4569
4642
|
* Clears accumulated event data from storage.
|
|
4570
|
-
* If
|
|
4571
|
-
* If
|
|
4643
|
+
* If ctx is provided, clears only that specific symbol-strategy pair's data.
|
|
4644
|
+
* If nothing is provided, clears all data.
|
|
4572
4645
|
*
|
|
4573
|
-
* @param
|
|
4646
|
+
* @param ctx - Optional context with symbol and strategyName
|
|
4574
4647
|
*
|
|
4575
4648
|
* @example
|
|
4576
4649
|
* ```typescript
|
|
4577
4650
|
* const service = new PartialMarkdownService();
|
|
4578
4651
|
*
|
|
4579
|
-
* // Clear specific symbol
|
|
4580
|
-
* await service.clear("BTCUSDT");
|
|
4652
|
+
* // Clear specific symbol-strategy pair
|
|
4653
|
+
* await service.clear({ symbol: "BTCUSDT", strategyName: "my-strategy" });
|
|
4581
4654
|
*
|
|
4582
|
-
* // Clear all
|
|
4655
|
+
* // Clear all data
|
|
4583
4656
|
* await service.clear();
|
|
4584
4657
|
* ```
|
|
4585
4658
|
*/
|
|
4586
|
-
clear: (
|
|
4659
|
+
clear: (ctx?: {
|
|
4660
|
+
symbol: string;
|
|
4661
|
+
strategyName: string;
|
|
4662
|
+
}) => Promise<void>;
|
|
4587
4663
|
/**
|
|
4588
4664
|
* Initializes the service by subscribing to partial profit/loss events.
|
|
4589
4665
|
* Uses singleshot to ensure initialization happens only once.
|
|
@@ -5904,26 +5980,26 @@ declare const Optimizer: OptimizerUtils;
|
|
|
5904
5980
|
*
|
|
5905
5981
|
* Data source:
|
|
5906
5982
|
* - PartialMarkdownService listens to partialProfitSubject/partialLossSubject
|
|
5907
|
-
* - Accumulates events in ReportStorage (max 250 events per symbol)
|
|
5908
|
-
* - Events include: timestamp, action, symbol, signalId, position, level, price, mode
|
|
5983
|
+
* - Accumulates events in ReportStorage (max 250 events per symbol-strategy pair)
|
|
5984
|
+
* - Events include: timestamp, action, symbol, strategyName, signalId, position, level, price, mode
|
|
5909
5985
|
*
|
|
5910
5986
|
* @example
|
|
5911
5987
|
* ```typescript
|
|
5912
5988
|
* import { Partial } from "./classes/Partial";
|
|
5913
5989
|
*
|
|
5914
|
-
* // Get statistical data for BTCUSDT
|
|
5915
|
-
* const stats = await Partial.getData("BTCUSDT");
|
|
5990
|
+
* // Get statistical data for BTCUSDT:my-strategy
|
|
5991
|
+
* const stats = await Partial.getData("BTCUSDT", "my-strategy");
|
|
5916
5992
|
* console.log(`Total events: ${stats.totalEvents}`);
|
|
5917
5993
|
* console.log(`Profit events: ${stats.totalProfit}`);
|
|
5918
5994
|
* console.log(`Loss events: ${stats.totalLoss}`);
|
|
5919
5995
|
*
|
|
5920
5996
|
* // Generate markdown report
|
|
5921
|
-
* const markdown = await Partial.getReport("BTCUSDT");
|
|
5997
|
+
* const markdown = await Partial.getReport("BTCUSDT", "my-strategy");
|
|
5922
5998
|
* console.log(markdown); // Formatted table with all events
|
|
5923
5999
|
*
|
|
5924
6000
|
* // Export report to file
|
|
5925
|
-
* await Partial.dump("BTCUSDT"); // Saves to ./dump/partial/
|
|
5926
|
-
* await Partial.dump("BTCUSDT", "./custom/path"); // Custom directory
|
|
6001
|
+
* await Partial.dump("BTCUSDT", "my-strategy"); // Saves to ./dump/partial/BTCUSDT_my-strategy.md
|
|
6002
|
+
* await Partial.dump("BTCUSDT", "my-strategy", "./custom/path"); // Custom directory
|
|
5927
6003
|
* ```
|
|
5928
6004
|
*/
|
|
5929
6005
|
declare class PartialUtils {
|
|
@@ -5934,11 +6010,12 @@ declare class PartialUtils {
|
|
|
5934
6010
|
* Returns aggregated metrics calculated from all profit and loss events.
|
|
5935
6011
|
*
|
|
5936
6012
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
6013
|
+
* @param strategyName - Strategy name (e.g., "my-strategy")
|
|
5937
6014
|
* @returns Promise resolving to PartialStatistics object with counts and event list
|
|
5938
6015
|
*
|
|
5939
6016
|
* @example
|
|
5940
6017
|
* ```typescript
|
|
5941
|
-
* const stats = await Partial.getData("BTCUSDT");
|
|
6018
|
+
* const stats = await Partial.getData("BTCUSDT", "my-strategy");
|
|
5942
6019
|
*
|
|
5943
6020
|
* console.log(`Total events: ${stats.totalEvents}`);
|
|
5944
6021
|
* console.log(`Profit events: ${stats.totalProfit} (${(stats.totalProfit / stats.totalEvents * 100).toFixed(1)}%)`);
|
|
@@ -5950,13 +6027,14 @@ declare class PartialUtils {
|
|
|
5950
6027
|
* }
|
|
5951
6028
|
* ```
|
|
5952
6029
|
*/
|
|
5953
|
-
getData: (symbol: string) => Promise<PartialStatistics>;
|
|
6030
|
+
getData: (symbol: string, strategyName: string) => Promise<PartialStatistics>;
|
|
5954
6031
|
/**
|
|
5955
|
-
* Generates markdown report with all partial profit/loss events for a symbol.
|
|
6032
|
+
* Generates markdown report with all partial profit/loss events for a symbol-strategy pair.
|
|
5956
6033
|
*
|
|
5957
6034
|
* Creates formatted table containing:
|
|
5958
6035
|
* - Action (PROFIT/LOSS)
|
|
5959
6036
|
* - Symbol
|
|
6037
|
+
* - Strategy
|
|
5960
6038
|
* - Signal ID
|
|
5961
6039
|
* - Position (LONG/SHORT)
|
|
5962
6040
|
* - Level % (+10%, -20%, etc)
|
|
@@ -5967,32 +6045,33 @@ declare class PartialUtils {
|
|
|
5967
6045
|
* Also includes summary statistics at the end.
|
|
5968
6046
|
*
|
|
5969
6047
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
6048
|
+
* @param strategyName - Strategy name (e.g., "my-strategy")
|
|
5970
6049
|
* @returns Promise resolving to markdown formatted report string
|
|
5971
6050
|
*
|
|
5972
6051
|
* @example
|
|
5973
6052
|
* ```typescript
|
|
5974
|
-
* const markdown = await Partial.getReport("BTCUSDT");
|
|
6053
|
+
* const markdown = await Partial.getReport("BTCUSDT", "my-strategy");
|
|
5975
6054
|
* console.log(markdown);
|
|
5976
6055
|
*
|
|
5977
6056
|
* // Output:
|
|
5978
|
-
* // # Partial Profit/Loss Report: BTCUSDT
|
|
6057
|
+
* // # Partial Profit/Loss Report: BTCUSDT:my-strategy
|
|
5979
6058
|
* //
|
|
5980
|
-
* // | Action | Symbol | Signal ID | Position | Level % | Current Price | Timestamp | Mode |
|
|
5981
|
-
* // | --- | --- | --- | --- | --- | --- | --- | --- |
|
|
5982
|
-
* // | PROFIT | BTCUSDT | abc123 | LONG | +10% | 51500.00000000 USD | 2024-01-15T10:30:00.000Z | Backtest |
|
|
5983
|
-
* // | LOSS | BTCUSDT | abc123 | LONG | -10% | 49000.00000000 USD | 2024-01-15T11:00:00.000Z | Backtest |
|
|
6059
|
+
* // | Action | Symbol | Strategy | Signal ID | Position | Level % | Current Price | Timestamp | Mode |
|
|
6060
|
+
* // | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
|
6061
|
+
* // | PROFIT | BTCUSDT | my-strategy | abc123 | LONG | +10% | 51500.00000000 USD | 2024-01-15T10:30:00.000Z | Backtest |
|
|
6062
|
+
* // | LOSS | BTCUSDT | my-strategy | abc123 | LONG | -10% | 49000.00000000 USD | 2024-01-15T11:00:00.000Z | Backtest |
|
|
5984
6063
|
* //
|
|
5985
6064
|
* // **Total events:** 2
|
|
5986
6065
|
* // **Profit events:** 1
|
|
5987
6066
|
* // **Loss events:** 1
|
|
5988
6067
|
* ```
|
|
5989
6068
|
*/
|
|
5990
|
-
getReport: (symbol: string) => Promise<string>;
|
|
6069
|
+
getReport: (symbol: string, strategyName: string) => Promise<string>;
|
|
5991
6070
|
/**
|
|
5992
6071
|
* Generates and saves markdown report to file.
|
|
5993
6072
|
*
|
|
5994
6073
|
* Creates directory if it doesn't exist.
|
|
5995
|
-
* Filename format: {symbol}.md (e.g., "
|
|
6074
|
+
* Filename format: {symbol}_{strategyName}.md (e.g., "BTCUSDT_my-strategy.md")
|
|
5996
6075
|
*
|
|
5997
6076
|
* Delegates to PartialMarkdownService.dump() which:
|
|
5998
6077
|
* 1. Generates markdown report via getReport()
|
|
@@ -6001,24 +6080,25 @@ declare class PartialUtils {
|
|
|
6001
6080
|
* 4. Logs success/failure to console
|
|
6002
6081
|
*
|
|
6003
6082
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
6083
|
+
* @param strategyName - Strategy name (e.g., "my-strategy")
|
|
6004
6084
|
* @param path - Output directory path (default: "./dump/partial")
|
|
6005
6085
|
* @returns Promise that resolves when file is written
|
|
6006
6086
|
*
|
|
6007
6087
|
* @example
|
|
6008
6088
|
* ```typescript
|
|
6009
|
-
* // Save to default path: ./dump/partial/
|
|
6010
|
-
* await Partial.dump("BTCUSDT");
|
|
6089
|
+
* // Save to default path: ./dump/partial/BTCUSDT_my-strategy.md
|
|
6090
|
+
* await Partial.dump("BTCUSDT", "my-strategy");
|
|
6011
6091
|
*
|
|
6012
|
-
* // Save to custom path: ./reports/partial/
|
|
6013
|
-
* await Partial.dump("BTCUSDT", "./reports/partial");
|
|
6092
|
+
* // Save to custom path: ./reports/partial/BTCUSDT_my-strategy.md
|
|
6093
|
+
* await Partial.dump("BTCUSDT", "my-strategy", "./reports/partial");
|
|
6014
6094
|
*
|
|
6015
6095
|
* // After multiple symbols backtested, export all reports
|
|
6016
6096
|
* for (const symbol of ["BTCUSDT", "ETHUSDT", "BNBUSDT"]) {
|
|
6017
|
-
* await Partial.dump(symbol, "./backtest-results");
|
|
6097
|
+
* await Partial.dump(symbol, "my-strategy", "./backtest-results");
|
|
6018
6098
|
* }
|
|
6019
6099
|
* ```
|
|
6020
6100
|
*/
|
|
6021
|
-
dump: (symbol: string, path?: string) => Promise<void>;
|
|
6101
|
+
dump: (symbol: string, strategyName: string, path?: string) => Promise<void>;
|
|
6022
6102
|
}
|
|
6023
6103
|
/**
|
|
6024
6104
|
* Global singleton instance of PartialUtils.
|
|
@@ -6029,9 +6109,9 @@ declare class PartialUtils {
|
|
|
6029
6109
|
* import { Partial } from "backtest-kit";
|
|
6030
6110
|
*
|
|
6031
6111
|
* // Usage same as PartialUtils methods
|
|
6032
|
-
* const stats = await Partial.getData("BTCUSDT");
|
|
6033
|
-
* const report = await Partial.getReport("BTCUSDT");
|
|
6034
|
-
* await Partial.dump("BTCUSDT");
|
|
6112
|
+
* const stats = await Partial.getData("BTCUSDT", "my-strategy");
|
|
6113
|
+
* const report = await Partial.getReport("BTCUSDT", "my-strategy");
|
|
6114
|
+
* await Partial.dump("BTCUSDT", "my-strategy");
|
|
6035
6115
|
* ```
|
|
6036
6116
|
*/
|
|
6037
6117
|
declare const Partial$1: PartialUtils;
|
|
@@ -8661,6 +8741,54 @@ declare class PartialGlobalService {
|
|
|
8661
8741
|
clear: (symbol: string, data: ISignalRow, priceClose: number) => Promise<void>;
|
|
8662
8742
|
}
|
|
8663
8743
|
|
|
8744
|
+
/**
|
|
8745
|
+
* Unique identifier for outline result.
|
|
8746
|
+
* Can be string or number for flexible ID formats.
|
|
8747
|
+
*/
|
|
8748
|
+
type ResultId = string | number;
|
|
8749
|
+
/**
|
|
8750
|
+
* Service for generating markdown documentation from LLM outline results.
|
|
8751
|
+
* Used by AI Strategy Optimizer to save debug logs and conversation history.
|
|
8752
|
+
*
|
|
8753
|
+
* Creates directory structure:
|
|
8754
|
+
* - ./dump/strategy/{signalId}/00_system_prompt.md - System messages and output data
|
|
8755
|
+
* - ./dump/strategy/{signalId}/01_user_message.md - First user input
|
|
8756
|
+
* - ./dump/strategy/{signalId}/02_user_message.md - Second user input
|
|
8757
|
+
* - ./dump/strategy/{signalId}/XX_llm_output.md - Final LLM output
|
|
8758
|
+
*/
|
|
8759
|
+
declare class OutlineMarkdownService {
|
|
8760
|
+
/** Logger service injected via DI */
|
|
8761
|
+
private readonly loggerService;
|
|
8762
|
+
/**
|
|
8763
|
+
* Dumps signal data and conversation history to markdown files.
|
|
8764
|
+
* Skips if directory already exists to avoid overwriting previous results.
|
|
8765
|
+
*
|
|
8766
|
+
* Generated files:
|
|
8767
|
+
* - 00_system_prompt.md - System messages and output summary
|
|
8768
|
+
* - XX_user_message.md - Each user message in separate file (numbered)
|
|
8769
|
+
* - XX_llm_output.md - Final LLM output with signal data
|
|
8770
|
+
*
|
|
8771
|
+
* @param signalId - Unique identifier for the result (used as directory name)
|
|
8772
|
+
* @param history - Array of message models from LLM conversation
|
|
8773
|
+
* @param signal - Signal DTO with trade parameters (priceOpen, TP, SL, etc.)
|
|
8774
|
+
* @param outputDir - Output directory path (default: "./dump/strategy")
|
|
8775
|
+
* @returns Promise that resolves when all files are written
|
|
8776
|
+
*
|
|
8777
|
+
* @example
|
|
8778
|
+
* ```typescript
|
|
8779
|
+
* await outlineService.dumpSignal(
|
|
8780
|
+
* "strategy-1",
|
|
8781
|
+
* conversationHistory,
|
|
8782
|
+
* { position: "long", priceTakeProfit: 51000, priceStopLoss: 49000, minuteEstimatedTime: 60 }
|
|
8783
|
+
* );
|
|
8784
|
+
* // Creates: ./dump/strategy/strategy-1/00_system_prompt.md
|
|
8785
|
+
* // ./dump/strategy/strategy-1/01_user_message.md
|
|
8786
|
+
* // ./dump/strategy/strategy-1/02_llm_output.md
|
|
8787
|
+
* ```
|
|
8788
|
+
*/
|
|
8789
|
+
dumpSignal: (signalId: ResultId, history: MessageModel[], signal: ISignalDto, outputDir?: string) => Promise<void>;
|
|
8790
|
+
}
|
|
8791
|
+
|
|
8664
8792
|
declare const backtest: {
|
|
8665
8793
|
optimizerTemplateService: OptimizerTemplateService;
|
|
8666
8794
|
exchangeValidationService: ExchangeValidationService;
|
|
@@ -8677,6 +8805,7 @@ declare const backtest: {
|
|
|
8677
8805
|
walkerMarkdownService: WalkerMarkdownService;
|
|
8678
8806
|
heatMarkdownService: HeatMarkdownService;
|
|
8679
8807
|
partialMarkdownService: PartialMarkdownService;
|
|
8808
|
+
outlineMarkdownService: OutlineMarkdownService;
|
|
8680
8809
|
backtestLogicPublicService: BacktestLogicPublicService;
|
|
8681
8810
|
liveLogicPublicService: LiveLogicPublicService;
|
|
8682
8811
|
walkerLogicPublicService: WalkerLogicPublicService;
|
|
@@ -8716,4 +8845,4 @@ declare const backtest: {
|
|
|
8716
8845
|
loggerService: LoggerService;
|
|
8717
8846
|
};
|
|
8718
8847
|
|
|
8719
|
-
export { Backtest, type BacktestStatistics, type CandleInterval, Constant, type DoneContract, type EntityId, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IHeatmapStatistics, type IOptimizerCallbacks, type IOptimizerData, type IOptimizerFetchArgs, type IOptimizerFilterArgs, type IOptimizerRange, type IOptimizerSchema, type IOptimizerSource, type IOptimizerStrategy, type IOptimizerTemplate, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, 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 IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, Live, type LiveStatistics, type MessageModel, type MessageRole, MethodContextService, Optimizer, Partial$1 as Partial, type PartialData, type PartialLossContract, type PartialProfitContract, type PartialStatistics, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatistics, PersistBase, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, PositionSize, type ProgressBacktestContract, type ProgressOptimizerContract, type ProgressWalkerContract, type RiskData, Schedule, type ScheduleData, type ScheduleStatistics, type SignalData, type SignalInterval, type TPersistBase, type TPersistBaseCtor, Walker, type WalkerContract, type WalkerMetric, type WalkerStatistics, addExchange, addFrame, addOptimizer, addRisk, addSizing, addStrategy, addWalker, emitters, formatPrice, formatQuantity, getAveragePrice, getCandles, getDate, getMode, backtest as lib, listExchanges, listFrames, listOptimizers, listRisks, listSizings, listStrategies, listWalkers, listenBacktestProgress, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenOptimizerProgress, listenPartialLoss, listenPartialLossOnce, listenPartialProfit, listenPartialProfitOnce, listenPerformance, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, setConfig, setLogger };
|
|
8848
|
+
export { Backtest, type BacktestStatistics, type CandleInterval, Constant, type DoneContract, type EntityId, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IHeatmapStatistics, type IOptimizerCallbacks, type IOptimizerData, type IOptimizerFetchArgs, type IOptimizerFilterArgs, type IOptimizerRange, type IOptimizerSchema, type IOptimizerSource, type IOptimizerStrategy, type IOptimizerTemplate, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, 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 IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, Live, type LiveStatistics, type MessageModel, type MessageRole, MethodContextService, Optimizer, Partial$1 as Partial, type PartialData, type PartialLossContract, type PartialProfitContract, type PartialStatistics, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatistics, PersistBase, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, PositionSize, type ProgressBacktestContract, type ProgressOptimizerContract, type ProgressWalkerContract, type RiskData, Schedule, type ScheduleData, type ScheduleStatistics, type SignalData, type SignalInterval, type TPersistBase, type TPersistBaseCtor, Walker, type WalkerContract, type WalkerMetric, type WalkerStatistics, addExchange, addFrame, addOptimizer, addRisk, addSizing, addStrategy, addWalker, dumpSignal, emitters, formatPrice, formatQuantity, getAveragePrice, getCandles, getDate, getMode, backtest as lib, listExchanges, listFrames, listOptimizers, listRisks, listSizings, listStrategies, listWalkers, listenBacktestProgress, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenOptimizerProgress, listenPartialLoss, listenPartialLossOnce, listenPartialProfit, listenPartialProfitOnce, listenPerformance, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, setConfig, setLogger };
|