Fix scenario exec
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user