Rename a bit for more clarity

This commit is contained in:
2025-09-28 14:18:56 +07:00
parent a8d09c36b7
commit 147186724e
3 changed files with 10 additions and 11 deletions

View File

@@ -785,7 +785,7 @@ public class DataController : ControllerBase
TotalPlatformPnL = state.TotalPlatformPnL, TotalPlatformPnL = state.TotalPlatformPnL,
TotalPlatformVolume = state.TotalPlatformVolume, TotalPlatformVolume = state.TotalPlatformVolume,
OpenInterest = state.OpenInterest, OpenInterest = state.OpenInterest,
TotalPositionCount = state.TotalPositionCount, TotalPositionCount = state.TotalLifetimePositionCount,
TotalPlatformFees = state.TotalPlatformFees, TotalPlatformFees = state.TotalPlatformFees,
// Historical snapshots // Historical snapshots

View File

@@ -26,7 +26,7 @@ public class PlatformSummaryGrainState
[Id(7)] public decimal OpenInterest { get; set; } [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; } [Id(9)] public decimal TotalPlatformFees { get; set; }

View File

@@ -133,7 +133,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
_state.State.TotalPlatformPnL = totalPnL; _state.State.TotalPlatformPnL = totalPnL;
_state.State.OpenInterest = totalOpenInterest; _state.State.OpenInterest = totalOpenInterest;
_state.State.TotalPositionCount = totalPositionCount; _state.State.TotalLifetimePositionCount = totalPositionCount;
_state.State.LastUpdated = DateTime.UtcNow; _state.State.LastUpdated = DateTime.UtcNow;
_state.State.HasPendingChanges = false; _state.State.HasPendingChanges = false;
@@ -223,13 +223,12 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
{ {
// Get all open positions from all accounts // Get all open positions from all accounts
// Get positions directly from database instead of exchange // 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 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 // Calculate open interest as the sum of leveraged position notional values
// Open interest = sum of (position size * price * leverage) for all open positions // Open interest = sum of (position size * price * leverage) for all open positions
var openInterest = openPositions var openInterest = openPositions
@@ -237,9 +236,9 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
_logger.LogDebug( _logger.LogDebug(
"Calculated position metrics: {PositionCount} positions, {OpenInterest} leveraged open interest", "Calculated position metrics: {PositionCount} positions, {OpenInterest} leveraged open interest",
positionCount, openInterest); totalOpenPositionCount, openInterest);
return (openInterest, positionCount); return (openInterest, totalOpenPositionCount);
} }
else else
{ {
@@ -354,7 +353,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
// Update open interest and position count // Update open interest and position count
// Since this is called only when position is fully open on broker, we always increase counts // 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; _state.State.OpenInterest += evt.Volume;
// Update position count by asset // Update position count by asset
@@ -414,7 +413,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
TotalVolume = _state.State.TotalPlatformVolume, TotalVolume = _state.State.TotalPlatformVolume,
TotalPnL = _state.State.TotalPlatformPnL, TotalPnL = _state.State.TotalPlatformPnL,
TotalOpenInterest = _state.State.OpenInterest, TotalOpenInterest = _state.State.OpenInterest,
TotalPositionCount = _state.State.TotalPositionCount, TotalPositionCount = _state.State.TotalLifetimePositionCount,
}; };
_state.State.DailySnapshots.Add(dailySnapshot); _state.State.DailySnapshots.Add(dailySnapshot);