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

View File

@@ -77,6 +77,13 @@ namespace Managing.Domain.Trades
[Required] [Required]
public Guid InitiatorIdentifier { get; set; } public Guid InitiatorIdentifier { get; set; }
/// <summary>
/// Indicates whether position recovery has been attempted for this cancelled position
/// Used to prevent repeated recovery attempts for positions that were never filled
/// </summary>
[Id(18)]
public bool RecoveryAttempted { get; set; }
/// <summary> /// <summary>
/// Return true if position is finished even if the position was canceled or rejected /// Return true if position is finished even if the position was canceled or rejected
/// </summary> /// </summary>