This commit is contained in:
2025-09-24 01:19:10 +07:00
parent 40f3c66694
commit 9bdfb989c1
9 changed files with 202 additions and 419 deletions

View File

@@ -14,52 +14,54 @@ public interface IPlatformSummaryGrain : IGrainWithStringKey
/// Gets the current platform summary data
/// </summary>
Task<PlatformSummaryViewModel> GetPlatformSummaryAsync();
/// <summary>
/// Forces a refresh of all platform data
/// </summary>
Task RefreshDataAsync();
/// <summary>
/// Gets the total volume traded across all strategies
/// </summary>
Task<decimal> GetTotalVolumeAsync();
/// <summary>
/// Gets the total PnL across all strategies
/// </summary>
Task<decimal> GetTotalPnLAsync();
/// <summary>
/// Gets the total open interest across all positions
/// </summary>
Task<decimal> GetTotalOpenInterest();
/// <summary>
/// Gets the total number of open positions
/// </summary>
Task<int> GetTotalPositionCountAsync();
/// <summary>
/// Gets the total platform fees
/// </summary>
Task<decimal> GetTotalFeesAsync();
/// <summary>
/// Gets the daily volume history for the last 30 days for chart visualization
/// </summary>
Task<List<VolumeHistoryPoint>> GetVolumeHistoryAsync();
// Event handlers for immediate updates
/// <summary>
/// Updates the active strategy count
/// </summary>
[OneWay]
Task UpdateActiveStrategyCountAsync(int newActiveCount);
[OneWay]
Task OnPositionClosedAsync(PositionClosedEvent evt);
[OneWay]
Task OnTradeExecutedAsync(TradeExecutedEvent evt);
Task OnPositionOpenAsync(PositionOpenEvent evt);
}
/// <summary>
@@ -68,59 +70,36 @@ public interface IPlatformSummaryGrain : IGrainWithStringKey
[GenerateSerializer]
public abstract class PlatformMetricsEvent
{
[Id(0)]
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
[Id(0)] public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}
/// <summary>
/// Event fired when a position is closed
/// </summary>
[GenerateSerializer]
public class PositionClosedEvent : PlatformMetricsEvent
{
[Id(1)]
public Guid PositionId { get; set; }
[Id(2)]
public Ticker Ticker { get; set; }
[Id(3)]
public decimal RealizedPnL { get; set; }
[Id(4)]
public decimal Volume { get; set; }
[Id(1)] public Guid PositionIdentifier { get; set; }
[Id(2)] public Ticker Ticker { get; set; }
[Id(3)] public decimal RealizedPnL { get; set; }
[Id(4)] public decimal Volume { get; set; }
}
/// <summary>
/// Event fired when a trade is executed
/// </summary>
[GenerateSerializer]
public class TradeExecutedEvent : PlatformMetricsEvent
public class PositionOpenEvent : PlatformMetricsEvent
{
[Id(1)]
public Guid TradeId { get; set; }
[Id(2)]
public Guid PositionId { get; set; }
[Id(3)]
public Guid StrategyId { get; set; }
[Id(4)]
public Ticker Ticker { get; set; }
[Id(5)]
public decimal Volume { get; set; }
[Id(6)]
public decimal PnL { get; set; }
[Id(7)]
public decimal Fee { get; set; }
[Id(8)]
public TradeDirection Direction { get; set; }
}
[Id(1)] public Ticker Ticker { get; set; }
[Id(2)] public decimal Volume { get; set; }
[Id(3)] public decimal Fee { get; set; }
[Id(4)] public TradeDirection Direction { get; set; }
[Id(5)] public Guid PositionIdentifier { get; set; }
}

View File

@@ -9,75 +9,53 @@ namespace Managing.Application.Abstractions.Grains;
[GenerateSerializer]
public class PlatformSummaryGrainState
{
[Id(0)]
public DateTime LastUpdated { get; set; }
[Id(1)]
public DateTime LastSnapshot { get; set; }
[Id(2)]
public bool HasPendingChanges { get; set; }
// Current metrics
[Id(3)]
public int TotalAgents { get; set; }
[Id(4)]
public int TotalActiveStrategies { get; set; }
[Id(5)]
public decimal TotalPlatformPnL { get; set; }
[Id(6)]
public decimal TotalPlatformVolume { get; set; }
[Id(7)]
public decimal TotalOpenInterest { get; set; }
[Id(8)]
public int TotalPositionCount { get; set; }
[Id(20)]
public decimal TotalPlatformFees { get; set; }
// 24-hour ago values (for comparison)
[Id(9)]
public int TotalAgents24hAgo { get; set; }
[Id(10)]
public int TotalActiveStrategies24hAgo { get; set; }
[Id(11)]
public decimal TotalPlatformPnL24hAgo { get; set; }
[Id(12)]
public decimal TotalPlatformVolume24hAgo { get; set; }
[Id(13)]
public decimal TotalOpenInterest24hAgo { get; set; }
[Id(14)]
public int TotalPositionCount24hAgo { get; set; }
[Id(21)]
public decimal TotalPlatformFees24hAgo { get; set; }
// Historical snapshots
[Id(15)]
public List<DailySnapshot> DailySnapshots { get; set; } = new();
// Volume breakdown by asset
[Id(16)]
public Dictionary<Ticker, decimal> VolumeByAsset { get; set; } = new();
// Position count breakdown
[Id(17)]
public Dictionary<Ticker, int> PositionCountByAsset { get; set; } = new();
[Id(18)]
public Dictionary<TradeDirection, int> PositionCountByDirection { get; set; } = new();
}
[Id(0)] public DateTime LastUpdated { get; set; }
[Id(1)] public DateTime LastSnapshot { get; set; }
[Id(2)] public bool HasPendingChanges { get; set; }
// Current metrics
[Id(3)] public int TotalAgents { get; set; }
[Id(4)] public int TotalActiveStrategies { get; set; }
[Id(5)] public decimal TotalPlatformPnL { get; set; }
[Id(6)] public decimal TotalPlatformVolume { get; set; }
[Id(7)] public decimal OpenInterest { get; set; }
[Id(8)] public int TotalPositionCount { get; set; }
[Id(20)] public decimal TotalPlatformFees { get; set; }
// 24-hour ago values (for comparison)
[Id(9)] public int TotalAgents24hAgo { get; set; }
[Id(10)] public int TotalActiveStrategies24hAgo { get; set; }
[Id(11)] public decimal TotalPlatformPnL24hAgo { get; set; }
[Id(12)] public decimal TotalPlatformVolume24hAgo { get; set; }
[Id(13)] public decimal TotalOpenInterest24hAgo { get; set; }
[Id(14)] public int TotalPositionCount24hAgo { get; set; }
[Id(21)] public decimal TotalPlatformFees24hAgo { get; set; }
// Historical snapshots
[Id(15)] public List<DailySnapshot> DailySnapshots { get; set; } = new();
// Volume breakdown by asset
[Id(16)] public Dictionary<Ticker, decimal> VolumeByAsset { get; set; } = new();
// Position count breakdown
[Id(17)] public Dictionary<Ticker, int> PositionCountByAsset { get; set; } = new();
[Id(18)] public Dictionary<TradeDirection, int> PositionCountByDirection { get; set; } = new();
}
/// <summary>
/// Daily snapshot of platform metrics
@@ -85,29 +63,19 @@ public class PlatformSummaryGrainState
[GenerateSerializer]
public class DailySnapshot
{
[Id(0)]
public DateTime Date { get; set; }
[Id(1)]
public int TotalAgents { get; set; }
[Id(2)]
public int TotalStrategies { get; set; }
[Id(3)]
public decimal TotalVolume { get; set; }
[Id(4)]
public decimal TotalPnL { get; set; }
[Id(5)]
public decimal TotalOpenInterest { get; set; }
[Id(6)]
public int TotalPositionCount { get; set; }
[Id(7)]
public decimal TotalFees { get; set; }
}
[Id(0)] public DateTime Date { get; set; }
[Id(1)] public int TotalAgents { get; set; }
[Id(2)] public int TotalStrategies { get; set; }
[Id(3)] public decimal TotalVolume { get; set; }
[Id(4)] public decimal TotalPnL { get; set; }
[Id(5)] public decimal TotalOpenInterest { get; set; }
[Id(6)] public int TotalPositionCount { get; set; }
[Id(7)] public decimal TotalFees { get; set; }
}

View File

@@ -9,18 +9,11 @@ namespace Managing.Application.Abstractions.Models;
[GenerateSerializer]
public class AgentSummaryUpdateEvent
{
[Id(0)]
public int UserId { get; set; }
[Id(1)]
public Guid BotId { get; set; }
[Id(2)]
public AgentSummaryEventType EventType { get; set; }
[Id(3)]
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
[Id(4)]
public string? AdditionalData { get; set; } // Optional additional context
}
[Id(0)] public Guid BotId { get; set; }
[Id(1)] public AgentSummaryEventType EventType { get; set; }
[Id(2)] public DateTime Timestamp { get; set; } = DateTime.UtcNow;
[Id(3)] public string? AdditionalData { get; set; } // Optional additional context
}