diff --git a/src/Managing.Application/Backtesting/Backtester.cs b/src/Managing.Application/Backtesting/Backtester.cs index 3b13a82..f2e7d34 100644 --- a/src/Managing.Application/Backtesting/Backtester.cs +++ b/src/Managing.Application/Backtesting/Backtester.cs @@ -265,6 +265,16 @@ namespace Managing.Application.Backtesting currentCandle++; + // Check if wallet balance fell below 10 USDC and break if so + var currentWalletBalance = bot.WalletBalances.Values.LastOrDefault(); + if (currentWalletBalance < 10m) + { + _logger.LogWarning( + "Backtest stopped early: Wallet balance fell below 10 USDC (Current: {CurrentBalance:F2} USDC) at candle {CurrentCandle}/{TotalCandles} from {CandleDate}", + currentWalletBalance, currentCandle, totalCandles, candle.Date.ToString("yyyy-MM-dd HH:mm")); + break; + } + // Log progress every 10% or every 1000 candles, whichever comes first var currentPercentage = (int)((double)currentCandle / totalCandles * 100); var shouldLog = currentPercentage >= lastLoggedPercentage + 10 ||