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

@@ -96,7 +96,8 @@ public class TradingBotBase : ITradingBot
await LogInformation(startupMessage); await LogInformation(startupMessage);
// Notify AgentGrain about bot startup // 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; break;
case BotStatus.Running: case BotStatus.Running:
@@ -170,15 +171,11 @@ public class TradingBotBase : ITradingBot
public async Task Run() public async Task Run()
{ {
if (!Config.IsForBacktest)
{
await LoadLastCandle();
}
// Update signals for live trading only // Update signals for live trading only
if (!Config.IsForBacktest) if (!Config.IsForBacktest)
{ {
await UpdateSignals(); await UpdateSignals();
await LoadLastCandle();
} }
if (!Config.IsForWatchingOnly) if (!Config.IsForWatchingOnly)
@@ -770,7 +767,8 @@ public class TradingBotBase : ITradingBot
} }
// Notify AgentGrain about position opening // Notify AgentGrain about position opening
await NotifyAgentGrainAsync(AgentSummaryEventType.PositionOpened, $"Signal: {signal.Identifier}"); await NotifyAgentGrainAsync(AgentSummaryEventType.PositionOpened,
$"Signal: {signal.Identifier}");
Logger.LogInformation($"Position requested"); Logger.LogInformation($"Position requested");
return position; // Return the created position without adding to list return position; // Return the created position without adding to list
@@ -1204,8 +1202,11 @@ public class TradingBotBase : ITradingBot
} }
// Notify AgentGrain about position closing // Notify AgentGrain about position closing
var pnlInfo = position.ProfitAndLoss?.Realized != null ? $"PnL: {position.ProfitAndLoss.Realized:F2}" : "PnL: Unknown"; var pnlInfo = position.ProfitAndLoss?.Realized != null
await NotifyAgentGrainAsync(AgentSummaryEventType.PositionClosed, $"Signal: {position.SignalIdentifier}, {pnlInfo}"); ? $"PnL: {position.ProfitAndLoss.Realized:F2}"
: "PnL: Unknown";
await NotifyAgentGrainAsync(AgentSummaryEventType.PositionClosed,
$"Signal: {position.SignalIdentifier}, {pnlInfo}");
} }
else else
{ {
@@ -1921,7 +1922,8 @@ public class TradingBotBase : ITradingBot
} }
catch (Exception ex) 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

@@ -18,6 +18,7 @@ public class PriceFetcherInitializer : IHostedService
// Initialize grains for different timeframes // Initialize grains for different timeframes
var timeframes = new[] var timeframes = new[]
{ {
Timeframe.FiveMinutes,
Timeframe.FifteenMinutes, Timeframe.FifteenMinutes,
Timeframe.OneHour, Timeframe.OneHour,
Timeframe.FourHour, Timeframe.FourHour,