Add reason when stopping bot
This commit is contained in:
@@ -265,12 +265,12 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
});
|
||||
}
|
||||
|
||||
public async Task StopAsync()
|
||||
public async Task StopAsync(string reason)
|
||||
{
|
||||
await StopAsyncInternal(false);
|
||||
await StopAsyncInternal(false, reason);
|
||||
}
|
||||
|
||||
private async Task StopAsyncInternal(bool isRestarting)
|
||||
private async Task StopAsyncInternal(bool isRestarting, string? reason = null)
|
||||
{
|
||||
// Only check for open positions if this is not part of a restart operation
|
||||
if (!isRestarting)
|
||||
@@ -318,6 +318,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
SyncStateFromBase();
|
||||
await _state.WriteStateAsync();
|
||||
await SaveBotAsync(BotStatus.Stopped);
|
||||
await _tradingBot?.StopBot(reason)!;
|
||||
_tradingBot = null;
|
||||
|
||||
await UpdateBotRegistryStatus(BotStatus.Stopped);
|
||||
@@ -409,7 +410,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
// Check if the bot should stop due to this failure
|
||||
if (balanceCheckResult.ShouldStopBot)
|
||||
{
|
||||
await StopAsync();
|
||||
await StopAsync(balanceCheckResult.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -647,7 +648,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
try
|
||||
{
|
||||
// Stop the bot first if it's running
|
||||
await StopAsync();
|
||||
await StopAsync("Deleting bot");
|
||||
|
||||
// Unregister from the bot registry
|
||||
var botRegistry = GrainFactory.GetGrain<ILiveBotRegistryGrain>(0);
|
||||
|
||||
Reference in New Issue
Block a user