Refactor StartBotCommandHandler to conditionally check trading_future feature flag based on trading type. This change ensures that the feature flag validation is only performed for Futures and BacktestFutures trading types, improving the handling of bot configuration.

This commit is contained in:
2025-12-28 22:18:01 +07:00
parent 31886aeaf3
commit e0fb76872e

View File

@@ -29,20 +29,23 @@ namespace Managing.Application.ManageBot
public async Task<BotStatus> Handle(StartBotCommand request, CancellationToken cancellationToken) public async Task<BotStatus> Handle(StartBotCommand request, CancellationToken cancellationToken)
{ {
// Check if trading_future feature flag is enabled
var isTradingFutureEnabled = await _flagsmithService.IsFeatureEnabledAsync(request.User.Name, "trading_future");
if (!isTradingFutureEnabled)
{
throw new InvalidOperationException(
"Futures trading is not enabled for your account. Please contact support to enable this feature.");
}
// Validate the configuration // Validate the configuration
if (request.Config == null) if (request.Config == null)
{ {
throw new ArgumentException("Bot configuration is required"); throw new ArgumentException("Bot configuration is required");
} }
// Check if trading_future feature flag is enabled (only for Futures trading types)
if (request.Config.TradingType == TradingType.Futures || request.Config.TradingType == TradingType.BacktestFutures)
{
var isTradingFutureEnabled = await _flagsmithService.IsFeatureEnabledAsync(request.User.Name, "trading_future");
if (!isTradingFutureEnabled)
{
throw new InvalidOperationException(
"Futures trading is not enabled for your account. Please contact support to enable this feature.");
}
}
if (request.Config.Scenario == null || !request.Config.Scenario.Indicators.Any()) if (request.Config.Scenario == null || !request.Config.Scenario.Indicators.Any())
{ {
throw new InvalidOperationException( throw new InvalidOperationException(