Update plateform summary

This commit is contained in:
2025-08-15 06:54:09 +07:00
parent e6c3ec139a
commit 0a4a4e1398
7 changed files with 202 additions and 103 deletions

View File

@@ -340,16 +340,6 @@ public class DataController : ControllerBase
[HttpGet("GetTopStrategies")]
public async Task<ActionResult<TopStrategiesViewModel>> GetTopStrategies()
{
const string cacheKey = "TopStrategies";
// Check if the top strategies are already cached
var cachedStrategies = _cacheService.GetValue<TopStrategiesViewModel>(cacheKey);
if (cachedStrategies != null)
{
return Ok(cachedStrategies);
}
// Get active bots
var activeBots = await _mediator.Send(new GetBotsByStatusCommand(BotStatus.Running));
@@ -372,12 +362,43 @@ public class DataController : ControllerBase
.ToList()
};
// Cache the result for 10 minutes
_cacheService.SaveValue(cacheKey, topStrategies, TimeSpan.FromMinutes(10));
return Ok(topStrategies);
}
/// <summary>
/// Retrieves the top 3 performing strategies based on ROI percentage.
/// </summary>
/// <returns>A <see cref="TopStrategiesByRoiViewModel"/> containing the top performing strategies by ROI.</returns>
[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();
// Map to view model
var topStrategiesByRoi = new TopStrategiesByRoiViewModel
{
TopStrategiesByRoi = botsWithRoi
.Select(item => new StrategyRoiPerformance
{
StrategyName = item.Bot.Name,
Roi = item.Roi,
PnL = item.PnL,
Volume = item.Volume
})
.ToList()
};
return Ok(topStrategiesByRoi);
}
/// <summary>
/// Retrieves list of the active strategies for a user with detailed information
/// </summary>
@@ -474,13 +495,13 @@ public class DataController : ControllerBase
{
// Get the platform summary grain
var platformSummaryGrain = _grainFactory.GetGrain<IPlatformSummaryGrain>("platform-summary");
// Get the platform summary from the grain (handles caching and real-time updates)
var abstractionsSummary = await platformSummaryGrain.GetPlatformSummaryAsync();
// Convert to API ViewModel
var summary = abstractionsSummary.ToApiViewModel();
return Ok(summary);
}
catch (Exception ex)

View File

@@ -1,4 +1,5 @@
using Managing.Api.Models.Responses;
using Managing.Common;
using AbstractionsPlatformSummaryViewModel = Managing.Application.Abstractions.Models.PlatformSummaryViewModel;
namespace Managing.Api.Extensions;
@@ -28,13 +29,13 @@ public static class PlatformSummaryExtensions
VolumeChange24h = abstractionsModel.VolumeChange24h,
OpenInterestChange24h = abstractionsModel.OpenInterestChange24h,
PositionCountChange24h = abstractionsModel.PositionCountChange24h,
VolumeByAsset = abstractionsModel.VolumeByAsset ?? new Dictionary<string, decimal>(),
PositionCountByAsset = abstractionsModel.PositionCountByAsset ?? new Dictionary<string, int>(),
VolumeByAsset = abstractionsModel.VolumeByAsset ?? new Dictionary<Enums.Ticker, decimal>(),
PositionCountByAsset = abstractionsModel.PositionCountByAsset ?? new Dictionary<Enums.Ticker, int>(),
PositionCountByDirection = abstractionsModel.PositionCountByDirection?.ToDictionary(
kvp => kvp.Key.ToString(),
kvp => kvp.Value) ?? new Dictionary<string, int>(),
kvp => kvp.Key,
kvp => kvp.Value) ?? new Dictionary<Enums.TradeDirection, int>(),
LastUpdated = abstractionsModel.LastUpdated,
Last24HourSnapshot = abstractionsModel.Last24HourSnapshot
};
}
}
}

View File

@@ -1,3 +1,5 @@
using Managing.Common;
namespace Managing.Api.Models.Responses
{
/// <summary>
@@ -9,39 +11,39 @@ namespace Managing.Api.Models.Responses
/// AgentName of the agent
/// </summary>
public string AgentName { get; set; }
/// <summary>
/// Total profit and loss in USD
/// </summary>
public decimal TotalPnL { get; set; }
/// <summary>
/// Total return on investment as a percentage
/// </summary>
public decimal TotalROI { get; set; }
/// <summary>
/// Number of winning trades
/// </summary>
public int Wins { get; set; }
/// <summary>
/// Number of losing trades
/// </summary>
public int Losses { get; set; }
/// <summary>
/// Number of active strategies for this agent
/// </summary>
public int ActiveStrategiesCount { get; set; }
/// <summary>
/// Total volume traded by this agent in USD
/// </summary>
public decimal TotalVolume { get; set; }
}
/// <summary>
/// Platform-wide statistics without individual agent details
/// </summary>
@@ -51,96 +53,96 @@ namespace Managing.Api.Models.Responses
/// Total number of agents on the platform
/// </summary>
public required int TotalAgents { get; set; }
/// <summary>
/// Total number of active strategies across all agents
/// </summary>
public required int TotalActiveStrategies { get; set; }
/// <summary>
/// Total platform-wide profit and loss in USD
/// </summary>
public required decimal TotalPlatformPnL { get; set; }
/// <summary>
/// Total volume traded across all agents in USD
/// </summary>
public required decimal TotalPlatformVolume { get; set; }
/// <summary>
/// Total volume traded across all agents in the last 24 hours in USD
/// </summary>
public required decimal TotalPlatformVolumeLast24h { get; set; }
/// <summary>
/// Total open interest across all positions in USD
/// </summary>
public required decimal TotalOpenInterest { get; set; }
/// <summary>
/// Total number of open positions across all strategies
/// </summary>
public required int TotalPositionCount { get; set; }
// 24-hour changes
/// <summary>
/// Change in agent count over the last 24 hours
/// </summary>
public required int AgentsChange24h { get; set; }
/// <summary>
/// Change in strategy count over the last 24 hours
/// </summary>
public required int StrategiesChange24h { get; set; }
/// <summary>
/// Change in PnL over the last 24 hours
/// </summary>
public required decimal PnLChange24h { get; set; }
/// <summary>
/// Change in volume over the last 24 hours
/// </summary>
public required decimal VolumeChange24h { get; set; }
/// <summary>
/// Change in open interest over the last 24 hours
/// </summary>
public required decimal OpenInterestChange24h { get; set; }
/// <summary>
/// Change in position count over the last 24 hours
/// </summary>
public required int PositionCountChange24h { get; set; }
// Breakdowns
/// <summary>
/// Volume breakdown by asset/ticker
/// </summary>
public required Dictionary<string, decimal> VolumeByAsset { get; set; }
public required Dictionary<Enums.Ticker, decimal> VolumeByAsset { get; set; }
/// <summary>
/// Position count breakdown by asset/ticker
/// </summary>
public required Dictionary<string, int> PositionCountByAsset { get; set; }
public required Dictionary<Enums.Ticker, int> PositionCountByAsset { get; set; }
/// <summary>
/// Position count breakdown by direction (Long/Short)
/// </summary>
public required Dictionary<string, int> PositionCountByDirection { get; set; }
public required Dictionary<Enums.TradeDirection, int> PositionCountByDirection { get; set; }
// Metadata
/// <summary>
/// When the data was last updated
/// </summary>
public required DateTime LastUpdated { get; set; }
/// <summary>
/// When the last 24-hour snapshot was taken
/// </summary>
public required DateTime Last24HourSnapshot { get; set; }
}
/// <summary>
/// Response model containing a list of agent summaries for the agent index
/// </summary>
@@ -150,10 +152,10 @@ namespace Managing.Api.Models.Responses
/// List of agent summaries sorted by performance
/// </summary>
public List<AgentSummaryViewModel> AgentSummaries { get; set; } = new List<AgentSummaryViewModel>();
/// <summary>
/// Time filter applied to the data
/// </summary>
public string TimeFilter { get; set; } = "Total";
}
}
}

View File

@@ -16,6 +16,32 @@ namespace Managing.Api.Models.Responses
public decimal PnL { get; set; }
}
/// <summary>
/// Represents a high-performing strategy with its name and ROI value
/// </summary>
public class StrategyRoiPerformance
{
/// <summary>
/// Name of the strategy bot
/// </summary>
public string StrategyName { get; set; }
/// <summary>
/// Return on Investment percentage of the strategy
/// </summary>
public decimal Roi { get; set; }
/// <summary>
/// Profit and Loss value of the strategy
/// </summary>
public decimal PnL { get; set; }
/// <summary>
/// Volume traded by the strategy
/// </summary>
public decimal Volume { get; set; }
}
/// <summary>
/// View model containing the top performing strategies by ROI
/// </summary>
@@ -26,4 +52,15 @@ namespace Managing.Api.Models.Responses
/// </summary>
public List<StrategyPerformance> TopStrategies { get; set; } = new List<StrategyPerformance>();
}
/// <summary>
/// View model containing the top performing strategies by ROI
/// </summary>
public class TopStrategiesByRoiViewModel
{
/// <summary>
/// List of the top performing strategies by ROI
/// </summary>
public List<StrategyRoiPerformance> TopStrategiesByRoi { get; set; } = new List<StrategyRoiPerformance>();
}
}