Orlean (#32)
* Start building with orlean * Add missing file * Serialize grain state * Remove grain and proxies * update and add plan * Update a bit * Fix backtest grain * Fix backtest grain * Clean a bit
This commit is contained in:
@@ -29,7 +29,6 @@ public class BacktestController : BaseController
|
||||
{
|
||||
private readonly IHubContext<BacktestHub> _hubContext;
|
||||
private readonly IBacktester _backtester;
|
||||
private readonly IScenarioService _scenarioService;
|
||||
private readonly IAccountService _accountService;
|
||||
private readonly IMoneyManagementService _moneyManagementService;
|
||||
private readonly IGeneticService _geneticService;
|
||||
@@ -47,7 +46,6 @@ public class BacktestController : BaseController
|
||||
public BacktestController(
|
||||
IHubContext<BacktestHub> hubContext,
|
||||
IBacktester backtester,
|
||||
IScenarioService scenarioService,
|
||||
IAccountService accountService,
|
||||
IMoneyManagementService moneyManagementService,
|
||||
IGeneticService geneticService,
|
||||
@@ -55,7 +53,6 @@ public class BacktestController : BaseController
|
||||
{
|
||||
_hubContext = hubContext;
|
||||
_backtester = backtester;
|
||||
_scenarioService = scenarioService;
|
||||
_accountService = accountService;
|
||||
_moneyManagementService = moneyManagementService;
|
||||
_geneticService = geneticService;
|
||||
@@ -245,7 +242,8 @@ public class BacktestController : BaseController
|
||||
return BadRequest("Sort order must be 'asc' or 'desc'");
|
||||
}
|
||||
|
||||
var (backtests, totalCount) = await _backtester.GetBacktestsByUserPaginatedAsync(user, page, pageSize, sortBy, sortOrder);
|
||||
var (backtests, totalCount) =
|
||||
await _backtester.GetBacktestsByUserPaginatedAsync(user, page, pageSize, sortBy, sortOrder);
|
||||
var totalPages = (int)Math.Ceiling(totalCount / (double)pageSize);
|
||||
|
||||
var response = new PaginatedBacktestsResponse
|
||||
@@ -279,14 +277,14 @@ public class BacktestController : BaseController
|
||||
|
||||
/// <summary>
|
||||
/// Runs a backtest with the specified configuration.
|
||||
/// The returned backtest includes a complete TradingBotConfig that preserves all
|
||||
/// settings including nullable MaxPositionTimeHours for easy bot deployment.
|
||||
/// Returns a lightweight backtest result for efficient processing.
|
||||
/// Use the returned ID to retrieve the full backtest data from the database.
|
||||
/// </summary>
|
||||
/// <param name="request">The backtest request containing configuration and parameters.</param>
|
||||
/// <returns>The result of the backtest with complete configuration.</returns>
|
||||
/// <returns>The lightweight result of the backtest with essential data.</returns>
|
||||
[HttpPost]
|
||||
[Route("Run")]
|
||||
public async Task<ActionResult<Backtest>> Run([FromBody] RunBacktestRequest request)
|
||||
public async Task<ActionResult<LightBacktest>> Run([FromBody] RunBacktestRequest request)
|
||||
{
|
||||
if (request?.Config == null)
|
||||
{
|
||||
@@ -310,7 +308,7 @@ public class BacktestController : BaseController
|
||||
|
||||
try
|
||||
{
|
||||
Backtest backtestResult = null;
|
||||
LightBacktest backtestResult = null;
|
||||
var account = await _accountService.GetAccount(request.Config.AccountName, true, false);
|
||||
var user = await GetUser();
|
||||
|
||||
@@ -367,7 +365,9 @@ public class BacktestController : BaseController
|
||||
MoneyManagement = moneyManagement,
|
||||
Ticker = request.Config.Ticker,
|
||||
ScenarioName = request.Config.ScenarioName,
|
||||
Scenario = scenario, // Use the converted scenario object
|
||||
Scenario = scenario != null
|
||||
? LightScenario.FromScenario(scenario)
|
||||
: null, // Convert to LightScenario for Orleans
|
||||
Timeframe = request.Config.Timeframe,
|
||||
IsForWatchingOnly = request.Config.IsForWatchingOnly,
|
||||
BotTradingBalance = request.Config.BotTradingBalance,
|
||||
@@ -395,7 +395,8 @@ public class BacktestController : BaseController
|
||||
request.WithCandles,
|
||||
null); // No requestId for regular backtests
|
||||
|
||||
await NotifyBacktesingSubscriberAsync(backtestResult);
|
||||
// Note: Notification is handled within the Orleans grain for LightBacktest
|
||||
// The full Backtest data can be retrieved from the database using the ID if needed
|
||||
|
||||
return Ok(backtestResult);
|
||||
}
|
||||
@@ -705,17 +706,6 @@ public class BacktestController : BaseController
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Notifies subscribers about the backtesting results via SignalR.
|
||||
/// </summary>
|
||||
/// <param name="backtesting">The backtest result to notify subscribers about.</param>
|
||||
private async Task NotifyBacktesingSubscriberAsync(Backtest backtesting)
|
||||
{
|
||||
if (backtesting != null)
|
||||
{
|
||||
await _hubContext.Clients.All.SendAsync("BacktestsSubscription", backtesting);
|
||||
}
|
||||
}
|
||||
|
||||
public MoneyManagement Map(MoneyManagementRequest moneyManagementRequest)
|
||||
{
|
||||
|
||||
@@ -220,7 +220,7 @@ public class BotController : BaseController
|
||||
AccountName = request.Config.AccountName,
|
||||
MoneyManagement = moneyManagement,
|
||||
Ticker = request.Config.Ticker,
|
||||
Scenario = scenario, // Use the converted scenario object
|
||||
Scenario = LightScenario.FromScenario(scenario), // Convert to LightScenario for Orleans
|
||||
ScenarioName = request.Config.ScenarioName, // Fallback to scenario name if scenario object not provided
|
||||
Timeframe = request.Config.Timeframe,
|
||||
IsForWatchingOnly = request.Config.IsForWatchingOnly,
|
||||
@@ -782,7 +782,7 @@ public class BotController : BaseController
|
||||
AccountName = request.Config.AccountName,
|
||||
MoneyManagement = moneyManagement,
|
||||
Ticker = request.Config.Ticker,
|
||||
Scenario = scenarioForUpdate, // Use the converted scenario object
|
||||
Scenario = LightScenario.FromScenario(scenarioForUpdate), // Convert to LightScenario for Orleans
|
||||
ScenarioName = request.Config.ScenarioName, // Fallback to scenario name if scenario object not provided
|
||||
Timeframe = request.Config.Timeframe,
|
||||
IsForWatchingOnly = request.Config.IsForWatchingOnly,
|
||||
|
||||
Reference in New Issue
Block a user