Add agent fees
This commit is contained in:
@@ -76,11 +76,16 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
_state.State.DailySnapshots.Add(initialSnapshot);
|
||||
_state.State.LastSnapshot = initialSnapshot.Date;
|
||||
_state.State.LastUpdated = initialSnapshot.Date;
|
||||
|
||||
_logger.LogInformation("Created initial empty daily snapshot for {Date}", today);
|
||||
}
|
||||
|
||||
_state.State.TotalAgents = await _agentService.GetTotalAgentCount();
|
||||
|
||||
await RefreshDataAsync();
|
||||
}
|
||||
|
||||
await base.OnActivateAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<PlatformSummaryGrainState> GetPlatformSummaryAsync()
|
||||
@@ -129,7 +134,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
// Calculate fees and PnL for all positions
|
||||
totalFees += position.CalculateTotalFees();
|
||||
totalPnL += position.ProfitAndLoss?.Realized ?? 0;
|
||||
|
||||
|
||||
// Count all positions
|
||||
totalPositionCount++;
|
||||
|
||||
@@ -142,6 +147,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
{
|
||||
_state.State.VolumeByAsset[ticker] = 0;
|
||||
}
|
||||
|
||||
_state.State.VolumeByAsset[ticker] += positionVolume;
|
||||
|
||||
// Position count breakdown by asset - update state directly
|
||||
@@ -149,6 +155,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
{
|
||||
_state.State.PositionCountByAsset[ticker] = 0;
|
||||
}
|
||||
|
||||
_state.State.PositionCountByAsset[ticker]++;
|
||||
|
||||
// Position count breakdown by direction - update state directly
|
||||
@@ -156,10 +163,10 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
{
|
||||
_state.State.PositionCountByDirection[direction] = 0;
|
||||
}
|
||||
|
||||
_state.State.PositionCountByDirection[direction]++;
|
||||
}
|
||||
|
||||
_state.State.TotalAgents = await _agentService.GetTotalAgentCount();
|
||||
_state.State.TotalPlatformVolume = totalVolume;
|
||||
_state.State.TotalPlatformFees = totalFees;
|
||||
_state.State.TotalPlatformPnL = totalPnL;
|
||||
@@ -169,7 +176,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
|
||||
_logger.LogDebug(
|
||||
"Updated position breakdown from positions: {AssetCount} assets, Long={LongPositions}, Short={ShortPositions}",
|
||||
_state.State.PositionCountByAsset.Count,
|
||||
_state.State.PositionCountByAsset.Count,
|
||||
_state.State.PositionCountByDirection.GetValueOrDefault(TradeDirection.Long, 0),
|
||||
_state.State.PositionCountByDirection.GetValueOrDefault(TradeDirection.Short, 0));
|
||||
|
||||
@@ -207,6 +214,24 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
}
|
||||
}
|
||||
|
||||
public async Task IncrementAgentCountAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Incrementing agent count from {CurrentCount} to {NewCount}",
|
||||
_state.State.TotalAgents, _state.State.TotalAgents + 1);
|
||||
|
||||
_state.State.TotalAgents++;
|
||||
await _state.WriteStateAsync();
|
||||
|
||||
_logger.LogInformation("Agent count incremented to: {NewCount}", _state.State.TotalAgents);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error incrementing agent count");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task OnPositionClosedAsync(PositionClosedEvent evt)
|
||||
{
|
||||
try
|
||||
@@ -282,20 +307,6 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
await _state.WriteStateAsync();
|
||||
}
|
||||
|
||||
private async Task RefreshPnLFromDatabaseAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var totalPnL = await _tradingService.GetGlobalPnLFromPositionsAsync();
|
||||
_state.State.TotalPlatformPnL = totalPnL;
|
||||
_logger.LogDebug("Refreshed PnL from database: {TotalPnL}", totalPnL);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error refreshing PnL from database");
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsDataStale()
|
||||
{
|
||||
var timeSinceLastUpdate = DateTime.UtcNow - _state.State.LastUpdated;
|
||||
|
||||
Reference in New Issue
Block a user