Clean and update event
This commit is contained in:
@@ -71,13 +71,13 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
TotalOpenInterest = 0,
|
||||
TotalPositionCount = 0,
|
||||
};
|
||||
|
||||
|
||||
_state.State.DailySnapshots.Add(initialSnapshot);
|
||||
_state.State.LastSnapshot = today;
|
||||
_state.State.LastUpdated = today;
|
||||
_logger.LogInformation("Created initial empty daily snapshot for {Date}", today);
|
||||
}
|
||||
|
||||
|
||||
await RefreshDataAsync();
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
|
||||
// Calculate volume from strategies
|
||||
var totalVolume = strategies.Sum(s => s.Volume);
|
||||
|
||||
|
||||
// Calculate PnL directly from database positions (closed positions only)
|
||||
var totalPnL = await _tradingService.GetGlobalPnLFromPositionsAsync();
|
||||
|
||||
@@ -118,7 +118,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
// Update state
|
||||
_state.State.TotalAgents = totalAgents;
|
||||
_state.State.TotalActiveStrategies = totalActiveStrategies;
|
||||
|
||||
|
||||
// Only update volume if it hasn't been updated by events recently
|
||||
// This preserves real-time volume updates from position events
|
||||
if (!_state.State.VolumeUpdatedByEvents)
|
||||
@@ -130,7 +130,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
{
|
||||
_logger.LogDebug("Preserving event-updated volume: {Volume}", _state.State.TotalPlatformVolume);
|
||||
}
|
||||
|
||||
|
||||
_state.State.TotalPlatformPnL = totalPnL;
|
||||
_state.State.OpenInterest = totalOpenInterest;
|
||||
_state.State.TotalPositionCount = totalPositionCount;
|
||||
@@ -254,31 +254,6 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
}
|
||||
}
|
||||
|
||||
public Task<decimal> GetTotalVolumeAsync()
|
||||
{
|
||||
return Task.FromResult(_state.State.TotalPlatformVolume);
|
||||
}
|
||||
|
||||
public Task<decimal> GetTotalPnLAsync()
|
||||
{
|
||||
return Task.FromResult(_state.State.TotalPlatformPnL);
|
||||
}
|
||||
|
||||
public Task<decimal> GetTotalOpenInterest()
|
||||
{
|
||||
return Task.FromResult(_state.State.OpenInterest);
|
||||
}
|
||||
|
||||
public Task<int> GetTotalPositionCountAsync()
|
||||
{
|
||||
return Task.FromResult(_state.State.TotalPositionCount);
|
||||
}
|
||||
|
||||
public Task<decimal> GetTotalFeesAsync()
|
||||
{
|
||||
return Task.FromResult(_state.State.TotalPlatformFees);
|
||||
}
|
||||
|
||||
// Event handlers for immediate updates
|
||||
public async Task UpdateActiveStrategyCountAsync(int newActiveCount)
|
||||
{
|
||||
@@ -303,7 +278,6 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task OnPositionClosedAsync(PositionClosedEvent evt)
|
||||
{
|
||||
try
|
||||
@@ -319,7 +293,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
}
|
||||
|
||||
_state.State.TotalPlatformVolume += evt.Volume;
|
||||
|
||||
|
||||
// PnL is now calculated directly from database positions, not from events
|
||||
// This ensures accuracy and prevents double-counting issues
|
||||
// Refresh PnL from database to get the latest accurate value
|
||||
@@ -427,7 +401,6 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task TakeDailySnapshotAsync()
|
||||
{
|
||||
_logger.LogInformation("Taking daily snapshot");
|
||||
|
||||
Reference in New Issue
Block a user