Fix bot TOP 3
This commit is contained in:
@@ -329,31 +329,24 @@ public class DataController : ControllerBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the top 3 performing strategies based on ROI.
|
||||
/// Retrieves the top 3 performing strategies based on PnL.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="TopStrategiesViewModel"/> containing the top performing strategies.</returns>
|
||||
[HttpGet("GetTopStrategies")]
|
||||
public async Task<ActionResult<TopStrategiesViewModel>> GetTopStrategies()
|
||||
{
|
||||
// Get active bots
|
||||
var activeBots = await _mediator.Send(new GetBotsByStatusCommand(BotStatus.Running));
|
||||
|
||||
// Calculate PnL for each bot once and store in a list of tuples
|
||||
var botsWithPnL = activeBots
|
||||
.Select(bot => new { Bot = bot, PnL = bot.Pnl, agentName = bot.User.AgentName })
|
||||
.OrderByDescending(item => item.PnL)
|
||||
.Take(3)
|
||||
.ToList();
|
||||
// Get top 3 bots by PnL directly from database (both running and stopped)
|
||||
var bots = await _mediator.Send(new GetTopBotsByPnLCommand(new[] { BotStatus.Running, BotStatus.Stopped }, 3));
|
||||
|
||||
// Map to view model
|
||||
var topStrategies = new TopStrategiesViewModel
|
||||
{
|
||||
TopStrategies = botsWithPnL
|
||||
.Select(item => new StrategyPerformance
|
||||
TopStrategies = bots
|
||||
.Select(bot => new StrategyPerformance
|
||||
{
|
||||
StrategyName = item.Bot.Name,
|
||||
PnL = item.PnL,
|
||||
AgentName = item.agentName,
|
||||
StrategyName = bot.Name,
|
||||
PnL = bot.Pnl,
|
||||
AgentName = bot.User.AgentName,
|
||||
})
|
||||
.ToList()
|
||||
};
|
||||
@@ -368,26 +361,19 @@ public class DataController : ControllerBase
|
||||
[HttpGet("GetTopStrategiesByRoi")]
|
||||
public async Task<ActionResult<TopStrategiesByRoiViewModel>> GetTopStrategiesByRoi()
|
||||
{
|
||||
// Get active bots
|
||||
var activeBots = await _mediator.Send(new GetBotsByStatusCommand(BotStatus.Running));
|
||||
|
||||
// Filter bots with valid ROI data and order by ROI
|
||||
var botsWithRoi = activeBots
|
||||
.Select(bot => new { Bot = bot, Roi = bot.Roi, PnL = bot.Pnl, Volume = bot.Volume })
|
||||
.OrderByDescending(item => item.Roi)
|
||||
.Take(3)
|
||||
.ToList();
|
||||
// Get top 3 bots by ROI directly from database (both running and stopped)
|
||||
var bots = await _mediator.Send(new GetTopBotsByRoiCommand(new[] { BotStatus.Running, BotStatus.Stopped }, 3));
|
||||
|
||||
// Map to view model
|
||||
var topStrategiesByRoi = new TopStrategiesByRoiViewModel
|
||||
{
|
||||
TopStrategiesByRoi = botsWithRoi
|
||||
.Select(item => new StrategyRoiPerformance
|
||||
TopStrategiesByRoi = bots
|
||||
.Select(bot => new StrategyRoiPerformance
|
||||
{
|
||||
StrategyName = item.Bot.Name,
|
||||
Roi = item.Roi,
|
||||
PnL = item.PnL,
|
||||
Volume = item.Volume
|
||||
StrategyName = bot.Name,
|
||||
Roi = bot.Roi,
|
||||
PnL = bot.Pnl,
|
||||
Volume = bot.Volume
|
||||
})
|
||||
.ToList()
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user