Fix loop when trying to recover the cancelled position

This commit is contained in:
2025-11-19 20:23:44 +07:00
parent 61f95981a7
commit f56d75d28f
2 changed files with 12 additions and 2 deletions

View File

@@ -2935,8 +2935,8 @@ public class TradingBotBase : ITradingBot
return; // No positions at all
}
// Only attempt recovery if the last position is cancelled
if (lastPosition.Status != PositionStatus.Canceled)
// Only attempt recovery if the last position is cancelled and recovery hasn't been attempted yet
if (lastPosition.Status != PositionStatus.Canceled || lastPosition.RecoveryAttempted)
{
return;
}
@@ -2955,6 +2955,9 @@ public class TradingBotBase : ITradingBot
return;
}
// Mark recovery as attempted before proceeding
lastPosition.RecoveryAttempted = true;
// Attempt recovery for the last position only
bool recovered = await RecoverOpenPositionFromBroker(signal, lastPosition);
if (recovered)