Fix dailySnapshot for platformsummary

This commit is contained in:
2025-09-24 12:21:56 +07:00
parent 44846a1817
commit d2a4bd4426
11 changed files with 241 additions and 397 deletions

View File

@@ -1,5 +1,4 @@
using Managing.Api.Extensions;
using Managing.Api.Models.Requests;
using Managing.Api.Models.Requests;
using Managing.Api.Models.Responses;
using Managing.Application.Abstractions.Grains;
using Managing.Application.Abstractions.Services;
@@ -15,6 +14,7 @@ using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using static Managing.Common.Enums;
using DailySnapshot = Managing.Api.Models.Responses.DailySnapshot;
namespace Managing.Api.Controllers;
@@ -563,10 +563,10 @@ public class DataController : ControllerBase
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();
var state = await platformSummaryGrain.GetPlatformSummaryAsync();
// Convert to API ViewModel
var summary = abstractionsSummary.ToApiViewModel();
// Map the state to the view model
var summary = MapPlatformSummaryStateToViewModel(state);
return Ok(summary);
}
@@ -778,4 +778,49 @@ public class DataController : ControllerBase
return scenario;
}
/// <summary>
/// Maps PlatformSummaryGrainState to PlatformSummaryViewModel
/// </summary>
/// <param name="state">The platform summary grain state</param>
/// <returns>A mapped platform summary view model</returns>
private PlatformSummaryViewModel MapPlatformSummaryStateToViewModel(PlatformSummaryGrainState state)
{
return new PlatformSummaryViewModel
{
// Metadata
LastUpdated = state.LastUpdated,
LastSnapshot = state.LastSnapshot,
HasPendingChanges = state.HasPendingChanges,
// Current metrics
TotalAgents = state.TotalAgents,
TotalActiveStrategies = state.TotalActiveStrategies,
TotalPlatformPnL = state.TotalPlatformPnL,
TotalPlatformVolume = state.TotalPlatformVolume,
OpenInterest = state.OpenInterest,
TotalPositionCount = state.TotalPositionCount,
TotalPlatformFees = state.TotalPlatformFees,
// Historical snapshots
DailySnapshots = state.DailySnapshots
.OrderBy(s => s.Date)
.Select(s => new DailySnapshot
{
Date = s.Date,
TotalAgents = s.TotalAgents,
TotalStrategies = s.TotalStrategies,
TotalVolume = s.TotalVolume,
TotalPnL = s.TotalPnL,
TotalOpenInterest = s.TotalOpenInterest,
TotalPositionCount = s.TotalPositionCount
})
.ToList(),
// Breakdowns
VolumeByAsset = state.VolumeByAsset ?? new Dictionary<Ticker, decimal>(),
PositionCountByAsset = state.PositionCountByAsset ?? new Dictionary<Ticker, int>(),
PositionCountByDirection = state.PositionCountByDirection ?? new Dictionary<TradeDirection, int>()
};
}
}