diff --git a/src/Managing.Application/Bots/TradingBotBase.cs b/src/Managing.Application/Bots/TradingBotBase.cs index 96e77df9..81e8faa8 100644 --- a/src/Managing.Application/Bots/TradingBotBase.cs +++ b/src/Managing.Application/Bots/TradingBotBase.cs @@ -372,6 +372,9 @@ public class TradingBotBase : ITradingBot private async Task ManagePositions() { + // Recovery Logic: Check for recently canceled positions that might need recovery + await RecoverRecentlyCanceledPositions(); + // Early exit optimization - skip if no positions to manage // Optimized: Use for loop to avoid multiple iterations bool hasOpenPositions = false; @@ -400,8 +403,7 @@ public class TradingBotBase : ITradingBot if (!hasOpenPositions && !hasWaitingSignals) return; - // Recovery Logic: Check for recently canceled positions that might need recovery - await RecoverRecentlyCanceledPositions(); + // First, process all existing positions that are not finished // Optimized: Inline the filter to avoid LINQ overhead