Fix loop when trying to recover the cancelled position
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -77,6 +77,13 @@ namespace Managing.Domain.Trades
|
||||
[Required]
|
||||
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>
|
||||
/// Return true if position is finished even if the position was canceled or rejected
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user