pagination for backtest and optimization

This commit is contained in:
2025-07-16 14:27:07 +07:00
parent 11778aa2a4
commit f51fd5a5f7
15 changed files with 287 additions and 9 deletions

View File

@@ -134,6 +134,54 @@ public class BacktestController : BaseController
return Ok(backtests);
}
/// <summary>
/// Retrieves paginated backtests for a specific genetic request ID.
/// This endpoint is used to view the results of a genetic algorithm optimization with pagination support.
/// </summary>
/// <param name="requestId">The request ID to filter backtests by.</param>
/// <param name="page">Page number (defaults to 1)</param>
/// <param name="pageSize">Number of items per page (defaults to 50, max 100)</param>
/// <returns>A paginated list of backtests associated with the specified request ID.</returns>
[HttpGet]
[Route("ByRequestId/{requestId}/Paginated")]
public async Task<ActionResult<PaginatedBacktestsResponse>> GetBacktestsByRequestIdPaginated(
string requestId,
int page = 1,
int pageSize = 50)
{
if (string.IsNullOrEmpty(requestId))
{
return BadRequest("Request ID is required");
}
if (page < 1)
{
return BadRequest("Page must be greater than 0");
}
if (pageSize < 1 || pageSize > 100)
{
return BadRequest("Page size must be between 1 and 100");
}
var (backtests, totalCount) = _backtester.GetBacktestsByRequestIdPaginated(requestId, page, pageSize);
var totalPages = (int)Math.Ceiling(totalCount / (double)pageSize);
var response = new PaginatedBacktestsResponse
{
Backtests = backtests,
TotalCount = totalCount,
CurrentPage = page,
PageSize = pageSize,
TotalPages = totalPages,
HasNextPage = page < totalPages,
HasPreviousPage = page > 1
};
return Ok(response);
}
/// <summary>
/// Runs a backtest with the specified configuration.
/// The returned backtest includes a complete TradingBotConfig that preserves all