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