Add reason when stopping bot
This commit is contained in:
@@ -20,6 +20,7 @@ namespace Managing.Application.Abstractions
|
||||
Candle LastCandle { get; set; }
|
||||
|
||||
Task Run();
|
||||
Task StopBot(string reason = null);
|
||||
int GetWinRate();
|
||||
decimal GetProfitAndLoss();
|
||||
decimal GetTotalFees();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1889,9 +1889,10 @@ public class TradingBotBase : ITradingBot
|
||||
/// <summary>
|
||||
/// Handles bot stopping and notifies platform summary
|
||||
/// </summary>
|
||||
public async Task StopBot()
|
||||
public async Task StopBot(string reason = null)
|
||||
{
|
||||
await LogInformation($"🛑 Bot Stopped\nBot: `{Config.Name}`\nTicker: `{Config.Ticker}`");
|
||||
await LogInformation(
|
||||
$"🛑 Bot Stopped\nBot: `{Config.Name}`\nTicker: `{Config.Ticker}`\nReason: `{reason ?? "No reason provided"}`");
|
||||
}
|
||||
|
||||
public async Task LogInformation(string message)
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Managing.Application.ManageBot
|
||||
try
|
||||
{
|
||||
var grain = _grainFactory.GetGrain<ILiveTradingBotGrain>(identifier);
|
||||
await grain.StopAsync();
|
||||
await grain.StopAsync("User requested stop");
|
||||
return BotStatus.Stopped;
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -72,7 +72,7 @@ namespace Managing.Application.ManageBot
|
||||
{
|
||||
var config = await grain.GetConfiguration();
|
||||
var account = await grain.GetAccount();
|
||||
await grain.StopAsync();
|
||||
await grain.StopAsync("Deleting bot");
|
||||
await _botRepository.DeleteBot(identifier);
|
||||
await grain.DeleteAsync();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user