Fix status IsFinished/IsOpen/IsForMetrics + use redis for markets on gmx.tsx instead of inmemory cache
This commit is contained in:
@@ -211,7 +211,7 @@ public class AgentGrain : Grain, IAgentGrain
|
||||
usdcWalletValue += usdcBalance;
|
||||
}
|
||||
|
||||
foreach (var position in positions.Where(p => !p.IsFinished()))
|
||||
foreach (var position in positions.Where(p => p.IsOpen()))
|
||||
{
|
||||
var positionUsd = position.Open.Price * position.Open.Quantity;
|
||||
var realized = position.ProfitAndLoss?.Realized ?? 0;
|
||||
|
||||
@@ -925,14 +925,14 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
if (_tradingBot == null)
|
||||
{
|
||||
// For non-running bots, check grain state positions
|
||||
var hasOpenPositions = _state.State.Positions?.Values.Any(p => !p.IsFinished()) ?? false;
|
||||
var hasOpenPositions = _state.State.Positions?.Values.Any(p => p.IsOpen()) ?? false;
|
||||
_logger.LogDebug("Bot {GrainId} has open positions: {HasOpenPositions} (from grain state)",
|
||||
this.GetPrimaryKey(), hasOpenPositions);
|
||||
return Task.FromResult(hasOpenPositions);
|
||||
}
|
||||
|
||||
// For running bots, check live positions
|
||||
var hasLiveOpenPositions = _tradingBot.Positions?.Values.Any(p => !p.IsFinished()) ?? false;
|
||||
var hasLiveOpenPositions = _tradingBot.Positions?.Values.Any(p => p.IsOpen()) ?? false;
|
||||
_logger.LogDebug("Bot {GrainId} has open positions: {HasOpenPositions} (from live data)",
|
||||
this.GetPrimaryKey(), hasLiveOpenPositions);
|
||||
return Task.FromResult(hasLiveOpenPositions);
|
||||
@@ -958,13 +958,13 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
_scopeFactory,
|
||||
async tradingService => await tradingService.GetPositionsByInitiatorIdentifierAsync(botId));
|
||||
|
||||
var hasOpenPositions = positions?.Any(p => !p.IsFinished()) ?? false;
|
||||
var hasOpenPositions = positions?.Any(p => p.IsOpen()) ?? false;
|
||||
_logger.LogDebug("Bot {GrainId} has open positions in database: {HasOpenPositions}",
|
||||
botId, hasOpenPositions);
|
||||
|
||||
if (hasOpenPositions)
|
||||
{
|
||||
var openPositions = positions?.Where(p => !p.IsFinished()).ToList() ?? new List<Position>();
|
||||
var openPositions = positions?.Where(p => p.IsOpen()).ToList() ?? new List<Position>();
|
||||
_logger.LogWarning(
|
||||
"Bot {GrainId} cannot be stopped - has {Count} open positions in database: {Positions}",
|
||||
botId, openPositions.Count, string.Join(", ", openPositions.Select(p => p.Identifier)));
|
||||
|
||||
Reference in New Issue
Block a user