update stats data
This commit is contained in:
@@ -65,8 +65,8 @@ public class LiveBotRegistryGrain : Grain, ILiveBotRegistryGrain
|
||||
"Bot {Identifier} registered successfully for user {UserId}. Total bots: {TotalBots}, Active bots: {ActiveBots}",
|
||||
identifier, userId, _state.State.TotalBotsCount, _state.State.ActiveBotsCount);
|
||||
|
||||
// Notify platform summary grain about strategy deployment
|
||||
await NotifyStrategyDeployedAsync(identifier, userId);
|
||||
// Notify platform summary grain about strategy count change
|
||||
await NotifyPlatformSummaryAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -102,8 +102,8 @@ public class LiveBotRegistryGrain : Grain, ILiveBotRegistryGrain
|
||||
"Bot {Identifier} unregistered successfully from user {UserId}. Total bots: {TotalBots}",
|
||||
identifier, entryToRemove.UserId, _state.State.TotalBotsCount);
|
||||
|
||||
// Notify platform summary grain about strategy stopped
|
||||
await NotifyStrategyStoppedAsync(identifier, entryToRemove.UserId);
|
||||
// Notify platform summary grain about strategy count change
|
||||
await NotifyPlatformSummaryAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -187,65 +187,19 @@ public class LiveBotRegistryGrain : Grain, ILiveBotRegistryGrain
|
||||
return Task.FromResult(entry.Status);
|
||||
}
|
||||
|
||||
private async Task NotifyStrategyDeployedAsync(Guid identifier, int userId)
|
||||
private async Task NotifyPlatformSummaryAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get bot details for the event
|
||||
var bot = await _botService.GetBotByIdentifier(identifier);
|
||||
if (bot != null)
|
||||
{
|
||||
var platformGrain = GrainFactory.GetGrain<IPlatformSummaryGrain>("platform-summary");
|
||||
|
||||
var deployedEvent = new StrategyDeployedEvent
|
||||
{
|
||||
StrategyId = identifier,
|
||||
AgentName = bot.User.AgentName,
|
||||
StrategyName = bot.Name
|
||||
};
|
||||
|
||||
await platformGrain.OnStrategyDeployedAsync(deployedEvent);
|
||||
_logger.LogDebug("Notified platform summary about strategy deployment: {StrategyName}", bot.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Could not find bot {Identifier} to notify platform summary", identifier);
|
||||
}
|
||||
var platformGrain = GrainFactory.GetGrain<IPlatformSummaryGrain>("platform-summary");
|
||||
await platformGrain.UpdateActiveStrategyCountAsync(_state.State.ActiveBotsCount);
|
||||
|
||||
_logger.LogDebug("Notified platform summary about active strategy count change. New count: {ActiveCount}",
|
||||
_state.State.ActiveBotsCount);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to notify platform summary about strategy deployment for bot {Identifier}", identifier);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task NotifyStrategyStoppedAsync(Guid identifier, int userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get bot details for the event
|
||||
var bot = await _botService.GetBotByIdentifier(identifier);
|
||||
if (bot != null)
|
||||
{
|
||||
var platformGrain = GrainFactory.GetGrain<IPlatformSummaryGrain>("platform-summary");
|
||||
|
||||
var stoppedEvent = new StrategyStoppedEvent
|
||||
{
|
||||
StrategyId = identifier,
|
||||
AgentName = bot.User?.Name ?? $"User-{userId}",
|
||||
StrategyName = bot.Name
|
||||
};
|
||||
|
||||
await platformGrain.OnStrategyStoppedAsync(stoppedEvent);
|
||||
_logger.LogDebug("Notified platform summary about strategy stopped: {StrategyName}", bot.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Could not find bot {Identifier} to notify platform summary", identifier);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to notify platform summary about strategy stopped for bot {Identifier}", identifier);
|
||||
_logger.LogError(ex, "Failed to notify platform summary about strategy count change");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,7 +190,8 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
var openInterest = openPositions
|
||||
.Sum(p => (p.Open.Price * p.Open.Quantity) * p.Open.Leverage);
|
||||
|
||||
_logger.LogDebug("Calculated position metrics: {PositionCount} positions, {OpenInterest} leveraged open interest",
|
||||
_logger.LogDebug(
|
||||
"Calculated position metrics: {PositionCount} positions, {OpenInterest} leveraged open interest",
|
||||
positionCount, openInterest);
|
||||
|
||||
return (openInterest, positionCount);
|
||||
@@ -229,20 +230,11 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
}
|
||||
|
||||
// Event handlers for immediate updates
|
||||
public async Task OnStrategyDeployedAsync(StrategyDeployedEvent evt)
|
||||
public async Task UpdateActiveStrategyCountAsync(int newActiveCount)
|
||||
{
|
||||
_logger.LogInformation("Strategy deployed: {StrategyId} - {StrategyName}", evt.StrategyId, evt.StrategyName);
|
||||
_logger.LogInformation("Updating active strategies count to: {NewActiveCount}", newActiveCount);
|
||||
|
||||
_state.State.TotalActiveStrategies++;
|
||||
_state.State.HasPendingChanges = true;
|
||||
await _state.WriteStateAsync();
|
||||
}
|
||||
|
||||
public async Task OnStrategyStoppedAsync(StrategyStoppedEvent evt)
|
||||
{
|
||||
_logger.LogInformation("Strategy stopped: {StrategyId} - {StrategyName}", evt.StrategyId, evt.StrategyName);
|
||||
|
||||
_state.State.TotalActiveStrategies--;
|
||||
_state.State.TotalActiveStrategies = newActiveCount;
|
||||
_state.State.HasPendingChanges = true;
|
||||
await _state.WriteStateAsync();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user