Update bundle backtests
This commit is contained in:
@@ -105,7 +105,7 @@ public class BundleBacktestGrain : Grain, IBundleBacktestGrain, IRemindable
|
||||
await backtester.UpdateBundleBacktestRequestAsync(bundleRequest);
|
||||
|
||||
// Generate backtest requests from variant configuration
|
||||
var backtestRequests = GenerateBacktestRequestsFromVariants(bundleRequest);
|
||||
var backtestRequests = await GenerateBacktestRequestsFromVariants(bundleRequest);
|
||||
if (backtestRequests == null || !backtestRequests.Any())
|
||||
{
|
||||
throw new InvalidOperationException("Failed to generate backtest requests from variants");
|
||||
@@ -133,7 +133,7 @@ public class BundleBacktestGrain : Grain, IBundleBacktestGrain, IRemindable
|
||||
/// <summary>
|
||||
/// Generates individual backtest requests from variant configuration
|
||||
/// </summary>
|
||||
private List<RunBacktestRequest> GenerateBacktestRequestsFromVariants(BundleBacktestRequest bundleRequest)
|
||||
private async Task<List<RunBacktestRequest>> GenerateBacktestRequestsFromVariants(BundleBacktestRequest bundleRequest)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -149,6 +149,21 @@ public class BundleBacktestGrain : Grain, IBundleBacktestGrain, IRemindable
|
||||
return new List<RunBacktestRequest>();
|
||||
}
|
||||
|
||||
// Get the first account for the user using AccountService
|
||||
var firstAccount = await ServiceScopeHelpers.WithScopedService<IAccountService, Account?>(
|
||||
_scopeFactory,
|
||||
async service =>
|
||||
{
|
||||
var accounts = await service.GetAccountsByUserAsync(bundleRequest.User, hideSecrets: true, getBalance: false);
|
||||
return accounts.FirstOrDefault();
|
||||
});
|
||||
|
||||
if (firstAccount == null)
|
||||
{
|
||||
_logger.LogError("No accounts found for user {UserId} in bundle request {RequestId}", bundleRequest.User.Id, bundleRequest.RequestId);
|
||||
return new List<RunBacktestRequest>();
|
||||
}
|
||||
|
||||
var backtestRequests = new List<RunBacktestRequest>();
|
||||
|
||||
foreach (var dateRange in dateTimeRanges)
|
||||
@@ -159,7 +174,7 @@ public class BundleBacktestGrain : Grain, IBundleBacktestGrain, IRemindable
|
||||
{
|
||||
var config = new TradingBotConfigRequest
|
||||
{
|
||||
AccountName = universalConfig.AccountName,
|
||||
AccountName = firstAccount.Name,
|
||||
Ticker = ticker,
|
||||
Timeframe = universalConfig.Timeframe,
|
||||
IsForWatchingOnly = universalConfig.IsForWatchingOnly,
|
||||
|
||||
@@ -94,7 +94,7 @@ public class BundleBacktestWorker : BaseWorker<BundleBacktestWorker>
|
||||
await backtester.UpdateBundleBacktestRequestAsync(bundleRequest);
|
||||
|
||||
// Generate backtest requests from the new variant structure
|
||||
var backtestRequests = GenerateBacktestRequestsFromVariants(bundleRequest);
|
||||
var backtestRequests = await GenerateBacktestRequestsFromVariants(bundleRequest);
|
||||
if (backtestRequests == null || !backtestRequests.Any())
|
||||
{
|
||||
throw new InvalidOperationException("Failed to generate backtest requests from variants");
|
||||
@@ -297,7 +297,7 @@ public class BundleBacktestWorker : BaseWorker<BundleBacktestWorker>
|
||||
var succeededIds = new HashSet<string>(failedBundle.Results ?? new List<string>());
|
||||
|
||||
// Generate backtest requests from the new variant structure
|
||||
var originalRequests = GenerateBacktestRequestsFromVariants(failedBundle);
|
||||
var originalRequests = await GenerateBacktestRequestsFromVariants(failedBundle);
|
||||
if (originalRequests == null || !originalRequests.Any()) continue;
|
||||
|
||||
for (int i = failedBundle.CompletedBacktests; i < originalRequests.Count; i++)
|
||||
@@ -339,7 +339,7 @@ public class BundleBacktestWorker : BaseWorker<BundleBacktestWorker>
|
||||
/// <summary>
|
||||
/// Generates individual backtest requests from variant configuration
|
||||
/// </summary>
|
||||
private List<RunBacktestRequest> GenerateBacktestRequestsFromVariants(BundleBacktestRequest bundleRequest)
|
||||
private async Task<List<RunBacktestRequest>> GenerateBacktestRequestsFromVariants(BundleBacktestRequest bundleRequest)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -355,6 +355,18 @@ public class BundleBacktestWorker : BaseWorker<BundleBacktestWorker>
|
||||
return new List<RunBacktestRequest>();
|
||||
}
|
||||
|
||||
// Get the first account for the user using AccountService
|
||||
using var scope = _serviceProvider.CreateScope();
|
||||
var accountService = scope.ServiceProvider.GetRequiredService<IAccountService>();
|
||||
var accounts = await accountService.GetAccountsByUserAsync(bundleRequest.User, hideSecrets: true, getBalance: false);
|
||||
var firstAccount = accounts.FirstOrDefault();
|
||||
|
||||
if (firstAccount == null)
|
||||
{
|
||||
_logger.LogError("No accounts found for user {UserId} in bundle request {RequestId}", bundleRequest.User.Id, bundleRequest.RequestId);
|
||||
return new List<RunBacktestRequest>();
|
||||
}
|
||||
|
||||
var backtestRequests = new List<RunBacktestRequest>();
|
||||
|
||||
foreach (var dateRange in dateTimeRanges)
|
||||
@@ -365,7 +377,7 @@ public class BundleBacktestWorker : BaseWorker<BundleBacktestWorker>
|
||||
{
|
||||
var config = new TradingBotConfigRequest
|
||||
{
|
||||
AccountName = universalConfig.AccountName,
|
||||
AccountName = firstAccount.Name,
|
||||
Ticker = ticker,
|
||||
Timeframe = universalConfig.Timeframe,
|
||||
IsForWatchingOnly = universalConfig.IsForWatchingOnly,
|
||||
|
||||
Reference in New Issue
Block a user