Fix dailySnapshot for platformsummary
This commit is contained in:
@@ -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>()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
using Managing.Api.Models.Responses;
|
||||
using Managing.Common;
|
||||
using AbstractionsPlatformSummaryViewModel = Managing.Application.Abstractions.Models.PlatformSummaryViewModel;
|
||||
|
||||
namespace Managing.Api.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting between Platform Summary ViewModels
|
||||
/// </summary>
|
||||
public static class PlatformSummaryExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts from the Abstractions PlatformSummaryViewModel to the API PlatformSummaryViewModel
|
||||
/// </summary>
|
||||
public static PlatformSummaryViewModel ToApiViewModel(this AbstractionsPlatformSummaryViewModel abstractionsModel)
|
||||
{
|
||||
return new PlatformSummaryViewModel
|
||||
{
|
||||
TotalAgents = abstractionsModel.TotalAgents,
|
||||
TotalActiveStrategies = abstractionsModel.TotalActiveStrategies,
|
||||
TotalPlatformPnL = abstractionsModel.TotalPlatformPnL,
|
||||
TotalPlatformVolume = abstractionsModel.TotalPlatformVolume,
|
||||
TotalPlatformVolumeLast24h = abstractionsModel.TotalPlatformVolumeLast24h,
|
||||
TotalOpenInterest = abstractionsModel.TotalOpenInterest,
|
||||
TotalPositionCount = abstractionsModel.TotalPositionCount,
|
||||
AgentsChange24h = abstractionsModel.AgentsChange24h,
|
||||
StrategiesChange24h = abstractionsModel.StrategiesChange24h,
|
||||
PnLChange24h = abstractionsModel.PnLChange24h,
|
||||
VolumeChange24h = abstractionsModel.VolumeChange24h,
|
||||
OpenInterestChange24h = abstractionsModel.OpenInterestChange24h,
|
||||
PositionCountChange24h = abstractionsModel.PositionCountChange24h,
|
||||
VolumeByAsset = abstractionsModel.VolumeByAsset ?? new Dictionary<Enums.Ticker, decimal>(),
|
||||
PositionCountByAsset = abstractionsModel.PositionCountByAsset ?? new Dictionary<Enums.Ticker, int>(),
|
||||
PositionCountByDirection = abstractionsModel.PositionCountByDirection?.ToDictionary(
|
||||
kvp => kvp.Key,
|
||||
kvp => kvp.Value) ?? new Dictionary<Enums.TradeDirection, int>(),
|
||||
LastUpdated = abstractionsModel.LastUpdated,
|
||||
Last24HourSnapshot = abstractionsModel.Last24HourSnapshot,
|
||||
VolumeHistory = abstractionsModel.VolumeHistory,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -59,4 +59,8 @@
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Extensions\"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Managing.Application.Abstractions.Models;
|
||||
using Managing.Common;
|
||||
|
||||
namespace Managing.Api.Models.Responses
|
||||
@@ -55,6 +54,22 @@ namespace Managing.Api.Models.Responses
|
||||
/// </summary>
|
||||
public class PlatformSummaryViewModel
|
||||
{
|
||||
/// <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 LastSnapshot { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether there are pending changes to be saved
|
||||
/// </summary>
|
||||
public required bool HasPendingChanges { get; set; }
|
||||
|
||||
// Current metrics
|
||||
/// <summary>
|
||||
/// Total number of agents on the platform
|
||||
/// </summary>
|
||||
@@ -75,58 +90,34 @@ namespace Managing.Api.Models.Responses
|
||||
/// </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; }
|
||||
public required decimal OpenInterest { 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
|
||||
/// Total platform-wide fees paid in USD
|
||||
/// </summary>
|
||||
public required int AgentsChange24h { get; set; }
|
||||
public required decimal TotalPlatformFees { get; set; }
|
||||
|
||||
// Historical snapshots
|
||||
/// <summary>
|
||||
/// Change in strategy count over the last 24 hours
|
||||
/// Daily snapshots for the last 60 days
|
||||
/// </summary>
|
||||
public required int StrategiesChange24h { get; set; }
|
||||
public required List<DailySnapshot> DailySnapshots { 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
|
||||
// Volume breakdown by asset
|
||||
/// <summary>
|
||||
/// Volume breakdown by asset/ticker
|
||||
/// </summary>
|
||||
public required Dictionary<Enums.Ticker, decimal> VolumeByAsset { get; set; }
|
||||
|
||||
// Position count breakdown
|
||||
/// <summary>
|
||||
/// Position count breakdown by asset/ticker
|
||||
/// </summary>
|
||||
@@ -136,18 +127,47 @@ namespace Managing.Api.Models.Responses
|
||||
/// Position count breakdown by direction (Long/Short)
|
||||
/// </summary>
|
||||
public required Dictionary<Enums.TradeDirection, int> PositionCountByDirection { get; set; }
|
||||
}
|
||||
|
||||
// Metadata
|
||||
/// <summary>
|
||||
/// Daily snapshot of platform metrics
|
||||
/// </summary>
|
||||
public class DailySnapshot
|
||||
{
|
||||
/// <summary>
|
||||
/// When the data was last updated
|
||||
/// Date of the snapshot
|
||||
/// </summary>
|
||||
public required DateTime LastUpdated { get; set; }
|
||||
public required DateTime Date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When the last 24-hour snapshot was taken
|
||||
/// Total number of agents on this date
|
||||
/// </summary>
|
||||
public required DateTime Last24HourSnapshot { get; set; }
|
||||
public List<VolumeHistoryPoint> VolumeHistory { get; internal set; }
|
||||
public required int TotalAgents { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total number of active strategies on this date
|
||||
/// </summary>
|
||||
public required int TotalStrategies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total volume traded on this date in USD
|
||||
/// </summary>
|
||||
public required decimal TotalVolume { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total PnL on this date in USD
|
||||
/// </summary>
|
||||
public required decimal TotalPnL { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total open interest on this date in USD
|
||||
/// </summary>
|
||||
public required decimal TotalOpenInterest { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total number of positions on this date
|
||||
/// </summary>
|
||||
public required int TotalPositionCount { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user