Update bot name
This commit is contained in:
@@ -247,12 +247,49 @@ namespace Managing.Application.ManageBot
|
||||
if (_botTasks.TryGetValue(identifier, out var botTaskWrapper) &&
|
||||
botTaskWrapper.BotInstance is TradingBot tradingBot)
|
||||
{
|
||||
return await tradingBot.UpdateConfiguration(newConfig);
|
||||
// Check if the bot name is changing
|
||||
if (newConfig.Name != identifier && !string.IsNullOrEmpty(newConfig.Name))
|
||||
{
|
||||
// Check if new name already exists
|
||||
if (_botTasks.ContainsKey(newConfig.Name))
|
||||
{
|
||||
return false; // New name already in use
|
||||
}
|
||||
|
||||
// Update the bot configuration first
|
||||
var updateResult = await tradingBot.UpdateConfiguration(newConfig, allowNameChange: true);
|
||||
|
||||
if (updateResult)
|
||||
{
|
||||
// Update the dictionary key
|
||||
if (_botTasks.TryRemove(identifier, out var removedWrapper))
|
||||
{
|
||||
_botTasks.TryAdd(newConfig.Name, removedWrapper);
|
||||
|
||||
// Update the backup with the new identifier
|
||||
if (!newConfig.IsForBacktest)
|
||||
{
|
||||
// Delete old backup
|
||||
await _botRepository.DeleteBotBackup(identifier);
|
||||
// Save new backup will be handled by the bot's SaveBackup method
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return updateResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No name change, just update configuration
|
||||
return await tradingBot.UpdateConfiguration(newConfig);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ITradingBot CreateTradingBot(TradingBotConfig config)
|
||||
{
|
||||
return new TradingBot(
|
||||
|
||||
Reference in New Issue
Block a user