Add best agent by pnl
This commit is contained in:
@@ -400,6 +400,49 @@ public class DataController : ControllerBase
|
||||
return Ok(topStrategiesByRoi);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the top 3 performing agents based on PnL.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="TopAgentsByPnLViewModel"/> containing the top performing agents by PnL.</returns>
|
||||
[HttpGet("GetTopAgentsByPnL")]
|
||||
public async Task<ActionResult<TopAgentsByPnLViewModel>> GetTopAgentsByPnL()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get all agent summaries
|
||||
var allAgentSummaries = await _mediator.Send(new GetAllAgentSummariesCommand("Total"));
|
||||
|
||||
// Filter agents with valid PnL data and order by PnL
|
||||
var agentsWithPnL = allAgentSummaries
|
||||
.Where(agent => agent.TotalPnL != 0) // Only include agents with actual PnL
|
||||
.OrderByDescending(agent => agent.TotalPnL)
|
||||
.Take(3)
|
||||
.ToList();
|
||||
|
||||
// Map to view model
|
||||
var topAgentsByPnL = new TopAgentsByPnLViewModel
|
||||
{
|
||||
TopAgentsByPnL = agentsWithPnL
|
||||
.Select(agent => new AgentPerformance
|
||||
{
|
||||
AgentName = agent.AgentName,
|
||||
PnL = agent.TotalPnL,
|
||||
TotalROI = agent.TotalROI,
|
||||
TotalVolume = agent.TotalVolume,
|
||||
ActiveStrategiesCount = agent.ActiveStrategiesCount,
|
||||
TotalBalance = agent.TotalBalance
|
||||
})
|
||||
.ToList()
|
||||
};
|
||||
|
||||
return Ok(topAgentsByPnL);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error retrieving top agents by PnL: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves list of the active strategies for a user with detailed information
|
||||
/// </summary>
|
||||
|
||||
@@ -65,4 +65,51 @@ namespace Managing.Api.Models.Responses
|
||||
/// </summary>
|
||||
public List<StrategyRoiPerformance> TopStrategiesByRoi { get; set; } = new List<StrategyRoiPerformance>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a high-performing agent with its name and PnL value
|
||||
/// </summary>
|
||||
public class AgentPerformance
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the agent
|
||||
/// </summary>
|
||||
public string AgentName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Profit and Loss value of the agent
|
||||
/// </summary>
|
||||
public decimal PnL { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total ROI percentage of the agent
|
||||
/// </summary>
|
||||
public decimal TotalROI { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total volume traded by the agent
|
||||
/// </summary>
|
||||
public decimal TotalVolume { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of active strategies for this agent
|
||||
/// </summary>
|
||||
public int ActiveStrategiesCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total balance including USDC and open position values
|
||||
/// </summary>
|
||||
public decimal TotalBalance { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// View model containing the top performing agents by PnL
|
||||
/// </summary>
|
||||
public class TopAgentsByPnLViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// List of the top performing agents by PnL
|
||||
/// </summary>
|
||||
public List<AgentPerformance> TopAgentsByPnL { get; set; } = new List<AgentPerformance>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user