Fix update agent save + revert market in redis
This commit is contained in:
@@ -61,5 +61,11 @@ namespace Managing.Application.Abstractions.Grains
|
||||
/// <param name="accountName">The account name to check balances for</param>
|
||||
/// <returns>BalanceCheckResult indicating the status and reason for any failure</returns>
|
||||
Task<BalanceCheckResult> CheckAndEnsureEthBalanceAsync(Guid requestingBotId, string accountName);
|
||||
|
||||
/// <summary>
|
||||
/// Forces an update of the agent summary.
|
||||
/// </summary>
|
||||
[OneWay]
|
||||
Task ForceUpdateSummary();
|
||||
}
|
||||
}
|
||||
@@ -161,6 +161,21 @@ public class AgentGrain : Grain, IAgentGrain
|
||||
}
|
||||
}
|
||||
|
||||
[OneWay]
|
||||
public async Task ForceUpdateSummary()
|
||||
{
|
||||
// Check if last update was more than 2 minutes ago
|
||||
if (_state.State.LastSummaryUpdateTime.HasValue &&
|
||||
DateTime.UtcNow - _state.State.LastSummaryUpdateTime.Value < TimeSpan.FromMinutes(2))
|
||||
{
|
||||
_logger.LogDebug("Skipping summary update for agent {UserId} - last update was {TimeAgo} ago",
|
||||
this.GetPrimaryKeyLong(), DateTime.UtcNow - _state.State.LastSummaryUpdateTime.Value);
|
||||
return;
|
||||
}
|
||||
|
||||
await UpdateSummary();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the agent summary by recalculating from position data (used for initialization or manual refresh)
|
||||
/// </summary>
|
||||
@@ -274,6 +289,10 @@ public class AgentGrain : Grain, IAgentGrain
|
||||
// Save summary to database
|
||||
await _agentService.SaveOrUpdateAgentSummary(summary);
|
||||
|
||||
// Update last summary update time
|
||||
_state.State.LastSummaryUpdateTime = DateTime.UtcNow;
|
||||
await _state.WriteStateAsync();
|
||||
|
||||
// Insert balance tracking data
|
||||
InsertBalanceTrackingData(totalBalance, botsAllocationUsdValue, netPnL, usdcWalletValue,
|
||||
usdcInPositionsValue);
|
||||
|
||||
@@ -845,7 +845,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
// Pass the complete Bot object to BotService for saving
|
||||
var success = await ServiceScopeHelpers.WithScopedService<IBotService, bool>(_scopeFactory,
|
||||
async (botService) => { return await botService.SaveBotStatisticsAsync(bot); });
|
||||
|
||||
|
||||
if (success)
|
||||
{
|
||||
_logger.LogDebug(
|
||||
@@ -857,6 +857,12 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
{
|
||||
_logger.LogWarning("Failed to save bot statistics for bot {BotId}", _state.State.Identifier);
|
||||
}
|
||||
|
||||
// await ServiceScopeHelpers.WithScopedService<IGrainFactory>(_scopeFactory, async grainFactory =>
|
||||
// {
|
||||
// var agentGrain = grainFactory.GetGrain<IAgentGrain>(_state.State.User.Id);
|
||||
// await agentGrain.ForceUpdateSummary();
|
||||
// });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -32,6 +32,12 @@ namespace Managing.Application.Bots.Models
|
||||
/// </summary>
|
||||
[Id(5)]
|
||||
public decimal TotalFees { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Timestamp of the last summary update to implement update throttling
|
||||
/// </summary>
|
||||
[Id(6)]
|
||||
public DateTime? LastSummaryUpdateTime { get; set; } = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user