diff --git a/src/Managing.Api/Controllers/DataController.cs b/src/Managing.Api/Controllers/DataController.cs index a6bfcca9..7f207ca3 100644 --- a/src/Managing.Api/Controllers/DataController.cs +++ b/src/Managing.Api/Controllers/DataController.cs @@ -461,8 +461,13 @@ public class DataController : ControllerBase var positionsByIdentifier = allPositions.GroupBy(p => p.InitiatorIdentifier) .ToDictionary(g => g.Key, g => g.ToList()); + // Get agent balance history for the last 30 days + var startDate = DateTime.UtcNow.AddDays(-30); + var endDate = DateTime.UtcNow; + var agentBalanceHistory = await _agentService.GetAgentBalances(agentName, startDate, endDate); + // Convert to detailed view model with additional information - var result = userStrategies.Select(strategy => MapStrategyToViewModel(strategy, positionsByIdentifier)) + var result = userStrategies.Select(strategy => MapStrategyToViewModel(strategy, positionsByIdentifier, agentBalanceHistory)) .ToList(); return Ok(result); @@ -495,8 +500,13 @@ public class DataController : ControllerBase return NotFound($"Strategy '{strategyName}' not found for user '{agentName}'"); } + // Get agent balance history for the last 30 days + var startDate = DateTime.UtcNow.AddDays(-30); + var endDate = DateTime.UtcNow; + var agentBalanceHistory = await _agentService.GetAgentBalances(agentName, startDate, endDate); + // Map the strategy to a view model using the shared method - var result = await MapStrategyToViewModelAsync(strategy); + var result = await MapStrategyToViewModelAsync(strategy, agentBalanceHistory); return Ok(result); } @@ -506,9 +516,10 @@ public class DataController : ControllerBase /// /// The trading bot to map /// Pre-fetched positions grouped by initiator identifier + /// Agent balance history data /// A view model with detailed strategy information private UserStrategyDetailsViewModel MapStrategyToViewModel(Bot strategy, - Dictionary> positionsByIdentifier) + Dictionary> positionsByIdentifier, AgentBalanceHistory agentBalanceHistory) { // Calculate ROI percentage based on PnL relative to account value decimal pnl = strategy.Pnl; @@ -533,6 +544,10 @@ public class DataController : ControllerBase ? strategyPositions : new List(); + // Convert agent balance history to wallet balances dictionary + var walletBalances = agentBalanceHistory?.AgentBalances? + .ToDictionary(b => b.Time, b => b.TotalValue) ?? new Dictionary(); + return new UserStrategyDetailsViewModel { Name = strategy.Name, @@ -548,7 +563,7 @@ public class DataController : ControllerBase Losses = losses, Positions = positions, Identifier = strategy.Identifier, - WalletBalances = new Dictionary(), + WalletBalances = walletBalances, Ticker = strategy.Ticker }; } @@ -557,8 +572,9 @@ public class DataController : ControllerBase /// Maps a trading bot to a strategy view model with detailed statistics /// /// The trading bot to map + /// Agent balance history data /// A view model with detailed strategy information - private async Task MapStrategyToViewModelAsync(Bot strategy) + private async Task MapStrategyToViewModelAsync(Bot strategy, AgentBalanceHistory agentBalanceHistory) { // Calculate ROI percentage based on PnL relative to account value decimal pnl = strategy.Pnl; @@ -581,6 +597,10 @@ public class DataController : ControllerBase // Fetch positions associated with this bot var positions = await _tradingService.GetPositionsByInitiatorIdentifierAsync(strategy.Identifier); + // Convert agent balance history to wallet balances dictionary + var walletBalances = agentBalanceHistory?.AgentBalances? + .ToDictionary(b => b.Time, b => b.TotalValue) ?? new Dictionary(); + return new UserStrategyDetailsViewModel { Name = strategy.Name, @@ -596,7 +616,8 @@ public class DataController : ControllerBase Losses = losses, Positions = positions.ToList(), Identifier = strategy.Identifier, - WalletBalances = new Dictionary(), + WalletBalances = walletBalances, + Ticker = strategy.Ticker }; }