Add event
This commit is contained in:
@@ -100,10 +100,10 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
_state.State.HasPendingChanges = false;
|
||||
|
||||
// Update volume breakdown by asset
|
||||
await UpdateVolumeBreakdownAsync(strategies);
|
||||
UpdateVolumeBreakdown(strategies);
|
||||
|
||||
// Update position count breakdown
|
||||
await UpdatePositionCountBreakdownAsync(strategies);
|
||||
UpdatePositionCountBreakdown(strategies);
|
||||
|
||||
await _state.WriteStateAsync();
|
||||
|
||||
@@ -115,14 +115,14 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateVolumeBreakdownAsync(IEnumerable<Bot> strategies)
|
||||
private void UpdateVolumeBreakdown(IEnumerable<Bot> strategies)
|
||||
{
|
||||
_state.State.VolumeByAsset.Clear();
|
||||
|
||||
// Group strategies by ticker and sum their volumes
|
||||
var volumeByAsset = strategies
|
||||
.Where(s => s.Volume > 0)
|
||||
.GroupBy(s => s.Ticker.ToString())
|
||||
.GroupBy(s => s.Ticker)
|
||||
.ToDictionary(g => g.Key, g => g.Sum(s => s.Volume));
|
||||
|
||||
foreach (var kvp in volumeByAsset)
|
||||
@@ -134,7 +134,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
volumeByAsset.Count, volumeByAsset.Values.Sum());
|
||||
}
|
||||
|
||||
private async Task UpdatePositionCountBreakdownAsync(IEnumerable<Bot> strategies)
|
||||
private void UpdatePositionCountBreakdown(IEnumerable<Bot> strategies)
|
||||
{
|
||||
_state.State.PositionCountByAsset.Clear();
|
||||
_state.State.PositionCountByDirection.Clear();
|
||||
@@ -146,7 +146,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
{
|
||||
// Group by asset and sum position counts per asset
|
||||
var positionsByAsset = activeStrategies
|
||||
.GroupBy(s => s.Ticker.ToString())
|
||||
.GroupBy(s => s.Ticker)
|
||||
.ToDictionary(g => g.Key, g => g.Sum(b => b.LongPositionCount + b.ShortPositionCount));
|
||||
|
||||
// Sum long and short position counts across all bots
|
||||
@@ -252,7 +252,6 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
_logger.LogInformation("Position opened: {PositionId} for {Ticker}", evt.PositionId, evt.Ticker);
|
||||
|
||||
_state.State.TotalPositionCount++;
|
||||
_state.State.TotalOpenInterest += evt.NotionalValue;
|
||||
_state.State.HasPendingChanges = true;
|
||||
await _state.WriteStateAsync();
|
||||
}
|
||||
@@ -274,6 +273,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
}
|
||||
|
||||
_state.State.VolumeByAsset[asset] += evt.Volume;
|
||||
_state.State.TotalOpenInterest -= evt.InitialVolume;
|
||||
|
||||
_state.State.HasPendingChanges = true;
|
||||
await _state.WriteStateAsync();
|
||||
@@ -285,7 +285,6 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
evt.TradeId, evt.Ticker, evt.Volume);
|
||||
|
||||
_state.State.TotalPlatformVolume += evt.Volume;
|
||||
_state.State.TotalPlatformPnL += evt.PnL;
|
||||
|
||||
// Update volume by asset
|
||||
var asset = evt.Ticker;
|
||||
@@ -402,8 +401,8 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
PositionCountChange24h = state.TotalPositionCount - state.TotalPositionCount24hAgo,
|
||||
|
||||
// Breakdowns
|
||||
VolumeByAsset = state.VolumeByAsset ?? new Dictionary<string, decimal>(),
|
||||
PositionCountByAsset = state.PositionCountByAsset ?? new Dictionary<string, int>(),
|
||||
VolumeByAsset = state.VolumeByAsset ?? new Dictionary<Ticker, decimal>(),
|
||||
PositionCountByAsset = state.PositionCountByAsset ?? new Dictionary<Ticker, int>(),
|
||||
PositionCountByDirection = state.PositionCountByDirection ?? new Dictionary<TradeDirection, int>(),
|
||||
|
||||
// Metadata
|
||||
|
||||
Reference in New Issue
Block a user