fix concurrent

This commit is contained in:
2025-08-14 18:11:22 +07:00
parent 6a2e4e81b1
commit 0a2b7aa335

View File

@@ -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<IBotRepository>(
_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);