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; return false;
} }
var existingBot = await _botRepository.GetBotByIdentifierAsync(bot.Identifier);
// Check if bot already exists in database // Check if bot already exists in database
await ServiceScopeHelpers.WithScopedService<IBotRepository>( await ServiceScopeHelpers.WithScopedService<IBotRepository>(
_scopeFactory, _scopeFactory,
async repo => async repo =>
{ {
var existingBot = await repo.GetBotByIdentifierAsync(bot.Identifier);
if (existingBot == null) if (existingBot == null)
{ {
_tradingBotLogger.LogInformation("Updating existing bot statistics for bot {BotId}", _tradingBotLogger.LogInformation("Updating existing bot statistics for bot {BotId}",
bot.Identifier); bot.Identifier);
// Insert new bot // Insert new bot
await _botRepository.InsertBotAsync(bot); await repo.InsertBotAsync(bot);
_tradingBotLogger.LogInformation( _tradingBotLogger.LogInformation(
"Created new bot statistics for bot {BotId}: Wins={Wins}, Losses={Losses}, PnL={PnL}, ROI={ROI}%, Volume={Volume}, Fees={Fees}", "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); 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}", _tradingBotLogger.LogInformation("Creating new bot statistics for bot {BotId}",
bot.Identifier); bot.Identifier);
// Update existing bot // Update existing bot
await _botRepository.UpdateBot(bot); await repo.UpdateBot(bot);
_tradingBotLogger.LogDebug( _tradingBotLogger.LogDebug(
"Updated bot statistics for bot {BotId}: Wins={Wins}, Losses={Losses}, PnL={PnL}, ROI={ROI}%, Volume={Volume}, Fees={Fees}", "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); bot.Identifier, bot.TradeWins, bot.TradeLosses, bot.Pnl, bot.Roi, bot.Volume, bot.Fees);