backtest-kit 1.6.6 → 1.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.cjs +124 -524
- package/build/index.mjs +124 -524
- package/package.json +1 -1
- package/types.d.ts +15 -2
package/build/index.cjs
CHANGED
|
@@ -16373,6 +16373,8 @@ const BACKTEST_METHOD_NAME_TASK = "BacktestUtils.task";
|
|
|
16373
16373
|
const BACKTEST_METHOD_NAME_GET_STATUS = "BacktestUtils.getStatus";
|
|
16374
16374
|
const BACKTEST_METHOD_NAME_GET_PENDING_SIGNAL = "BacktestUtils.getPendingSignal";
|
|
16375
16375
|
const BACKTEST_METHOD_NAME_GET_SCHEDULED_SIGNAL = "BacktestUtils.getScheduledSignal";
|
|
16376
|
+
const BACKTEST_METHOD_NAME_CANCEL = "BacktestUtils.cancel";
|
|
16377
|
+
const BACKTEST_METHOD_NAME_GET_DATA = "BacktestUtils.getData";
|
|
16376
16378
|
/**
|
|
16377
16379
|
* Internal task function that runs backtest and handles completion.
|
|
16378
16380
|
* Consumes backtest results and updates instance state flags.
|
|
@@ -16430,9 +16432,11 @@ class BacktestInstance {
|
|
|
16430
16432
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
16431
16433
|
* @param strategyName - Strategy name for this backtest instance
|
|
16432
16434
|
*/
|
|
16433
|
-
constructor(symbol, strategyName) {
|
|
16435
|
+
constructor(symbol, strategyName, exchangeName, frameName) {
|
|
16434
16436
|
this.symbol = symbol;
|
|
16435
16437
|
this.strategyName = strategyName;
|
|
16438
|
+
this.exchangeName = exchangeName;
|
|
16439
|
+
this.frameName = frameName;
|
|
16436
16440
|
/** A randomly generated string. */
|
|
16437
16441
|
this.id = functoolsKit.randomString();
|
|
16438
16442
|
/** Internal flag indicating if backtest was stopped manually */
|
|
@@ -16474,6 +16478,8 @@ class BacktestInstance {
|
|
|
16474
16478
|
id: this.id,
|
|
16475
16479
|
symbol: this.symbol,
|
|
16476
16480
|
strategyName: this.strategyName,
|
|
16481
|
+
exchangeName: this.exchangeName,
|
|
16482
|
+
frameName: this.frameName,
|
|
16477
16483
|
status: this.task.getStatus(),
|
|
16478
16484
|
};
|
|
16479
16485
|
};
|
|
@@ -16490,20 +16496,42 @@ class BacktestInstance {
|
|
|
16490
16496
|
context,
|
|
16491
16497
|
});
|
|
16492
16498
|
{
|
|
16493
|
-
backtest$1.backtestMarkdownService.clear(true, {
|
|
16494
|
-
|
|
16495
|
-
|
|
16496
|
-
|
|
16497
|
-
backtest$1.
|
|
16498
|
-
|
|
16499
|
+
backtest$1.backtestMarkdownService.clear(true, {
|
|
16500
|
+
symbol,
|
|
16501
|
+
strategyName: context.strategyName,
|
|
16502
|
+
});
|
|
16503
|
+
backtest$1.liveMarkdownService.clear(true, {
|
|
16504
|
+
symbol,
|
|
16505
|
+
strategyName: context.strategyName,
|
|
16506
|
+
});
|
|
16507
|
+
backtest$1.scheduleMarkdownService.clear(true, {
|
|
16508
|
+
symbol,
|
|
16509
|
+
strategyName: context.strategyName,
|
|
16510
|
+
});
|
|
16511
|
+
backtest$1.performanceMarkdownService.clear(true, {
|
|
16512
|
+
symbol,
|
|
16513
|
+
strategyName: context.strategyName,
|
|
16514
|
+
});
|
|
16515
|
+
backtest$1.partialMarkdownService.clear(true, {
|
|
16516
|
+
symbol,
|
|
16517
|
+
strategyName: context.strategyName,
|
|
16518
|
+
});
|
|
16519
|
+
backtest$1.riskMarkdownService.clear(true, {
|
|
16520
|
+
symbol,
|
|
16521
|
+
strategyName: context.strategyName,
|
|
16522
|
+
});
|
|
16499
16523
|
}
|
|
16500
16524
|
{
|
|
16501
|
-
backtest$1.strategyCoreService.clear(true, {
|
|
16525
|
+
backtest$1.strategyCoreService.clear(true, {
|
|
16526
|
+
symbol,
|
|
16527
|
+
strategyName: context.strategyName,
|
|
16528
|
+
});
|
|
16502
16529
|
}
|
|
16503
16530
|
{
|
|
16504
16531
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(context.strategyName);
|
|
16505
16532
|
riskName && backtest$1.riskGlobalService.clear(true, { riskName });
|
|
16506
|
-
riskList &&
|
|
16533
|
+
riskList &&
|
|
16534
|
+
riskList.forEach((riskName) => backtest$1.riskGlobalService.clear(true, { riskName }));
|
|
16507
16535
|
}
|
|
16508
16536
|
return backtest$1.backtestCommandService.run(symbol, context);
|
|
16509
16537
|
};
|
|
@@ -16543,7 +16571,10 @@ class BacktestInstance {
|
|
|
16543
16571
|
}
|
|
16544
16572
|
this.task(symbol, context).catch((error) => exitEmitter.next(new Error(functoolsKit.getErrorMessage(error))));
|
|
16545
16573
|
return () => {
|
|
16546
|
-
backtest$1.strategyCoreService.stop(true, {
|
|
16574
|
+
backtest$1.strategyCoreService.stop(true, {
|
|
16575
|
+
symbol,
|
|
16576
|
+
strategyName: context.strategyName,
|
|
16577
|
+
});
|
|
16547
16578
|
backtest$1.strategyCoreService
|
|
16548
16579
|
.getPendingSignal(true, symbol, context.strategyName)
|
|
16549
16580
|
.then(async (pendingSignal) => {
|
|
@@ -16563,173 +16594,6 @@ class BacktestInstance {
|
|
|
16563
16594
|
this._isStopped = true;
|
|
16564
16595
|
};
|
|
16565
16596
|
};
|
|
16566
|
-
/**
|
|
16567
|
-
* Retrieves the currently active pending signal for the strategy.
|
|
16568
|
-
* If no active signal exists, returns null.
|
|
16569
|
-
*
|
|
16570
|
-
* @param symbol - Trading pair symbol
|
|
16571
|
-
* @param strategyName - Name of strategy to get pending signal for
|
|
16572
|
-
* @returns Promise resolving to pending signal or null
|
|
16573
|
-
*
|
|
16574
|
-
* @example
|
|
16575
|
-
* ```typescript
|
|
16576
|
-
* const instance = new BacktestInstance();
|
|
16577
|
-
* const pending = await instance.getPendingSignal("BTCUSDT", "my-strategy");
|
|
16578
|
-
* if (pending) {
|
|
16579
|
-
* console.log("Active signal:", pending.id);
|
|
16580
|
-
* }
|
|
16581
|
-
* ```
|
|
16582
|
-
*/
|
|
16583
|
-
this.getPendingSignal = async (symbol, strategyName) => {
|
|
16584
|
-
backtest$1.loggerService.info(BACKTEST_METHOD_NAME_GET_PENDING_SIGNAL, {
|
|
16585
|
-
symbol,
|
|
16586
|
-
strategyName,
|
|
16587
|
-
});
|
|
16588
|
-
return await backtest$1.strategyCoreService.getPendingSignal(true, symbol, strategyName);
|
|
16589
|
-
};
|
|
16590
|
-
/**
|
|
16591
|
-
* Retrieves the currently active scheduled signal for the strategy.
|
|
16592
|
-
* If no scheduled signal exists, returns null.
|
|
16593
|
-
*
|
|
16594
|
-
* @param symbol - Trading pair symbol
|
|
16595
|
-
* @param strategyName - Name of strategy to get scheduled signal for
|
|
16596
|
-
* @returns Promise resolving to scheduled signal or null
|
|
16597
|
-
*
|
|
16598
|
-
* @example
|
|
16599
|
-
* ```typescript
|
|
16600
|
-
* const instance = new BacktestInstance();
|
|
16601
|
-
* const scheduled = await instance.getScheduledSignal("BTCUSDT", "my-strategy");
|
|
16602
|
-
* if (scheduled) {
|
|
16603
|
-
* console.log("Scheduled signal:", scheduled.id);
|
|
16604
|
-
* }
|
|
16605
|
-
* ```
|
|
16606
|
-
*/
|
|
16607
|
-
this.getScheduledSignal = async (symbol, strategyName) => {
|
|
16608
|
-
backtest$1.loggerService.info(BACKTEST_METHOD_NAME_GET_SCHEDULED_SIGNAL, {
|
|
16609
|
-
symbol,
|
|
16610
|
-
strategyName,
|
|
16611
|
-
});
|
|
16612
|
-
return await backtest$1.strategyCoreService.getScheduledSignal(true, symbol, strategyName);
|
|
16613
|
-
};
|
|
16614
|
-
/**
|
|
16615
|
-
* Stops the strategy from generating new signals.
|
|
16616
|
-
*
|
|
16617
|
-
* Sets internal flag to prevent strategy from opening new signals.
|
|
16618
|
-
* Current active signal (if any) will complete normally.
|
|
16619
|
-
* Backtest will stop at the next safe point (idle state or after signal closes).
|
|
16620
|
-
*
|
|
16621
|
-
* @param symbol - Trading pair symbol
|
|
16622
|
-
* @param strategyName - Strategy name to stop
|
|
16623
|
-
* @returns Promise that resolves when stop flag is set
|
|
16624
|
-
*
|
|
16625
|
-
* @example
|
|
16626
|
-
* ```typescript
|
|
16627
|
-
* const instance = new BacktestInstance();
|
|
16628
|
-
* await instance.stop("BTCUSDT", "my-strategy");
|
|
16629
|
-
* ```
|
|
16630
|
-
*/
|
|
16631
|
-
this.stop = async (symbol, strategyName) => {
|
|
16632
|
-
backtest$1.loggerService.info(BACKTEST_METHOD_NAME_STOP, {
|
|
16633
|
-
symbol,
|
|
16634
|
-
strategyName,
|
|
16635
|
-
});
|
|
16636
|
-
await backtest$1.strategyCoreService.stop(true, { symbol, strategyName });
|
|
16637
|
-
};
|
|
16638
|
-
/**
|
|
16639
|
-
* Cancels the scheduled signal without stopping the strategy.
|
|
16640
|
-
*
|
|
16641
|
-
* Clears the scheduled signal (waiting for priceOpen activation).
|
|
16642
|
-
* Does NOT affect active pending signals or strategy operation.
|
|
16643
|
-
* Does NOT set stop flag - strategy can continue generating new signals.
|
|
16644
|
-
*
|
|
16645
|
-
* @param symbol - Trading pair symbol
|
|
16646
|
-
* @param strategyName - Strategy name
|
|
16647
|
-
* @param cancelId - Optional cancellation ID for tracking user-initiated cancellations
|
|
16648
|
-
* @returns Promise that resolves when scheduled signal is cancelled
|
|
16649
|
-
*
|
|
16650
|
-
* @example
|
|
16651
|
-
* ```typescript
|
|
16652
|
-
* const instance = new BacktestInstance();
|
|
16653
|
-
* await instance.cancel("BTCUSDT", "my-strategy", "manual-cancel-001");
|
|
16654
|
-
* ```
|
|
16655
|
-
*/
|
|
16656
|
-
this.cancel = async (symbol, strategyName, cancelId) => {
|
|
16657
|
-
backtest$1.loggerService.info("BacktestInstance.cancel", {
|
|
16658
|
-
symbol,
|
|
16659
|
-
strategyName,
|
|
16660
|
-
cancelId,
|
|
16661
|
-
});
|
|
16662
|
-
await backtest$1.strategyCoreService.cancel(true, { symbol, strategyName }, cancelId);
|
|
16663
|
-
};
|
|
16664
|
-
/**
|
|
16665
|
-
* Gets statistical data from all closed signals for a symbol-strategy pair.
|
|
16666
|
-
*
|
|
16667
|
-
* @param symbol - Trading pair symbol
|
|
16668
|
-
* @param strategyName - Strategy name to get data for
|
|
16669
|
-
* @returns Promise resolving to statistical data object
|
|
16670
|
-
*
|
|
16671
|
-
* @example
|
|
16672
|
-
* ```typescript
|
|
16673
|
-
* const instance = new BacktestInstance();
|
|
16674
|
-
* const stats = await instance.getData("BTCUSDT", "my-strategy");
|
|
16675
|
-
* console.log(stats.sharpeRatio, stats.winRate);
|
|
16676
|
-
* ```
|
|
16677
|
-
*/
|
|
16678
|
-
this.getData = async (symbol, strategyName) => {
|
|
16679
|
-
backtest$1.loggerService.info("BacktestUtils.getData", {
|
|
16680
|
-
symbol,
|
|
16681
|
-
strategyName,
|
|
16682
|
-
});
|
|
16683
|
-
return await backtest$1.backtestMarkdownService.getData(symbol, strategyName, true);
|
|
16684
|
-
};
|
|
16685
|
-
/**
|
|
16686
|
-
* Generates markdown report with all closed signals for a symbol-strategy pair.
|
|
16687
|
-
*
|
|
16688
|
-
* @param symbol - Trading pair symbol
|
|
16689
|
-
* @param strategyName - Strategy name to generate report for
|
|
16690
|
-
* @param columns - Optional columns configuration for the report
|
|
16691
|
-
* @returns Promise resolving to markdown formatted report string
|
|
16692
|
-
*
|
|
16693
|
-
* @example
|
|
16694
|
-
* ```typescript
|
|
16695
|
-
* const instance = new BacktestInstance();
|
|
16696
|
-
* const markdown = await instance.getReport("BTCUSDT", "my-strategy");
|
|
16697
|
-
* console.log(markdown);
|
|
16698
|
-
* ```
|
|
16699
|
-
*/
|
|
16700
|
-
this.getReport = async (symbol, strategyName, columns) => {
|
|
16701
|
-
backtest$1.loggerService.info(BACKTEST_METHOD_NAME_GET_REPORT, {
|
|
16702
|
-
symbol,
|
|
16703
|
-
strategyName,
|
|
16704
|
-
});
|
|
16705
|
-
return await backtest$1.backtestMarkdownService.getReport(symbol, strategyName, true, columns);
|
|
16706
|
-
};
|
|
16707
|
-
/**
|
|
16708
|
-
* Saves strategy report to disk.
|
|
16709
|
-
*
|
|
16710
|
-
* @param symbol - Trading pair symbol
|
|
16711
|
-
* @param strategyName - Strategy name to save report for
|
|
16712
|
-
* @param path - Optional directory path to save report (default: "./dump/backtest")
|
|
16713
|
-
* @param columns - Optional columns configuration for the report
|
|
16714
|
-
*
|
|
16715
|
-
* @example
|
|
16716
|
-
* ```typescript
|
|
16717
|
-
* const instance = new BacktestInstance();
|
|
16718
|
-
* // Save to default path: ./dump/backtest/my-strategy.md
|
|
16719
|
-
* await instance.dump("BTCUSDT", "my-strategy");
|
|
16720
|
-
*
|
|
16721
|
-
* // Save to custom path: ./custom/path/my-strategy.md
|
|
16722
|
-
* await instance.dump("BTCUSDT", "my-strategy", "./custom/path");
|
|
16723
|
-
* ```
|
|
16724
|
-
*/
|
|
16725
|
-
this.dump = async (symbol, strategyName, path, columns) => {
|
|
16726
|
-
backtest$1.loggerService.info(BACKTEST_METHOD_NAME_DUMP, {
|
|
16727
|
-
symbol,
|
|
16728
|
-
strategyName,
|
|
16729
|
-
path,
|
|
16730
|
-
});
|
|
16731
|
-
await backtest$1.backtestMarkdownService.dump(symbol, strategyName, true, path, columns);
|
|
16732
|
-
};
|
|
16733
16597
|
}
|
|
16734
16598
|
}
|
|
16735
16599
|
/**
|
|
@@ -16757,7 +16621,7 @@ class BacktestUtils {
|
|
|
16757
16621
|
* Memoized function to get or create BacktestInstance for a symbol-strategy pair.
|
|
16758
16622
|
* Each symbol-strategy combination gets its own isolated instance.
|
|
16759
16623
|
*/
|
|
16760
|
-
this._getInstance = functoolsKit.memoize(([symbol, strategyName]) => `${symbol}:${strategyName}`, (symbol, strategyName) => new BacktestInstance(symbol, strategyName));
|
|
16624
|
+
this._getInstance = functoolsKit.memoize(([symbol, strategyName]) => `${symbol}:${strategyName}`, (symbol, strategyName, exchangeName, frameName) => new BacktestInstance(symbol, strategyName, exchangeName, frameName));
|
|
16761
16625
|
/**
|
|
16762
16626
|
* Runs backtest for a symbol with context propagation.
|
|
16763
16627
|
*
|
|
@@ -16773,10 +16637,12 @@ class BacktestUtils {
|
|
|
16773
16637
|
}
|
|
16774
16638
|
{
|
|
16775
16639
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(context.strategyName);
|
|
16776
|
-
riskName &&
|
|
16777
|
-
|
|
16640
|
+
riskName &&
|
|
16641
|
+
backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_RUN);
|
|
16642
|
+
riskList &&
|
|
16643
|
+
riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_RUN));
|
|
16778
16644
|
}
|
|
16779
|
-
const instance = this._getInstance(symbol, context.strategyName);
|
|
16645
|
+
const instance = this._getInstance(symbol, context.strategyName, context.exchangeName, context.frameName);
|
|
16780
16646
|
return instance.run(symbol, context);
|
|
16781
16647
|
};
|
|
16782
16648
|
/**
|
|
@@ -16806,10 +16672,12 @@ class BacktestUtils {
|
|
|
16806
16672
|
backtest$1.frameValidationService.validate(context.frameName, BACKTEST_METHOD_NAME_BACKGROUND);
|
|
16807
16673
|
{
|
|
16808
16674
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(context.strategyName);
|
|
16809
|
-
riskName &&
|
|
16810
|
-
|
|
16675
|
+
riskName &&
|
|
16676
|
+
backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_BACKGROUND);
|
|
16677
|
+
riskList &&
|
|
16678
|
+
riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_BACKGROUND));
|
|
16811
16679
|
}
|
|
16812
|
-
const instance = this._getInstance(symbol, context.strategyName);
|
|
16680
|
+
const instance = this._getInstance(symbol, context.strategyName, context.exchangeName, context.frameName);
|
|
16813
16681
|
return instance.background(symbol, context);
|
|
16814
16682
|
};
|
|
16815
16683
|
/**
|
|
@@ -16832,11 +16700,12 @@ class BacktestUtils {
|
|
|
16832
16700
|
backtest$1.strategyValidationService.validate(strategyName, BACKTEST_METHOD_NAME_GET_PENDING_SIGNAL);
|
|
16833
16701
|
{
|
|
16834
16702
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(strategyName);
|
|
16835
|
-
riskName &&
|
|
16836
|
-
|
|
16703
|
+
riskName &&
|
|
16704
|
+
backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_GET_PENDING_SIGNAL);
|
|
16705
|
+
riskList &&
|
|
16706
|
+
riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_GET_PENDING_SIGNAL));
|
|
16837
16707
|
}
|
|
16838
|
-
|
|
16839
|
-
return await instance.getPendingSignal(symbol, strategyName);
|
|
16708
|
+
return await backtest$1.strategyCoreService.getPendingSignal(true, symbol, strategyName);
|
|
16840
16709
|
};
|
|
16841
16710
|
/**
|
|
16842
16711
|
* Retrieves the currently active scheduled signal for the strategy.
|
|
@@ -16858,11 +16727,12 @@ class BacktestUtils {
|
|
|
16858
16727
|
backtest$1.strategyValidationService.validate(strategyName, BACKTEST_METHOD_NAME_GET_SCHEDULED_SIGNAL);
|
|
16859
16728
|
{
|
|
16860
16729
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(strategyName);
|
|
16861
|
-
riskName &&
|
|
16862
|
-
|
|
16730
|
+
riskName &&
|
|
16731
|
+
backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_GET_SCHEDULED_SIGNAL);
|
|
16732
|
+
riskList &&
|
|
16733
|
+
riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_GET_SCHEDULED_SIGNAL));
|
|
16863
16734
|
}
|
|
16864
|
-
|
|
16865
|
-
return await instance.getScheduledSignal(symbol, strategyName);
|
|
16735
|
+
return await backtest$1.strategyCoreService.getScheduledSignal(true, symbol, strategyName);
|
|
16866
16736
|
};
|
|
16867
16737
|
/**
|
|
16868
16738
|
* Stops the strategy from generating new signals.
|
|
@@ -16885,11 +16755,12 @@ class BacktestUtils {
|
|
|
16885
16755
|
backtest$1.strategyValidationService.validate(strategyName, BACKTEST_METHOD_NAME_STOP);
|
|
16886
16756
|
{
|
|
16887
16757
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(strategyName);
|
|
16888
|
-
riskName &&
|
|
16889
|
-
|
|
16758
|
+
riskName &&
|
|
16759
|
+
backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_STOP);
|
|
16760
|
+
riskList &&
|
|
16761
|
+
riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_STOP));
|
|
16890
16762
|
}
|
|
16891
|
-
|
|
16892
|
-
return await instance.stop(symbol, strategyName);
|
|
16763
|
+
await backtest$1.strategyCoreService.stop(true, { symbol, strategyName });
|
|
16893
16764
|
};
|
|
16894
16765
|
/**
|
|
16895
16766
|
* Cancels the scheduled signal without stopping the strategy.
|
|
@@ -16910,14 +16781,15 @@ class BacktestUtils {
|
|
|
16910
16781
|
* ```
|
|
16911
16782
|
*/
|
|
16912
16783
|
this.cancel = async (symbol, strategyName, cancelId) => {
|
|
16913
|
-
backtest$1.strategyValidationService.validate(strategyName,
|
|
16784
|
+
backtest$1.strategyValidationService.validate(strategyName, BACKTEST_METHOD_NAME_CANCEL);
|
|
16914
16785
|
{
|
|
16915
16786
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(strategyName);
|
|
16916
|
-
riskName &&
|
|
16917
|
-
|
|
16787
|
+
riskName &&
|
|
16788
|
+
backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_CANCEL);
|
|
16789
|
+
riskList &&
|
|
16790
|
+
riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_CANCEL));
|
|
16918
16791
|
}
|
|
16919
|
-
|
|
16920
|
-
return await instance.cancel(symbol, strategyName, cancelId);
|
|
16792
|
+
await backtest$1.strategyCoreService.cancel(true, { symbol, strategyName }, cancelId);
|
|
16921
16793
|
};
|
|
16922
16794
|
/**
|
|
16923
16795
|
* Gets statistical data from all closed signals for a symbol-strategy pair.
|
|
@@ -16933,14 +16805,15 @@ class BacktestUtils {
|
|
|
16933
16805
|
* ```
|
|
16934
16806
|
*/
|
|
16935
16807
|
this.getData = async (symbol, strategyName) => {
|
|
16936
|
-
backtest$1.strategyValidationService.validate(strategyName,
|
|
16808
|
+
backtest$1.strategyValidationService.validate(strategyName, BACKTEST_METHOD_NAME_GET_DATA);
|
|
16937
16809
|
{
|
|
16938
16810
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(strategyName);
|
|
16939
|
-
riskName &&
|
|
16940
|
-
|
|
16811
|
+
riskName &&
|
|
16812
|
+
backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_GET_DATA);
|
|
16813
|
+
riskList &&
|
|
16814
|
+
riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_GET_DATA));
|
|
16941
16815
|
}
|
|
16942
|
-
|
|
16943
|
-
return await instance.getData(symbol, strategyName);
|
|
16816
|
+
return await backtest$1.backtestMarkdownService.getData(symbol, strategyName, true);
|
|
16944
16817
|
};
|
|
16945
16818
|
/**
|
|
16946
16819
|
* Generates markdown report with all closed signals for a symbol-strategy pair.
|
|
@@ -16960,11 +16833,12 @@ class BacktestUtils {
|
|
|
16960
16833
|
backtest$1.strategyValidationService.validate(strategyName, BACKTEST_METHOD_NAME_GET_REPORT);
|
|
16961
16834
|
{
|
|
16962
16835
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(strategyName);
|
|
16963
|
-
riskName &&
|
|
16964
|
-
|
|
16836
|
+
riskName &&
|
|
16837
|
+
backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_GET_REPORT);
|
|
16838
|
+
riskList &&
|
|
16839
|
+
riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_GET_REPORT));
|
|
16965
16840
|
}
|
|
16966
|
-
|
|
16967
|
-
return await instance.getReport(symbol, strategyName, columns);
|
|
16841
|
+
return await backtest$1.backtestMarkdownService.getReport(symbol, strategyName, true, columns);
|
|
16968
16842
|
};
|
|
16969
16843
|
/**
|
|
16970
16844
|
* Saves strategy report to disk.
|
|
@@ -16987,11 +16861,12 @@ class BacktestUtils {
|
|
|
16987
16861
|
backtest$1.strategyValidationService.validate(strategyName, BACKTEST_METHOD_NAME_DUMP);
|
|
16988
16862
|
{
|
|
16989
16863
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(strategyName);
|
|
16990
|
-
riskName &&
|
|
16991
|
-
|
|
16864
|
+
riskName &&
|
|
16865
|
+
backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_DUMP);
|
|
16866
|
+
riskList &&
|
|
16867
|
+
riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, BACKTEST_METHOD_NAME_DUMP));
|
|
16992
16868
|
}
|
|
16993
|
-
|
|
16994
|
-
return await instance.dump(symbol, strategyName, path, columns);
|
|
16869
|
+
await backtest$1.backtestMarkdownService.dump(symbol, strategyName, true, path, columns);
|
|
16995
16870
|
};
|
|
16996
16871
|
/**
|
|
16997
16872
|
* Lists all active backtest instances with their current status.
|
|
@@ -17101,9 +16976,10 @@ class LiveInstance {
|
|
|
17101
16976
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
17102
16977
|
* @param strategyName - Strategy name for this live trading instance
|
|
17103
16978
|
*/
|
|
17104
|
-
constructor(symbol, strategyName) {
|
|
16979
|
+
constructor(symbol, strategyName, exchangeName) {
|
|
17105
16980
|
this.symbol = symbol;
|
|
17106
16981
|
this.strategyName = strategyName;
|
|
16982
|
+
this.exchangeName = exchangeName;
|
|
17107
16983
|
/** A randomly generated string. */
|
|
17108
16984
|
this.id = functoolsKit.randomString();
|
|
17109
16985
|
/** Internal flag indicating if live trading was stopped manually */
|
|
@@ -17145,6 +17021,7 @@ class LiveInstance {
|
|
|
17145
17021
|
id: this.id,
|
|
17146
17022
|
symbol: this.symbol,
|
|
17147
17023
|
strategyName: this.strategyName,
|
|
17024
|
+
exchangeName: this.exchangeName,
|
|
17148
17025
|
status: this.task.getStatus(),
|
|
17149
17026
|
};
|
|
17150
17027
|
};
|
|
@@ -17237,173 +17114,6 @@ class LiveInstance {
|
|
|
17237
17114
|
this._isStopped = true;
|
|
17238
17115
|
};
|
|
17239
17116
|
};
|
|
17240
|
-
/**
|
|
17241
|
-
* Retrieves the currently active pending signal for the strategy.
|
|
17242
|
-
* If no active signal exists, returns null.
|
|
17243
|
-
*
|
|
17244
|
-
* @param symbol - Trading pair symbol
|
|
17245
|
-
* @param strategyName - Name of strategy to get pending signal for
|
|
17246
|
-
* @returns Promise resolving to pending signal or null
|
|
17247
|
-
*
|
|
17248
|
-
* @example
|
|
17249
|
-
* ```typescript
|
|
17250
|
-
* const instance = new LiveInstance();
|
|
17251
|
-
* const pending = await instance.getPendingSignal("BTCUSDT", "my-strategy");
|
|
17252
|
-
* if (pending) {
|
|
17253
|
-
* console.log("Active signal:", pending.id);
|
|
17254
|
-
* }
|
|
17255
|
-
* ```
|
|
17256
|
-
*/
|
|
17257
|
-
this.getPendingSignal = async (symbol, strategyName) => {
|
|
17258
|
-
backtest$1.loggerService.info(LIVE_METHOD_NAME_GET_PENDING_SIGNAL, {
|
|
17259
|
-
symbol,
|
|
17260
|
-
strategyName,
|
|
17261
|
-
});
|
|
17262
|
-
return await backtest$1.strategyCoreService.getPendingSignal(false, symbol, strategyName);
|
|
17263
|
-
};
|
|
17264
|
-
/**
|
|
17265
|
-
* Retrieves the currently active scheduled signal for the strategy.
|
|
17266
|
-
* If no scheduled signal exists, returns null.
|
|
17267
|
-
*
|
|
17268
|
-
* @param symbol - Trading pair symbol
|
|
17269
|
-
* @param strategyName - Name of strategy to get scheduled signal for
|
|
17270
|
-
* @returns Promise resolving to scheduled signal or null
|
|
17271
|
-
*
|
|
17272
|
-
* @example
|
|
17273
|
-
* ```typescript
|
|
17274
|
-
* const instance = new LiveInstance();
|
|
17275
|
-
* const scheduled = await instance.getScheduledSignal("BTCUSDT", "my-strategy");
|
|
17276
|
-
* if (scheduled) {
|
|
17277
|
-
* console.log("Scheduled signal:", scheduled.id);
|
|
17278
|
-
* }
|
|
17279
|
-
* ```
|
|
17280
|
-
*/
|
|
17281
|
-
this.getScheduledSignal = async (symbol, strategyName) => {
|
|
17282
|
-
backtest$1.loggerService.info(LIVE_METHOD_NAME_GET_SCHEDULED_SIGNAL, {
|
|
17283
|
-
symbol,
|
|
17284
|
-
strategyName,
|
|
17285
|
-
});
|
|
17286
|
-
return await backtest$1.strategyCoreService.getScheduledSignal(false, symbol, strategyName);
|
|
17287
|
-
};
|
|
17288
|
-
/**
|
|
17289
|
-
* Stops the strategy from generating new signals.
|
|
17290
|
-
*
|
|
17291
|
-
* Sets internal flag to prevent strategy from opening new signals.
|
|
17292
|
-
* Current active signal (if any) will complete normally.
|
|
17293
|
-
* Live trading will stop at the next safe point (idle/closed state).
|
|
17294
|
-
*
|
|
17295
|
-
* @param symbol - Trading pair symbol
|
|
17296
|
-
* @param strategyName - Strategy name to stop
|
|
17297
|
-
* @returns Promise that resolves when stop flag is set
|
|
17298
|
-
*
|
|
17299
|
-
* @example
|
|
17300
|
-
* ```typescript
|
|
17301
|
-
* const instance = new LiveInstance();
|
|
17302
|
-
* await instance.stop("BTCUSDT", "my-strategy");
|
|
17303
|
-
* ```
|
|
17304
|
-
*/
|
|
17305
|
-
this.stop = async (symbol, strategyName) => {
|
|
17306
|
-
backtest$1.loggerService.info(LIVE_METHOD_NAME_STOP, {
|
|
17307
|
-
symbol,
|
|
17308
|
-
strategyName,
|
|
17309
|
-
});
|
|
17310
|
-
await backtest$1.strategyCoreService.stop(false, { symbol, strategyName });
|
|
17311
|
-
};
|
|
17312
|
-
/**
|
|
17313
|
-
* Cancels the scheduled signal without stopping the strategy.
|
|
17314
|
-
*
|
|
17315
|
-
* Clears the scheduled signal (waiting for priceOpen activation).
|
|
17316
|
-
* Does NOT affect active pending signals or strategy operation.
|
|
17317
|
-
* Does NOT set stop flag - strategy can continue generating new signals.
|
|
17318
|
-
*
|
|
17319
|
-
* @param symbol - Trading pair symbol
|
|
17320
|
-
* @param strategyName - Strategy name
|
|
17321
|
-
* @param cancelId - Optional cancellation ID for tracking user-initiated cancellations
|
|
17322
|
-
* @returns Promise that resolves when scheduled signal is cancelled
|
|
17323
|
-
*
|
|
17324
|
-
* @example
|
|
17325
|
-
* ```typescript
|
|
17326
|
-
* const instance = new LiveInstance();
|
|
17327
|
-
* await instance.cancel("BTCUSDT", "my-strategy", "manual-cancel-001");
|
|
17328
|
-
* ```
|
|
17329
|
-
*/
|
|
17330
|
-
this.cancel = async (symbol, strategyName, cancelId) => {
|
|
17331
|
-
backtest$1.loggerService.info(LIVE_METHOD_NAME_CANCEL, {
|
|
17332
|
-
symbol,
|
|
17333
|
-
strategyName,
|
|
17334
|
-
cancelId,
|
|
17335
|
-
});
|
|
17336
|
-
await backtest$1.strategyCoreService.cancel(false, { symbol, strategyName }, cancelId);
|
|
17337
|
-
};
|
|
17338
|
-
/**
|
|
17339
|
-
* Gets statistical data from all live trading events for a symbol-strategy pair.
|
|
17340
|
-
*
|
|
17341
|
-
* @param symbol - Trading pair symbol
|
|
17342
|
-
* @param strategyName - Strategy name to get data for
|
|
17343
|
-
* @returns Promise resolving to statistical data object
|
|
17344
|
-
*
|
|
17345
|
-
* @example
|
|
17346
|
-
* ```typescript
|
|
17347
|
-
* const instance = new LiveInstance();
|
|
17348
|
-
* const stats = await instance.getData("BTCUSDT", "my-strategy");
|
|
17349
|
-
* console.log(stats.sharpeRatio, stats.winRate);
|
|
17350
|
-
* ```
|
|
17351
|
-
*/
|
|
17352
|
-
this.getData = async (symbol, strategyName) => {
|
|
17353
|
-
backtest$1.loggerService.info("LiveUtils.getData", {
|
|
17354
|
-
symbol,
|
|
17355
|
-
strategyName,
|
|
17356
|
-
});
|
|
17357
|
-
return await backtest$1.liveMarkdownService.getData(symbol, strategyName, false);
|
|
17358
|
-
};
|
|
17359
|
-
/**
|
|
17360
|
-
* Generates markdown report with all events for a symbol-strategy pair.
|
|
17361
|
-
*
|
|
17362
|
-
* @param symbol - Trading pair symbol
|
|
17363
|
-
* @param strategyName - Strategy name to generate report for
|
|
17364
|
-
* @param columns - Optional columns configuration for the report
|
|
17365
|
-
* @returns Promise resolving to markdown formatted report string
|
|
17366
|
-
*
|
|
17367
|
-
* @example
|
|
17368
|
-
* ```typescript
|
|
17369
|
-
* const instance = new LiveInstance();
|
|
17370
|
-
* const markdown = await instance.getReport("BTCUSDT", "my-strategy");
|
|
17371
|
-
* console.log(markdown);
|
|
17372
|
-
* ```
|
|
17373
|
-
*/
|
|
17374
|
-
this.getReport = async (symbol, strategyName, columns) => {
|
|
17375
|
-
backtest$1.loggerService.info(LIVE_METHOD_NAME_GET_REPORT, {
|
|
17376
|
-
symbol,
|
|
17377
|
-
strategyName,
|
|
17378
|
-
});
|
|
17379
|
-
return await backtest$1.liveMarkdownService.getReport(symbol, strategyName, false, columns);
|
|
17380
|
-
};
|
|
17381
|
-
/**
|
|
17382
|
-
* Saves strategy report to disk.
|
|
17383
|
-
*
|
|
17384
|
-
* @param symbol - Trading pair symbol
|
|
17385
|
-
* @param strategyName - Strategy name to save report for
|
|
17386
|
-
* @param path - Optional directory path to save report (default: "./dump/live")
|
|
17387
|
-
* @param columns - Optional columns configuration for the report
|
|
17388
|
-
*
|
|
17389
|
-
* @example
|
|
17390
|
-
* ```typescript
|
|
17391
|
-
* const instance = new LiveInstance();
|
|
17392
|
-
* // Save to default path: ./dump/live/my-strategy.md
|
|
17393
|
-
* await instance.dump("BTCUSDT", "my-strategy");
|
|
17394
|
-
*
|
|
17395
|
-
* // Save to custom path: ./custom/path/my-strategy.md
|
|
17396
|
-
* await instance.dump("BTCUSDT", "my-strategy", "./custom/path");
|
|
17397
|
-
* ```
|
|
17398
|
-
*/
|
|
17399
|
-
this.dump = async (symbol, strategyName, path, columns) => {
|
|
17400
|
-
backtest$1.loggerService.info(LIVE_METHOD_NAME_DUMP, {
|
|
17401
|
-
symbol,
|
|
17402
|
-
strategyName,
|
|
17403
|
-
path,
|
|
17404
|
-
});
|
|
17405
|
-
await backtest$1.liveMarkdownService.dump(symbol, strategyName, false, path, columns);
|
|
17406
|
-
};
|
|
17407
17117
|
}
|
|
17408
17118
|
}
|
|
17409
17119
|
/**
|
|
@@ -17441,7 +17151,7 @@ class LiveUtils {
|
|
|
17441
17151
|
* Memoized function to get or create LiveInstance for a symbol-strategy pair.
|
|
17442
17152
|
* Each symbol-strategy combination gets its own isolated instance.
|
|
17443
17153
|
*/
|
|
17444
|
-
this._getInstance = functoolsKit.memoize(([symbol, strategyName]) => `${symbol}:${strategyName}`, (symbol, strategyName) => new LiveInstance(symbol, strategyName));
|
|
17154
|
+
this._getInstance = functoolsKit.memoize(([symbol, strategyName]) => `${symbol}:${strategyName}`, (symbol, strategyName, exchangeName) => new LiveInstance(symbol, strategyName, exchangeName));
|
|
17445
17155
|
/**
|
|
17446
17156
|
* Runs live trading for a symbol with context propagation.
|
|
17447
17157
|
*
|
|
@@ -17462,7 +17172,7 @@ class LiveUtils {
|
|
|
17462
17172
|
riskName && backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_RUN);
|
|
17463
17173
|
riskList && riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_RUN));
|
|
17464
17174
|
}
|
|
17465
|
-
const instance = this._getInstance(symbol, context.strategyName);
|
|
17175
|
+
const instance = this._getInstance(symbol, context.strategyName, context.exchangeName);
|
|
17466
17176
|
return instance.run(symbol, context);
|
|
17467
17177
|
};
|
|
17468
17178
|
/**
|
|
@@ -17494,7 +17204,7 @@ class LiveUtils {
|
|
|
17494
17204
|
riskName && backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_BACKGROUND);
|
|
17495
17205
|
riskList && riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_BACKGROUND));
|
|
17496
17206
|
}
|
|
17497
|
-
const instance = this._getInstance(symbol, context.strategyName);
|
|
17207
|
+
const instance = this._getInstance(symbol, context.strategyName, context.exchangeName);
|
|
17498
17208
|
return instance.background(symbol, context);
|
|
17499
17209
|
};
|
|
17500
17210
|
/**
|
|
@@ -17520,8 +17230,7 @@ class LiveUtils {
|
|
|
17520
17230
|
riskName && backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_GET_PENDING_SIGNAL);
|
|
17521
17231
|
riskList && riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_GET_PENDING_SIGNAL));
|
|
17522
17232
|
}
|
|
17523
|
-
|
|
17524
|
-
return await instance.getPendingSignal(symbol, strategyName);
|
|
17233
|
+
return await backtest$1.strategyCoreService.getPendingSignal(false, symbol, strategyName);
|
|
17525
17234
|
};
|
|
17526
17235
|
/**
|
|
17527
17236
|
* Retrieves the currently active scheduled signal for the strategy.
|
|
@@ -17546,8 +17255,7 @@ class LiveUtils {
|
|
|
17546
17255
|
riskName && backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_GET_SCHEDULED_SIGNAL);
|
|
17547
17256
|
riskList && riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_GET_SCHEDULED_SIGNAL));
|
|
17548
17257
|
}
|
|
17549
|
-
|
|
17550
|
-
return await instance.getScheduledSignal(symbol, strategyName);
|
|
17258
|
+
return await backtest$1.strategyCoreService.getScheduledSignal(false, symbol, strategyName);
|
|
17551
17259
|
};
|
|
17552
17260
|
/**
|
|
17553
17261
|
* Stops the strategy from generating new signals.
|
|
@@ -17573,8 +17281,7 @@ class LiveUtils {
|
|
|
17573
17281
|
riskName && backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_STOP);
|
|
17574
17282
|
riskList && riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_STOP));
|
|
17575
17283
|
}
|
|
17576
|
-
|
|
17577
|
-
return await instance.stop(symbol, strategyName);
|
|
17284
|
+
await backtest$1.strategyCoreService.stop(false, { symbol, strategyName });
|
|
17578
17285
|
};
|
|
17579
17286
|
/**
|
|
17580
17287
|
* Cancels the scheduled signal without stopping the strategy.
|
|
@@ -17601,8 +17308,7 @@ class LiveUtils {
|
|
|
17601
17308
|
riskName && backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_CANCEL);
|
|
17602
17309
|
riskList && riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_CANCEL));
|
|
17603
17310
|
}
|
|
17604
|
-
|
|
17605
|
-
return await instance.cancel(symbol, strategyName, cancelId);
|
|
17311
|
+
await backtest$1.strategyCoreService.cancel(false, { symbol, strategyName }, cancelId);
|
|
17606
17312
|
};
|
|
17607
17313
|
/**
|
|
17608
17314
|
* Gets statistical data from all live trading events for a symbol-strategy pair.
|
|
@@ -17624,8 +17330,7 @@ class LiveUtils {
|
|
|
17624
17330
|
riskName && backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_GET_DATA);
|
|
17625
17331
|
riskList && riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_GET_DATA));
|
|
17626
17332
|
}
|
|
17627
|
-
|
|
17628
|
-
return await instance.getData(symbol, strategyName);
|
|
17333
|
+
return await backtest$1.liveMarkdownService.getData(symbol, strategyName, false);
|
|
17629
17334
|
};
|
|
17630
17335
|
/**
|
|
17631
17336
|
* Generates markdown report with all events for a symbol-strategy pair.
|
|
@@ -17648,8 +17353,7 @@ class LiveUtils {
|
|
|
17648
17353
|
riskName && backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_GET_REPORT);
|
|
17649
17354
|
riskList && riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_GET_REPORT));
|
|
17650
17355
|
}
|
|
17651
|
-
|
|
17652
|
-
return await instance.getReport(symbol, strategyName, columns);
|
|
17356
|
+
return await backtest$1.liveMarkdownService.getReport(symbol, strategyName, false, columns);
|
|
17653
17357
|
};
|
|
17654
17358
|
/**
|
|
17655
17359
|
* Saves strategy report to disk.
|
|
@@ -17675,8 +17379,7 @@ class LiveUtils {
|
|
|
17675
17379
|
riskName && backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_DUMP);
|
|
17676
17380
|
riskList && riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, LIVE_METHOD_NAME_DUMP));
|
|
17677
17381
|
}
|
|
17678
|
-
|
|
17679
|
-
return await instance.dump(symbol, strategyName, path, columns);
|
|
17382
|
+
await backtest$1.liveMarkdownService.dump(symbol, strategyName, false, path, columns);
|
|
17680
17383
|
};
|
|
17681
17384
|
/**
|
|
17682
17385
|
* Lists all active live trading instances with their current status.
|
|
@@ -18194,123 +17897,6 @@ class WalkerInstance {
|
|
|
18194
17897
|
this._isStopped = true;
|
|
18195
17898
|
};
|
|
18196
17899
|
};
|
|
18197
|
-
/**
|
|
18198
|
-
* Stops all strategies in the walker from generating new signals.
|
|
18199
|
-
*
|
|
18200
|
-
* Iterates through all strategies defined in walker schema and:
|
|
18201
|
-
* 1. Sends stop signal via walkerStopSubject (interrupts current running strategy)
|
|
18202
|
-
* 2. Sets internal stop flag for each strategy (prevents new signals)
|
|
18203
|
-
*
|
|
18204
|
-
* Current active signals (if any) will complete normally.
|
|
18205
|
-
* Walker will stop at the next safe point.
|
|
18206
|
-
*
|
|
18207
|
-
* Supports multiple walkers running on the same symbol simultaneously.
|
|
18208
|
-
* Stop signal is filtered by walkerName to prevent interference.
|
|
18209
|
-
*
|
|
18210
|
-
* @param symbol - Trading pair symbol
|
|
18211
|
-
* @param walkerName - Walker name to stop
|
|
18212
|
-
* @returns Promise that resolves when all stop flags are set
|
|
18213
|
-
*
|
|
18214
|
-
* @example
|
|
18215
|
-
* ```typescript
|
|
18216
|
-
* const instance = new WalkerInstance();
|
|
18217
|
-
* await instance.stop("BTCUSDT", "my-walker");
|
|
18218
|
-
* ```
|
|
18219
|
-
*/
|
|
18220
|
-
this.stop = async (symbol, walkerName) => {
|
|
18221
|
-
backtest$1.loggerService.info(WALKER_METHOD_NAME_STOP, {
|
|
18222
|
-
symbol,
|
|
18223
|
-
walkerName,
|
|
18224
|
-
});
|
|
18225
|
-
const walkerSchema = backtest$1.walkerSchemaService.get(walkerName);
|
|
18226
|
-
for (const strategyName of walkerSchema.strategies) {
|
|
18227
|
-
await walkerStopSubject.next({ symbol, strategyName, walkerName });
|
|
18228
|
-
await backtest$1.strategyCoreService.stop(true, { symbol, strategyName });
|
|
18229
|
-
}
|
|
18230
|
-
};
|
|
18231
|
-
/**
|
|
18232
|
-
* Gets walker results data from all strategy comparisons.
|
|
18233
|
-
*
|
|
18234
|
-
* @param symbol - Trading symbol
|
|
18235
|
-
* @param walkerName - Walker name to get data for
|
|
18236
|
-
* @returns Promise resolving to walker results data object
|
|
18237
|
-
*
|
|
18238
|
-
* @example
|
|
18239
|
-
* ```typescript
|
|
18240
|
-
* const instance = new WalkerInstance();
|
|
18241
|
-
* const results = await instance.getData("BTCUSDT", "my-walker");
|
|
18242
|
-
* console.log(results.bestStrategy, results.bestMetric);
|
|
18243
|
-
* ```
|
|
18244
|
-
*/
|
|
18245
|
-
this.getData = async (symbol, walkerName) => {
|
|
18246
|
-
backtest$1.loggerService.info(WALKER_METHOD_NAME_GET_DATA, {
|
|
18247
|
-
symbol,
|
|
18248
|
-
walkerName,
|
|
18249
|
-
});
|
|
18250
|
-
const walkerSchema = backtest$1.walkerSchemaService.get(walkerName);
|
|
18251
|
-
return await backtest$1.walkerMarkdownService.getData(walkerName, symbol, walkerSchema.metric || "sharpeRatio", {
|
|
18252
|
-
exchangeName: walkerSchema.exchangeName,
|
|
18253
|
-
frameName: walkerSchema.frameName,
|
|
18254
|
-
});
|
|
18255
|
-
};
|
|
18256
|
-
/**
|
|
18257
|
-
* Generates markdown report with all strategy comparisons for a walker.
|
|
18258
|
-
*
|
|
18259
|
-
* @param symbol - Trading symbol
|
|
18260
|
-
* @param walkerName - Walker name to generate report for
|
|
18261
|
-
* @param strategyColumns - Optional strategy columns configuration
|
|
18262
|
-
* @param pnlColumns - Optional PNL columns configuration
|
|
18263
|
-
* @returns Promise resolving to markdown formatted report string
|
|
18264
|
-
*
|
|
18265
|
-
* @example
|
|
18266
|
-
* ```typescript
|
|
18267
|
-
* const instance = new WalkerInstance();
|
|
18268
|
-
* const markdown = await instance.getReport("BTCUSDT", "my-walker");
|
|
18269
|
-
* console.log(markdown);
|
|
18270
|
-
* ```
|
|
18271
|
-
*/
|
|
18272
|
-
this.getReport = async (symbol, walkerName, strategyColumns, pnlColumns) => {
|
|
18273
|
-
backtest$1.loggerService.info(WALKER_METHOD_NAME_GET_REPORT, {
|
|
18274
|
-
symbol,
|
|
18275
|
-
walkerName,
|
|
18276
|
-
});
|
|
18277
|
-
const walkerSchema = backtest$1.walkerSchemaService.get(walkerName);
|
|
18278
|
-
return await backtest$1.walkerMarkdownService.getReport(walkerName, symbol, walkerSchema.metric || "sharpeRatio", {
|
|
18279
|
-
exchangeName: walkerSchema.exchangeName,
|
|
18280
|
-
frameName: walkerSchema.frameName,
|
|
18281
|
-
}, strategyColumns, pnlColumns);
|
|
18282
|
-
};
|
|
18283
|
-
/**
|
|
18284
|
-
* Saves walker report to disk.
|
|
18285
|
-
*
|
|
18286
|
-
* @param symbol - Trading symbol
|
|
18287
|
-
* @param walkerName - Walker name to save report for
|
|
18288
|
-
* @param path - Optional directory path to save report (default: "./dump/walker")
|
|
18289
|
-
* @param strategyColumns - Optional strategy columns configuration
|
|
18290
|
-
* @param pnlColumns - Optional PNL columns configuration
|
|
18291
|
-
*
|
|
18292
|
-
* @example
|
|
18293
|
-
* ```typescript
|
|
18294
|
-
* const instance = new WalkerInstance();
|
|
18295
|
-
* // Save to default path: ./dump/walker/my-walker.md
|
|
18296
|
-
* await instance.dump("BTCUSDT", "my-walker");
|
|
18297
|
-
*
|
|
18298
|
-
* // Save to custom path: ./custom/path/my-walker.md
|
|
18299
|
-
* await instance.dump("BTCUSDT", "my-walker", "./custom/path");
|
|
18300
|
-
* ```
|
|
18301
|
-
*/
|
|
18302
|
-
this.dump = async (symbol, walkerName, path, strategyColumns, pnlColumns) => {
|
|
18303
|
-
backtest$1.loggerService.info(WALKER_METHOD_NAME_DUMP, {
|
|
18304
|
-
symbol,
|
|
18305
|
-
walkerName,
|
|
18306
|
-
path,
|
|
18307
|
-
});
|
|
18308
|
-
const walkerSchema = backtest$1.walkerSchemaService.get(walkerName);
|
|
18309
|
-
await backtest$1.walkerMarkdownService.dump(walkerName, symbol, walkerSchema.metric || "sharpeRatio", {
|
|
18310
|
-
exchangeName: walkerSchema.exchangeName,
|
|
18311
|
-
frameName: walkerSchema.frameName,
|
|
18312
|
-
}, path, strategyColumns, pnlColumns);
|
|
18313
|
-
};
|
|
18314
17900
|
}
|
|
18315
17901
|
}
|
|
18316
17902
|
/**
|
|
@@ -18431,8 +18017,10 @@ class WalkerUtils {
|
|
|
18431
18017
|
riskList &&
|
|
18432
18018
|
riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, WALKER_METHOD_NAME_STOP));
|
|
18433
18019
|
}
|
|
18434
|
-
const
|
|
18435
|
-
|
|
18020
|
+
for (const strategyName of walkerSchema.strategies) {
|
|
18021
|
+
await walkerStopSubject.next({ symbol, strategyName, walkerName });
|
|
18022
|
+
await backtest$1.strategyCoreService.stop(true, { symbol, strategyName });
|
|
18023
|
+
}
|
|
18436
18024
|
};
|
|
18437
18025
|
/**
|
|
18438
18026
|
* Gets walker results data from all strategy comparisons.
|
|
@@ -18458,8 +18046,10 @@ class WalkerUtils {
|
|
|
18458
18046
|
riskList &&
|
|
18459
18047
|
riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, WALKER_METHOD_NAME_GET_DATA));
|
|
18460
18048
|
}
|
|
18461
|
-
|
|
18462
|
-
|
|
18049
|
+
return await backtest$1.walkerMarkdownService.getData(walkerName, symbol, walkerSchema.metric || "sharpeRatio", {
|
|
18050
|
+
exchangeName: walkerSchema.exchangeName,
|
|
18051
|
+
frameName: walkerSchema.frameName,
|
|
18052
|
+
});
|
|
18463
18053
|
};
|
|
18464
18054
|
/**
|
|
18465
18055
|
* Generates markdown report with all strategy comparisons for a walker.
|
|
@@ -18487,8 +18077,10 @@ class WalkerUtils {
|
|
|
18487
18077
|
riskList &&
|
|
18488
18078
|
riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, WALKER_METHOD_NAME_GET_REPORT));
|
|
18489
18079
|
}
|
|
18490
|
-
|
|
18491
|
-
|
|
18080
|
+
return await backtest$1.walkerMarkdownService.getReport(walkerName, symbol, walkerSchema.metric || "sharpeRatio", {
|
|
18081
|
+
exchangeName: walkerSchema.exchangeName,
|
|
18082
|
+
frameName: walkerSchema.frameName,
|
|
18083
|
+
}, strategyColumns, pnlColumns);
|
|
18492
18084
|
};
|
|
18493
18085
|
/**
|
|
18494
18086
|
* Saves walker report to disk.
|
|
@@ -18519,8 +18111,10 @@ class WalkerUtils {
|
|
|
18519
18111
|
riskList &&
|
|
18520
18112
|
riskList.forEach((riskName) => backtest$1.riskValidationService.validate(riskName, WALKER_METHOD_NAME_DUMP));
|
|
18521
18113
|
}
|
|
18522
|
-
|
|
18523
|
-
|
|
18114
|
+
await backtest$1.walkerMarkdownService.dump(walkerName, symbol, walkerSchema.metric || "sharpeRatio", {
|
|
18115
|
+
exchangeName: walkerSchema.exchangeName,
|
|
18116
|
+
frameName: walkerSchema.frameName,
|
|
18117
|
+
}, path, strategyColumns, pnlColumns);
|
|
18524
18118
|
};
|
|
18525
18119
|
/**
|
|
18526
18120
|
* Lists all active walker instances with their current status.
|
|
@@ -20039,6 +19633,12 @@ class NotificationInstance {
|
|
|
20039
19633
|
* Automatically called on first use.
|
|
20040
19634
|
*/
|
|
20041
19635
|
this.waitForInit = functoolsKit.singleshot(async () => {
|
|
19636
|
+
// Add bootstrap notification to mark initialization
|
|
19637
|
+
this._addNotification({
|
|
19638
|
+
type: "bootstrap",
|
|
19639
|
+
id: CREATE_KEY_FN(),
|
|
19640
|
+
timestamp: Date.now(),
|
|
19641
|
+
});
|
|
20042
19642
|
// Signal events
|
|
20043
19643
|
signalEmitter.subscribe(this._handleSignal);
|
|
20044
19644
|
// Partial profit/loss events
|