Remove extra message on the low usdc while position open

This commit is contained in:
2025-10-05 02:49:33 +07:00
parent 4aad20b30b
commit b25f0be083

View File

@@ -259,9 +259,10 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
var hasOpenPositions = await HasOpenPositionsInDatabaseAsync(); var hasOpenPositions = await HasOpenPositionsInDatabaseAsync();
if (hasOpenPositions) if (hasOpenPositions)
{ {
_logger.LogWarning("Cannot stop LiveTradingBotGrain {GrainId} - bot has open positions in database", _logger.LogWarning("Cannot stop strategy {Name} : strategy has open positions in database",
this.GetPrimaryKey()); _tradingBot?.Config.Name);
throw new InvalidOperationException("Cannot stop bot while it has open positions. Please close all positions first."); throw new InvalidOperationException(
"Cannot stop bot while it has open positions. Please close all positions first.");
} }
} }
@@ -372,24 +373,12 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
if (!balanceCheckResult.IsSuccessful) if (!balanceCheckResult.IsSuccessful)
{ {
// Log the specific reason for the failure
await _tradingBot.LogWarning(
$"Balance check failed: {balanceCheckResult.Message} (Reason: {balanceCheckResult.FailureReason})");
// Check if the bot should stop due to this failure // Check if the bot should stop due to this failure
if (balanceCheckResult.ShouldStopBot) if (balanceCheckResult.ShouldStopBot)
{ {
await _tradingBot.LogWarning(
$"Stopping bot due to balance check failure: {balanceCheckResult.Message}");
await StopAsync(); await StopAsync();
return; return;
} }
else
{
// Skip this execution cycle but continue running
await _tradingBot.LogInformation("Skipping this execution cycle due to balance check failure.");
return;
}
} }
} }
catch (Exception ex) catch (Exception ex)
@@ -618,7 +607,8 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
{ {
_logger.LogWarning("Cannot delete LiveTradingBotGrain {GrainId} - bot has open positions in database", _logger.LogWarning("Cannot delete LiveTradingBotGrain {GrainId} - bot has open positions in database",
this.GetPrimaryKey()); this.GetPrimaryKey());
throw new InvalidOperationException("Cannot delete bot while it has open positions. Please close all positions first."); throw new InvalidOperationException(
"Cannot delete bot while it has open positions. Please close all positions first.");
} }
try try
@@ -893,7 +883,8 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Error checking open positions for LiveTradingBotGrain {GrainId}", this.GetPrimaryKey()); _logger.LogError(ex, "Error checking open positions for LiveTradingBotGrain {GrainId}",
this.GetPrimaryKey());
return Task.FromResult(false); // Default to false on error to avoid blocking autoswap return Task.FromResult(false); // Default to false on error to avoid blocking autoswap
} }
} }
@@ -918,7 +909,8 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
if (hasOpenPositions) if (hasOpenPositions)
{ {
var openPositions = positions?.Where(p => !p.IsFinished()).ToList() ?? new List<Position>(); var openPositions = positions?.Where(p => !p.IsFinished()).ToList() ?? new List<Position>();
_logger.LogWarning("Bot {GrainId} cannot be stopped - has {Count} open positions in database: {Positions}", _logger.LogWarning(
"Bot {GrainId} cannot be stopped - has {Count} open positions in database: {Positions}",
botId, openPositions.Count, string.Join(", ", openPositions.Select(p => p.Identifier))); botId, openPositions.Count, string.Join(", ", openPositions.Select(p => p.Identifier)));
} }