Enhance DataController and BotService with new configuration and bot name checks

- Added IConfiguration dependency to DataController for environment variable access.
- Updated GetPaginatedAgentSummariesCommand to include a flag for filtering profitable agents.
- Implemented HasUserBotWithNameAsync method in IBotService and BotService to check for existing bots by name.
- Modified StartBotCommandHandler and StartCopyTradingCommandHandler to prevent duplicate bot names during strategy creation.
This commit is contained in:
2025-11-22 13:34:26 +07:00
parent 269bbfaab0
commit e69dd43ace
9 changed files with 65 additions and 7 deletions

View File

@@ -17,6 +17,7 @@ using Managing.Domain.Trades;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using static Managing.Common.Enums;
using DailySnapshot = Managing.Api.Models.Responses.DailySnapshot;
@@ -41,6 +42,7 @@ public class DataController : ControllerBase
private readonly IGrainFactory _grainFactory;
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly IBotService _botService;
private readonly IConfiguration _configuration;
/// <summary>
/// Initializes a new instance of the <see cref="DataController"/> class.
@@ -50,12 +52,12 @@ public class DataController : ControllerBase
/// <param name="cacheService">Service for caching data.</param>
/// <param name="statisticService">Service for statistical analysis.</param>
/// <param name="agentService">Service for agents</param>
/// <param name="hubContext">SignalR hub context for real-time communication.</param>
/// <param name="mediator">Mediator for handling commands and queries.</param>
/// <param name="tradingService">Service for trading operations.</param>
/// <param name="grainFactory">Orleans grain factory for accessing grains.</param>
/// <param name="serviceScopeFactory">Service scope factory for creating scoped services.</param>
/// <param name="botService">Service for bot operations.</param>
/// <param name="configuration">Configuration for accessing environment variables.</param>
public DataController(
IExchangeService exchangeService,
IAccountService accountService,
@@ -66,7 +68,8 @@ public class DataController : ControllerBase
ITradingService tradingService,
IGrainFactory grainFactory,
IServiceScopeFactory serviceScopeFactory,
IBotService botService)
IBotService botService,
IConfiguration configuration)
{
_exchangeService = exchangeService;
_accountService = accountService;
@@ -78,6 +81,7 @@ public class DataController : ControllerBase
_grainFactory = grainFactory;
_serviceScopeFactory = serviceScopeFactory;
_botService = botService;
_configuration = configuration;
}
/// <summary>
@@ -706,8 +710,11 @@ public class DataController : ControllerBase
.ToList();
}
// Check environment variable for filtering profitable agents only
var showOnlyProfitableAgent = _configuration.GetValue<bool>("showOnlyProfitableAgent", false);
// Get paginated results from database
var command = new GetPaginatedAgentSummariesCommand(page, pageSize, sortBy, sortOrder, agentNamesList);
var command = new GetPaginatedAgentSummariesCommand(page, pageSize, sortBy, sortOrder, agentNamesList, showOnlyProfitableAgent);
var result = await _mediator.Send(command);
var agentSummaries = result.Results;
var totalCount = result.TotalCount;