Add cancellation token support to backtest execution and update progress handling
This commit is contained in:
@@ -125,6 +125,7 @@ public class BacktestExecutor
|
||||
/// <param name="bundleRequestId">Optional bundle request ID to update with backtest result</param>
|
||||
/// <param name="metadata">Additional metadata</param>
|
||||
/// <param name="progressCallback">Optional callback for progress updates (0-100)</param>
|
||||
/// <param name="cancellationToken">Cancellation token to stop execution</param>
|
||||
/// <returns>The lightweight backtest result</returns>
|
||||
public async Task<LightBacktest> ExecuteAsync(
|
||||
TradingBotConfig config,
|
||||
@@ -135,7 +136,8 @@ public class BacktestExecutor
|
||||
string requestId = null,
|
||||
Guid? bundleRequestId = null,
|
||||
object metadata = null,
|
||||
Func<int, Task> progressCallback = null)
|
||||
Func<int, Task> progressCallback = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (candles == null || candles.Count == 0)
|
||||
{
|
||||
@@ -247,6 +249,9 @@ public class BacktestExecutor
|
||||
// Process all candles with optimized rolling window approach
|
||||
foreach (var candle in orderedCandles)
|
||||
{
|
||||
// Check for cancellation (timeout or shutdown)
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// Add to HashSet for reuse
|
||||
fixedCandles.Add(candle);
|
||||
tradingBot.LastCandle = candle;
|
||||
|
||||
@@ -65,7 +65,8 @@ public class BacktestExecutorAdapter : IBacktester
|
||||
requestId,
|
||||
bundleRequestId: null,
|
||||
metadata,
|
||||
progressCallback: null);
|
||||
progressCallback: null,
|
||||
cancellationToken: default);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -88,7 +89,8 @@ public class BacktestExecutorAdapter : IBacktester
|
||||
requestId,
|
||||
bundleRequestId: null,
|
||||
metadata,
|
||||
progressCallback: null);
|
||||
progressCallback: null,
|
||||
cancellationToken: default);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user