Fix Get agent balance
This commit is contained in:
@@ -378,14 +378,14 @@ public class StatisticService : IStatisticService
|
||||
await _messengerService.SendBadTraders(lastBadTrader);
|
||||
}
|
||||
|
||||
public async Task<IList<AgentBalanceHistory>> GetAgentBalances(string agentName, DateTime start,
|
||||
public async Task<AgentBalanceHistory> GetAgentBalances(string agentName, DateTime start,
|
||||
DateTime? end = null)
|
||||
{
|
||||
var effectiveEnd = end ?? DateTime.UtcNow;
|
||||
string cacheKey = $"AgentBalances_{agentName}_{start:yyyyMMdd}_{effectiveEnd:yyyyMMdd}";
|
||||
|
||||
// Check if the balances are already cached
|
||||
var cachedBalances = _cacheService.GetValue<IList<AgentBalanceHistory>>(cacheKey);
|
||||
var cachedBalances = _cacheService.GetValue<AgentBalanceHistory>(cacheKey);
|
||||
|
||||
if (cachedBalances != null)
|
||||
{
|
||||
@@ -393,15 +393,12 @@ public class StatisticService : IStatisticService
|
||||
}
|
||||
|
||||
var balances = await _agentBalanceRepository.GetAgentBalances(agentName, start, end);
|
||||
|
||||
|
||||
// Create a single AgentBalanceHistory with all balances
|
||||
var result = new List<AgentBalanceHistory>
|
||||
var result = new AgentBalanceHistory
|
||||
{
|
||||
new AgentBalanceHistory
|
||||
{
|
||||
AgentName = agentName,
|
||||
AgentBalances = balances.OrderBy(b => b.Time).ToList()
|
||||
}
|
||||
AgentName = agentName,
|
||||
AgentBalances = balances.OrderBy(b => b.Time).ToList()
|
||||
};
|
||||
|
||||
// Cache the results for 5 minutes
|
||||
@@ -434,7 +431,8 @@ public class StatisticService : IStatisticService
|
||||
}
|
||||
|
||||
// Get all agents with their balance history
|
||||
var (fetchedAgents, fetchedTotalCount) = await _agentBalanceRepository.GetAllAgentBalancesWithHistory(start, end);
|
||||
var (fetchedAgents, fetchedTotalCount) =
|
||||
await _agentBalanceRepository.GetAllAgentBalancesWithHistory(start, end);
|
||||
|
||||
// Cache all results for 5 minutes
|
||||
_cacheService.SaveValue(cacheKey, (fetchedAgents, fetchedTotalCount), TimeSpan.FromMinutes(5));
|
||||
|
||||
Reference in New Issue
Block a user