Implement profitable bots filtering in BotController and DataController

- Added IConfiguration dependency to BotController for accessing environment variables.
- Updated GetBotsPaginatedAsync method in BotService and IBotService to include a flag for filtering profitable bots.
- Modified DataController to utilize the new filtering option for agent summaries and bot retrieval.
- Enhanced PostgreSqlBotRepository to apply filtering based on profitability when querying bots.
This commit is contained in:
2025-11-22 14:02:29 +07:00
parent e69dd43ace
commit 2a354bd7d2
6 changed files with 42 additions and 18 deletions

View File

@@ -20,6 +20,7 @@ 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;
@@ -43,6 +44,7 @@ public class BotController : BaseController
private readonly IMoneyManagementService _moneyManagementService;
private readonly IServiceScopeFactory _scopeFactory;
private readonly IAdminConfigurationService _adminService;
private readonly IConfiguration _configuration;
/// <summary>
/// Initializes a new instance of the <see cref="BotController"/> class.
@@ -56,10 +58,11 @@ public class BotController : BaseController
/// <param name="botService"></param>
/// <param name="userService"></param>
/// <param name="scopeFactory"></param>
/// <param name="configuration">Configuration for accessing environment variables.</param>
public BotController(ILogger<BotController> logger, IMediator mediator, IHubContext<BotHub> hubContext,
IBacktester backtester, IBotService botService, IUserService userService,
IAccountService accountService, IMoneyManagementService moneyManagementService,
IServiceScopeFactory scopeFactory, IAdminConfigurationService adminService) : base(userService)
IServiceScopeFactory scopeFactory, IAdminConfigurationService adminService, IConfiguration configuration) : base(userService)
{
_logger = logger;
_mediator = mediator;
@@ -70,6 +73,7 @@ public class BotController : BaseController
_moneyManagementService = moneyManagementService;
_scopeFactory = scopeFactory;
_adminService = adminService;
_configuration = configuration;
}
/// <summary>
@@ -431,6 +435,9 @@ public class BotController : BaseController
pageSize = Math.Min(Math.Max(pageSize, 1), 100);
}
// Check environment variable for filtering profitable bots only
var showOnlyProfitable = _configuration.GetValue<bool>("showOnlyProfitable", false);
// Get paginated bots from service
var (bots, totalCount) = await _botService.GetBotsPaginatedAsync(
pageNumber,
@@ -440,7 +447,8 @@ public class BotController : BaseController
ticker,
agentName,
sortBy,
sortDirection);
sortDirection,
showOnlyProfitable);
// Map to response objects
var tradingBotResponses = MapBotsToTradingBotResponse(bots);