Update bot name

This commit is contained in:
2025-06-09 02:00:33 +07:00
parent 64183fface
commit 26098d8c42
3 changed files with 88 additions and 10 deletions

View File

@@ -1278,12 +1278,23 @@ public class TradingBot : Bot, ITradingBot
/// <summary>
/// Updates the trading bot configuration with new settings.
/// This method validates the new configuration and applies it to the running bot.
/// </summary>
/// <param name="newConfig">The new configuration to apply</param>
/// <returns>True if the configuration was successfully updated, false otherwise</returns>
/// <exception cref="ArgumentException">Thrown when the new configuration is invalid</exception>
public async Task<bool> UpdateConfiguration(TradingBotConfig newConfig)
{
return await UpdateConfiguration(newConfig, allowNameChange: false);
}
/// <summary>
/// Updates the trading bot configuration with new settings.
/// This method validates the new configuration and applies it to the running bot.
/// </summary>
/// <param name="newConfig">The new configuration to apply</param>
/// <param name="allowNameChange">Whether to allow changing the bot name/identifier</param>
/// <returns>True if the configuration was successfully updated, false otherwise</returns>
/// <exception cref="ArgumentException">Thrown when the new configuration is invalid</exception>
public async Task<bool> UpdateConfiguration(TradingBotConfig newConfig, bool allowNameChange = false)
{
try
{
@@ -1312,7 +1323,7 @@ public class TradingBot : Bot, ITradingBot
// Protect critical properties that shouldn't change for running bots
var protectedBotType = Config.BotType;
var protectedIsForBacktest = Config.IsForBacktest;
var protectedName = Config.Name;
var protectedName = allowNameChange ? newConfig.Name : Config.Name;
// Log the configuration update (before changing anything)
await LogInformation("⚙️ **Configuration Update**\n" +
@@ -1321,7 +1332,8 @@ public class TradingBot : Bot, ITradingBot
$"⏱️ Max Time: {(Config.MaxPositionTimeHours?.ToString() + "h" ?? "Disabled")}\n" +
$"📈 Flip Only in Profit: {(Config.FlipOnlyWhenInProfit ? "" : "")}\n" +
$"⏳ Cooldown: {Config.CooldownPeriod} candles\n" +
$"📉 Max Loss Streak: {Config.MaxLossStreak}");
$"📉 Max Loss Streak: {Config.MaxLossStreak}" +
(allowNameChange && newConfig.Name != Config.Name ? $"\n🏷 Name: {Config.Name} → {newConfig.Name}" : ""));
// Update the configuration
Config = newConfig;
@@ -1331,6 +1343,13 @@ public class TradingBot : Bot, ITradingBot
Config.IsForBacktest = protectedIsForBacktest;
Config.Name = protectedName;
// Update bot name and identifier if allowed
if (allowNameChange && !string.IsNullOrEmpty(newConfig.Name))
{
Name = newConfig.Name;
Identifier = newConfig.Name;
}
// If account changed, reload it
if (Config.AccountName != Account?.Name)
{