Fix unsubscribe + reduce bot update db query

This commit is contained in:
2025-09-15 00:42:24 +07:00
parent b0d2dcc6b9
commit d2dbee9a5f
3 changed files with 27 additions and 5 deletions

View File

@@ -296,6 +296,8 @@ namespace Managing.Application.ManageBot
var existingBot = await _botRepository.GetBotByIdentifierAsync(bot.Identifier);
// Check if bot already exists in database
await ServiceScopeHelpers.WithScopedService<IBotRepository>(
_scopeFactory,
@@ -311,7 +313,13 @@ namespace Managing.Application.ManageBot
"Created new bot statistics for bot {BotId}: Wins={Wins}, Losses={Losses}, PnL={PnL}, ROI={ROI}%, Volume={Volume}, Fees={Fees}",
bot.Identifier, bot.TradeWins, bot.TradeLosses, bot.Pnl, bot.Roi, bot.Volume, bot.Fees);
}
else
else if (existingBot.Status != bot.Status
|| existingBot.Pnl != Math.Round(bot.Pnl, 8)
|| existingBot.Roi != Math.Round(bot.Roi, 8)
|| existingBot.Volume != Math.Round(bot.Volume, 8)
|| existingBot.Fees != Math.Round(bot.Fees, 8)
|| existingBot.LongPositionCount != bot.LongPositionCount
|| existingBot.ShortPositionCount != bot.ShortPositionCount)
{
_tradingBotLogger.LogInformation("Update bot statistics for bot {BotId}",
bot.Identifier);