Refactor BotController and BotService for improved bot management

- Cleaned up constructor parameters in BotController for better readability.
- Enhanced StartCopyTradingCommand handling with improved formatting.
- Updated bot deletion logic in BotService to delete associated positions and trigger agent summary updates.
- Added new method in TradingService for deleting positions by initiator identifier.
- Implemented error handling in StopBotCommandHandler to ensure agent summary updates do not disrupt bot stop operations.
This commit is contained in:
2025-11-23 15:30:11 +07:00
parent 9c8ab71736
commit 411fc41bef
8 changed files with 558 additions and 13 deletions

View File

@@ -20,7 +20,6 @@ using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Configuration;
using static Managing.Common.Enums;
namespace Managing.Api.Controllers;
@@ -62,7 +61,8 @@ public class BotController : BaseController
public BotController(ILogger<BotController> logger, IMediator mediator, IHubContext<BotHub> hubContext,
IBacktester backtester, IBotService botService, IUserService userService,
IAccountService accountService, IMoneyManagementService moneyManagementService,
IServiceScopeFactory scopeFactory, IAdminConfigurationService adminService, IConfiguration configuration) : base(userService)
IServiceScopeFactory scopeFactory, IAdminConfigurationService adminService,
IConfiguration configuration) : base(userService)
{
_logger = logger;
_mediator = mediator;
@@ -172,7 +172,9 @@ public class BotController : BaseController
return Unauthorized("User not found");
}
var result = await _mediator.Send(new StartCopyTradingCommand(request.MasterBotIdentifier, request.BotTradingBalance, user));
var result =
await _mediator.Send(new StartCopyTradingCommand(request.MasterBotIdentifier, request.BotTradingBalance,
user));
await NotifyBotSubscriberAsync();
return Ok(result);
@@ -306,7 +308,8 @@ public class BotController : BaseController
var result = await _botService.DeleteBot(identifier);
await NotifyBotSubscriberAsync();
return Ok(result);
return result ? Ok(result) : Problem($"Failed to delete bot with identifier {identifier}");
}
catch (Exception ex)
{