Fix update agent Summary when new balance fetch

This commit is contained in:
2025-10-11 13:10:47 +07:00
parent 04df72a6bd
commit b6a4c7661f
5 changed files with 116 additions and 4 deletions

View File

@@ -1,13 +1,12 @@
using Managing.Application.Abstractions;
using Managing.Application.Abstractions.Repositories;
using Managing.Application.Abstractions.Services;
using Managing.Application.Abstractions;
using Managing.Core;
using Managing.Domain.Accounts;
using Managing.Domain.Bots;
using Managing.Domain.Statistics;
using Managing.Domain.Trades;
using Managing.Domain.Users;
using Managing.Domain.Accounts;
using Managing.Domain.Bots;
using Managing.Domain.Shared.Helpers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using static Managing.Common.Enums;
@@ -95,6 +94,9 @@ public class AgentService : IAgentService
// Insert the fresh balance data into InfluxDB
_agentBalanceRepository.InsertAgentBalance(freshBalance);
// Update the AgentSummary TotalBalance with the fresh balance data
await UpdateAgentSummaryTotalBalanceAsync(userId, freshBalance.TotalBalanceValue);
// Add the fresh balance to our results if it falls within the requested time range
if (freshBalance.Time >= start && freshBalance.Time <= effectiveEnd)
{
@@ -186,6 +188,21 @@ public class AgentService : IAgentService
}
}
public async Task UpdateAgentSummaryTotalBalanceAsync(int userId, decimal totalBalance)
{
try
{
await _agentSummaryRepository.UpdateTotalBalanceAsync(userId, totalBalance);
_logger.LogInformation("Total balance updated for user {UserId} to {TotalBalance}", userId, totalBalance);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error updating total balance for user {UserId} to {TotalBalance}", userId, totalBalance);
throw;
}
}
/// <summary>
/// Determines if fresh balance data should be calculated based on the last balance timestamp
/// </summary>

View File

@@ -1969,6 +1969,7 @@ public class TradingBotBase : ITradingBot
// Add the signal to our collection
await AddSignal(signal);
await ManagePositions();
return signal;
}