Update bot market type
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json;
|
||||
using Managing.Api.Models.Requests;
|
||||
using Managing.Api.Models.Responses;
|
||||
using Managing.Application.Abstractions.Repositories;
|
||||
@@ -35,6 +35,7 @@ public class BacktestController : BaseController
|
||||
private readonly IAccountService _accountService;
|
||||
private readonly IMoneyManagementService _moneyManagementService;
|
||||
private readonly IGeneticService _geneticService;
|
||||
private readonly IFlagsmithService _flagsmithService;
|
||||
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||
private readonly ILogger<BacktestController> _logger;
|
||||
|
||||
@@ -54,6 +55,7 @@ public class BacktestController : BaseController
|
||||
IAccountService accountService,
|
||||
IMoneyManagementService moneyManagementService,
|
||||
IGeneticService geneticService,
|
||||
IFlagsmithService flagsmithService,
|
||||
IUserService userService,
|
||||
IServiceScopeFactory serviceScopeFactory,
|
||||
ILogger<BacktestController> logger) : base(userService)
|
||||
@@ -63,6 +65,7 @@ public class BacktestController : BaseController
|
||||
_accountService = accountService;
|
||||
_moneyManagementService = moneyManagementService;
|
||||
_geneticService = geneticService;
|
||||
_flagsmithService = flagsmithService;
|
||||
_serviceScopeFactory = serviceScopeFactory;
|
||||
_logger = logger;
|
||||
}
|
||||
@@ -152,7 +155,8 @@ public class BacktestController : BaseController
|
||||
[FromQuery] string? indicators = null,
|
||||
[FromQuery] double? durationMinDays = null,
|
||||
[FromQuery] double? durationMaxDays = null,
|
||||
[FromQuery] string? name = null)
|
||||
[FromQuery] string? name = null,
|
||||
[FromQuery] TradingType? tradingType = null)
|
||||
{
|
||||
var user = await GetUser();
|
||||
|
||||
@@ -211,7 +215,8 @@ public class BacktestController : BaseController
|
||||
Tickers = tickerList,
|
||||
Indicators = indicatorList,
|
||||
DurationMin = durationMinDays.HasValue ? TimeSpan.FromDays(durationMinDays.Value) : (TimeSpan?)null,
|
||||
DurationMax = durationMaxDays.HasValue ? TimeSpan.FromDays(durationMaxDays.Value) : (TimeSpan?)null
|
||||
DurationMax = durationMaxDays.HasValue ? TimeSpan.FromDays(durationMaxDays.Value) : (TimeSpan?)null,
|
||||
TradingType = tradingType
|
||||
};
|
||||
|
||||
try
|
||||
@@ -317,7 +322,8 @@ public class BacktestController : BaseController
|
||||
ScoreMessage = b.ScoreMessage,
|
||||
InitialBalance = b.InitialBalance,
|
||||
NetPnl = b.NetPnl,
|
||||
PositionCount = b.PositionCount
|
||||
PositionCount = b.PositionCount,
|
||||
TradingType = b.Config.TradingType
|
||||
}),
|
||||
TotalCount = totalCount,
|
||||
CurrentPage = page,
|
||||
@@ -354,7 +360,8 @@ public class BacktestController : BaseController
|
||||
[FromQuery] string? indicators = null,
|
||||
[FromQuery] double? durationMinDays = null,
|
||||
[FromQuery] double? durationMaxDays = null,
|
||||
[FromQuery] string? name = null)
|
||||
[FromQuery] string? name = null,
|
||||
[FromQuery] TradingType? tradingType = null)
|
||||
{
|
||||
var user = await GetUser();
|
||||
|
||||
@@ -427,7 +434,8 @@ public class BacktestController : BaseController
|
||||
Tickers = tickerList,
|
||||
Indicators = indicatorList,
|
||||
DurationMin = durationMinDays.HasValue ? TimeSpan.FromDays(durationMinDays.Value) : (TimeSpan?)null,
|
||||
DurationMax = durationMaxDays.HasValue ? TimeSpan.FromDays(durationMaxDays.Value) : (TimeSpan?)null
|
||||
DurationMax = durationMaxDays.HasValue ? TimeSpan.FromDays(durationMaxDays.Value) : (TimeSpan?)null,
|
||||
TradingType = tradingType
|
||||
};
|
||||
|
||||
var (backtests, totalCount) =
|
||||
@@ -459,7 +467,8 @@ public class BacktestController : BaseController
|
||||
ScoreMessage = b.ScoreMessage,
|
||||
InitialBalance = b.InitialBalance,
|
||||
NetPnl = b.NetPnl,
|
||||
PositionCount = b.PositionCount
|
||||
PositionCount = b.PositionCount,
|
||||
TradingType = b.Config.TradingType
|
||||
}),
|
||||
TotalCount = totalCount,
|
||||
CurrentPage = page,
|
||||
@@ -651,6 +660,20 @@ public class BacktestController : BaseController
|
||||
{
|
||||
var user = await GetUser();
|
||||
|
||||
// Check if trading type is futures and verify the user has permission via feature flag
|
||||
if (request.UniversalConfig.TradingType == TradingType.Futures ||
|
||||
request.UniversalConfig.TradingType == TradingType.BacktestFutures)
|
||||
{
|
||||
var isTradingFutureEnabled = await _flagsmithService.IsFeatureEnabledAsync(user.Name, "trading_future");
|
||||
|
||||
if (!isTradingFutureEnabled)
|
||||
{
|
||||
_logger.LogWarning("User {UserName} attempted to create futures bundle backtest but does not have the trading_future feature flag enabled",
|
||||
user.Name);
|
||||
return Forbid("Futures trading is not enabled for your account. Please contact support to enable this feature.");
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(request.UniversalConfig.ScenarioName) && request.UniversalConfig.Scenario == null)
|
||||
{
|
||||
return BadRequest("Either scenario name or scenario object is required in universal configuration");
|
||||
|
||||
Reference in New Issue
Block a user