From 5328d760ddfc740397563b61e610d7806cee9e41 Mon Sep 17 00:00:00 2001 From: cryptooda Date: Thu, 11 Dec 2025 23:41:53 +0700 Subject: [PATCH] Add support for backtesting trading types in LiveTradingBotGrain and TradingBox - Introduced handling for TradingType.BacktestFutures and TradingType.BacktestSpot in LiveTradingBotGrain. - Updated TradingBox to map backtest trading types to their respective futures and spot types. --- src/Managing.Application/Bots/Grains/LiveTradingBotGrain.cs | 2 ++ .../Workers/BundleBacktestHealthCheckWorker.cs | 6 ++---- src/Managing.Domain/Shared/Helpers/TradingBox.cs | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Managing.Application/Bots/Grains/LiveTradingBotGrain.cs b/src/Managing.Application/Bots/Grains/LiveTradingBotGrain.cs index 3c63efad..25da085a 100644 --- a/src/Managing.Application/Bots/Grains/LiveTradingBotGrain.cs +++ b/src/Managing.Application/Bots/Grains/LiveTradingBotGrain.cs @@ -549,6 +549,8 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable { TradingType.Futures => new FuturesBot(logger, _scopeFactory, config, streamProvider), TradingType.Spot => new SpotBot(logger, _scopeFactory, config, streamProvider), + TradingType.BacktestFutures => new FuturesBot(logger, _scopeFactory, config, streamProvider), + TradingType.BacktestSpot => new SpotBot(logger, _scopeFactory, config, streamProvider), _ => throw new InvalidOperationException($"Unsupported TradingType for live trading: {config.TradingType}") }; diff --git a/src/Managing.Application/Workers/BundleBacktestHealthCheckWorker.cs b/src/Managing.Application/Workers/BundleBacktestHealthCheckWorker.cs index 90b32330..2d60d374 100644 --- a/src/Managing.Application/Workers/BundleBacktestHealthCheckWorker.cs +++ b/src/Managing.Application/Workers/BundleBacktestHealthCheckWorker.cs @@ -448,7 +448,7 @@ public class BundleBacktestHealthCheckWorker : BackgroundService bundle.Status = failedJobs == 0 ? BundleBacktestRequestStatus.Completed - : BundleBacktestRequestStatus.Completed; + : BundleBacktestRequestStatus.Failed; bundle.CompletedBacktests = completedJobs; bundle.FailedBacktests = failedJobs; bundle.CompletedAt = DateTime.UtcNow; @@ -464,7 +464,6 @@ public class BundleBacktestHealthCheckWorker : BackgroundService // Some jobs are still pending or running - bundle is genuinely stuck // Reset any stale running jobs back to pending var runningJobs = jobs.Where(j => j.Status == JobStatus.Running).ToList(); - var resetJobCount = 0; foreach (var job in runningJobs) { @@ -482,14 +481,13 @@ public class BundleBacktestHealthCheckWorker : BackgroundService job.AssignedWorkerId = null; job.LastHeartbeat = null; await jobRepository.UpdateAsync(job); - resetJobCount++; } } // Update bundle timestamp to give it another chance bundle.UpdatedAt = DateTime.UtcNow; bundle.ErrorMessage = - $"Bundle was stuck. Reset {resetJobCount} stale jobs to pending."; + $"Bundle was stuck. Reset {runningJobs.Count(j => j.Status == JobStatus.Pending)} stale jobs to pending."; } await backtestRepository.UpdateBundleBacktestRequestAsync(bundle); diff --git a/src/Managing.Domain/Shared/Helpers/TradingBox.cs b/src/Managing.Domain/Shared/Helpers/TradingBox.cs index 717a10f6..6d5b05cc 100644 --- a/src/Managing.Domain/Shared/Helpers/TradingBox.cs +++ b/src/Managing.Domain/Shared/Helpers/TradingBox.cs @@ -1359,6 +1359,8 @@ public static class TradingBox { TradingType.BacktestFutures => TradingType.Futures, TradingType.BacktestSpot => TradingType.Spot, + TradingType.Futures => TradingType.Futures, + TradingType.Spot => TradingType.Spot, _ => throw new InvalidOperationException($"Unsupported TradingType for live trading: {tradingType}") }; }