Update cache for userStrategy details

This commit is contained in:
2025-08-14 17:42:07 +07:00
parent 9d0c7cf834
commit aacb92018f
5 changed files with 390 additions and 35 deletions

View File

@@ -295,24 +295,32 @@ namespace Managing.Application.ManageBot
}
// Check if bot already exists in database
var existingBot = await _botRepository.GetBotByIdentifierAsync(bot.Identifier);
if (existingBot != null)
{
// Update existing bot
await _botRepository.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);
}
else
{
// Insert new bot
await _botRepository.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);
}
await ServiceScopeHelpers.WithScopedService<IBotRepository>(
_scopeFactory,
async repo =>
{
var existingBot = await repo.GetBotByIdentifierAsync(bot.Identifier);
if (existingBot == null)
{
_tradingBotLogger.LogInformation("Creating new bot statistics for bot {BotId}",
bot.Identifier);
// Update existing bot
await _botRepository.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);
}
else
{
_tradingBotLogger.LogInformation("Updating existing bot statistics for bot {BotId}",
bot.Identifier);
// Insert new bot
await _botRepository.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);
}
});
return true;
}