From 147186724eee124482ecd37348d3aa8186ae6264 Mon Sep 17 00:00:00 2001 From: cryptooda Date: Sun, 28 Sep 2025 14:18:56 +0700 Subject: [PATCH] Rename a bit for more clarity --- src/Managing.Api/Controllers/DataController.cs | 2 +- .../Grains/PlatformSummaryGrainState.cs | 2 +- .../Grains/PlatformSummaryGrain.cs | 17 ++++++++--------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Managing.Api/Controllers/DataController.cs b/src/Managing.Api/Controllers/DataController.cs index 78b99d61..d3a6a233 100644 --- a/src/Managing.Api/Controllers/DataController.cs +++ b/src/Managing.Api/Controllers/DataController.cs @@ -785,7 +785,7 @@ public class DataController : ControllerBase TotalPlatformPnL = state.TotalPlatformPnL, TotalPlatformVolume = state.TotalPlatformVolume, OpenInterest = state.OpenInterest, - TotalPositionCount = state.TotalPositionCount, + TotalPositionCount = state.TotalLifetimePositionCount, TotalPlatformFees = state.TotalPlatformFees, // Historical snapshots diff --git a/src/Managing.Application.Abstractions/Grains/PlatformSummaryGrainState.cs b/src/Managing.Application.Abstractions/Grains/PlatformSummaryGrainState.cs index 44d1faff..905d7712 100644 --- a/src/Managing.Application.Abstractions/Grains/PlatformSummaryGrainState.cs +++ b/src/Managing.Application.Abstractions/Grains/PlatformSummaryGrainState.cs @@ -26,7 +26,7 @@ public class PlatformSummaryGrainState [Id(7)] public decimal OpenInterest { get; set; } - [Id(8)] public int TotalPositionCount { get; set; } + [Id(8)] public int TotalLifetimePositionCount { get; set; } [Id(9)] public decimal TotalPlatformFees { get; set; } diff --git a/src/Managing.Application/Grains/PlatformSummaryGrain.cs b/src/Managing.Application/Grains/PlatformSummaryGrain.cs index 8f6bd6e6..7d7a5e01 100644 --- a/src/Managing.Application/Grains/PlatformSummaryGrain.cs +++ b/src/Managing.Application/Grains/PlatformSummaryGrain.cs @@ -133,7 +133,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable _state.State.TotalPlatformPnL = totalPnL; _state.State.OpenInterest = totalOpenInterest; - _state.State.TotalPositionCount = totalPositionCount; + _state.State.TotalLifetimePositionCount = totalPositionCount; _state.State.LastUpdated = DateTime.UtcNow; _state.State.HasPendingChanges = false; @@ -223,13 +223,12 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable { // Get all open positions from all accounts // Get positions directly from database instead of exchange - var allPositions = await _tradingService.GetAllDatabasePositionsAsync(); + var allPositions = (await _tradingService.GetAllDatabasePositionsAsync()).ToList(); var openPositions = allPositions?.Where(p => !p.IsFinished()); + var totalOpenPositionCount = allPositions.Count(); - if (openPositions?.Any() == true) + if (openPositions.Any()) { - var positionCount = allPositions.Count(); - // Calculate open interest as the sum of leveraged position notional values // Open interest = sum of (position size * price * leverage) for all open positions var openInterest = openPositions @@ -237,9 +236,9 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable _logger.LogDebug( "Calculated position metrics: {PositionCount} positions, {OpenInterest} leveraged open interest", - positionCount, openInterest); + totalOpenPositionCount, openInterest); - return (openInterest, positionCount); + return (openInterest, totalOpenPositionCount); } else { @@ -354,7 +353,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable // Update open interest and position count // Since this is called only when position is fully open on broker, we always increase counts - _state.State.TotalPositionCount++; + _state.State.TotalLifetimePositionCount++; _state.State.OpenInterest += evt.Volume; // Update position count by asset @@ -414,7 +413,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable TotalVolume = _state.State.TotalPlatformVolume, TotalPnL = _state.State.TotalPlatformPnL, TotalOpenInterest = _state.State.OpenInterest, - TotalPositionCount = _state.State.TotalPositionCount, + TotalPositionCount = _state.State.TotalLifetimePositionCount, }; _state.State.DailySnapshots.Add(dailySnapshot);