Add bundle backtest endpoint
This commit is contained in:
@@ -399,6 +399,114 @@ public class BacktestController : BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs multiple backtests in a bundle with the specified configurations.
|
||||||
|
/// This endpoint receives a list of backtest requests and will execute them all.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="requests">The list of backtest requests to execute.</param>
|
||||||
|
/// <returns>A list of backtest results.</returns>
|
||||||
|
[HttpPost]
|
||||||
|
[Route("Bundle")]
|
||||||
|
public async Task<ActionResult<IEnumerable<object>>> RunBundle([FromBody] List<RunBacktestRequest> requests)
|
||||||
|
{
|
||||||
|
if (requests == null || !requests.Any())
|
||||||
|
{
|
||||||
|
return BadRequest("At least one backtest request is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requests.Count > 10)
|
||||||
|
{
|
||||||
|
return BadRequest("Maximum of 10 backtests allowed per bundle request");
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await GetUser();
|
||||||
|
var results = new List<object>();
|
||||||
|
|
||||||
|
foreach (var request in requests)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Validate individual request
|
||||||
|
if (request?.Config == null)
|
||||||
|
{
|
||||||
|
results.Add(new
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid().ToString(),
|
||||||
|
Status = "Error",
|
||||||
|
Message = "Invalid request: Configuration is required"
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(request.Config.AccountName))
|
||||||
|
{
|
||||||
|
results.Add(new
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid().ToString(),
|
||||||
|
Status = "Error",
|
||||||
|
Message = "Invalid request: Account name is required"
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(request.Config.ScenarioName) && request.Config.Scenario == null)
|
||||||
|
{
|
||||||
|
results.Add(new
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid().ToString(),
|
||||||
|
Status = "Error",
|
||||||
|
Message = "Invalid request: Either scenario name or scenario object is required"
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(request.Config.MoneyManagementName) && request.Config.MoneyManagement == null)
|
||||||
|
{
|
||||||
|
results.Add(new
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid().ToString(),
|
||||||
|
Status = "Error",
|
||||||
|
Message = "Invalid request: Either money management name or money management object is required"
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Implement actual backtest execution logic here
|
||||||
|
// For now, return a placeholder result
|
||||||
|
var placeholderResult = new
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid().ToString(),
|
||||||
|
Status = "Pending",
|
||||||
|
Message = "Bundle backtest - Application layer integration pending",
|
||||||
|
Config = new
|
||||||
|
{
|
||||||
|
AccountName = request.Config.AccountName,
|
||||||
|
Ticker = request.Config.Ticker,
|
||||||
|
ScenarioName = request.Config.ScenarioName,
|
||||||
|
Timeframe = request.Config.Timeframe,
|
||||||
|
BotTradingBalance = request.Config.BotTradingBalance,
|
||||||
|
Name = request.Config.Name ?? $"Bundle-Backtest-{DateTime.UtcNow:yyyyMMdd-HHmmss}"
|
||||||
|
},
|
||||||
|
StartDate = request.StartDate,
|
||||||
|
EndDate = request.EndDate
|
||||||
|
};
|
||||||
|
|
||||||
|
results.Add(placeholderResult);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
results.Add(new
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid().ToString(),
|
||||||
|
Status = "Error",
|
||||||
|
Message = $"Error processing backtest: {ex.Message}"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(results);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Runs a genetic algorithm optimization with the specified configuration.
|
/// Runs a genetic algorithm optimization with the specified configuration.
|
||||||
/// This endpoint saves the genetic request to the database and returns the request ID.
|
/// This endpoint saves the genetic request to the database and returns the request ID.
|
||||||
|
|||||||
Reference in New Issue
Block a user