Fix scenario exec

This commit is contained in:
2025-09-15 01:27:06 +07:00
parent d2dbee9a5f
commit bb4db3deff
2 changed files with 18 additions and 15 deletions

View File

@@ -94,9 +94,10 @@ public class TradingBotBase : ITradingBot
$"📢 I'll notify you when signals are triggered.";
await LogInformation(startupMessage);
// Notify AgentGrain about bot startup
await NotifyAgentGrainAsync(AgentSummaryEventType.BotStarted, $"Bot: {Config.Name}, Ticker: {Config.Ticker}");
await NotifyAgentGrainAsync(AgentSummaryEventType.BotStarted,
$"Bot: {Config.Name}, Ticker: {Config.Ticker}");
break;
case BotStatus.Running:
@@ -170,15 +171,11 @@ public class TradingBotBase : ITradingBot
public async Task Run()
{
if (!Config.IsForBacktest)
{
await LoadLastCandle();
}
// Update signals for live trading only
if (!Config.IsForBacktest)
{
await UpdateSignals();
await LoadLastCandle();
}
if (!Config.IsForWatchingOnly)
@@ -770,7 +767,8 @@ public class TradingBotBase : ITradingBot
}
// Notify AgentGrain about position opening
await NotifyAgentGrainAsync(AgentSummaryEventType.PositionOpened, $"Signal: {signal.Identifier}");
await NotifyAgentGrainAsync(AgentSummaryEventType.PositionOpened,
$"Signal: {signal.Identifier}");
Logger.LogInformation($"Position requested");
return position; // Return the created position without adding to list
@@ -1204,8 +1202,11 @@ public class TradingBotBase : ITradingBot
}
// Notify AgentGrain about position closing
var pnlInfo = position.ProfitAndLoss?.Realized != null ? $"PnL: {position.ProfitAndLoss.Realized:F2}" : "PnL: Unknown";
await NotifyAgentGrainAsync(AgentSummaryEventType.PositionClosed, $"Signal: {position.SignalIdentifier}, {pnlInfo}");
var pnlInfo = position.ProfitAndLoss?.Realized != null
? $"PnL: {position.ProfitAndLoss.Realized:F2}"
: "PnL: Unknown";
await NotifyAgentGrainAsync(AgentSummaryEventType.PositionClosed,
$"Signal: {position.SignalIdentifier}, {pnlInfo}");
}
else
{
@@ -1904,7 +1905,7 @@ public class TradingBotBase : ITradingBot
await ServiceScopeHelpers.WithScopedService<IGrainFactory>(_scopeFactory, async grainFactory =>
{
var agentGrain = grainFactory.GetGrain<IAgentGrain>(Account.User.Id);
var updateEvent = new AgentSummaryUpdateEvent
{
UserId = Account.User.Id,
@@ -1915,13 +1916,14 @@ public class TradingBotBase : ITradingBot
};
await agentGrain.OnAgentSummaryUpdateAsync(updateEvent);
Logger.LogDebug("Sent agent notification: {EventType} for bot {BotId}", eventType, Identifier);
});
}
catch (Exception ex)
{
Logger.LogError(ex, "Failed to send agent notification: {EventType} for bot {BotId}", eventType, Identifier);
Logger.LogError(ex, "Failed to send agent notification: {EventType} for bot {BotId}", eventType,
Identifier);
}
}
}

View File

@@ -16,8 +16,9 @@ public class PriceFetcherInitializer : IHostedService
public async Task StartAsync(CancellationToken cancellationToken)
{
// Initialize grains for different timeframes
var timeframes = new[]
{
var timeframes = new[]
{
Timeframe.FiveMinutes,
Timeframe.FifteenMinutes,
Timeframe.OneHour,
Timeframe.FourHour,