diff --git a/src/Managing.Application/ManageBot/BotService.cs b/src/Managing.Application/ManageBot/BotService.cs index 0a02e09..70cdb72 100644 --- a/src/Managing.Application/ManageBot/BotService.cs +++ b/src/Managing.Application/ManageBot/BotService.cs @@ -294,18 +294,19 @@ namespace Managing.Application.ManageBot return false; } + var existingBot = await _botRepository.GetBotByIdentifierAsync(bot.Identifier); + // Check if bot already exists in database await ServiceScopeHelpers.WithScopedService( _scopeFactory, async repo => { - var existingBot = await repo.GetBotByIdentifierAsync(bot.Identifier); if (existingBot == null) { _tradingBotLogger.LogInformation("Updating existing bot statistics for bot {BotId}", bot.Identifier); // Insert new bot - await _botRepository.InsertBotAsync(bot); + await repo.InsertBotAsync(bot); _tradingBotLogger.LogInformation( "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); @@ -315,7 +316,7 @@ namespace Managing.Application.ManageBot _tradingBotLogger.LogInformation("Creating new bot statistics for bot {BotId}", bot.Identifier); // Update existing bot - await _botRepository.UpdateBot(bot); + await repo.UpdateBot(bot); _tradingBotLogger.LogDebug( "Updated 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);