pagination for backtest and optimization
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -10,6 +10,7 @@ using Managing.Bootstrap;
|
||||
using Managing.Common;
|
||||
using Managing.Core.Middleawares;
|
||||
using Managing.Infrastructure.Databases.InfluxDb.Models;
|
||||
using Managing.Infrastructure.Databases.MongoDb;
|
||||
using Managing.Infrastructure.Databases.MongoDb.Configurations;
|
||||
using Managing.Infrastructure.Evm.Models.Privy;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
@@ -209,6 +210,19 @@ if (builder.Configuration.GetValue<bool>("EnableBotManager", false))
|
||||
var app = builder.Build();
|
||||
app.UseSerilogRequestLogging();
|
||||
|
||||
// Create MongoDB indexes on startup
|
||||
try
|
||||
{
|
||||
var indexService = app.Services.GetRequiredService<IndexService>();
|
||||
await indexService.CreateIndexesAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Log the error but don't fail the application startup
|
||||
var logger = app.Services.GetRequiredService<ILogger<Program>>();
|
||||
logger.LogError(ex, "Failed to create MongoDB indexes on startup. The application will continue without indexes.");
|
||||
}
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
"BaseUrl": "https://api.kaigen.managing.live",
|
||||
"DebitEndpoint": "/api/credits/debit",
|
||||
"RefundEndpoint": "/api/credits/refund",
|
||||
"PrivateKey": "${KAIGEN_PRIVATE_KEY}"
|
||||
"PrivateKey": "0x0fb7fbebde2b9a14b039fa974ad330dd693f91e783cd4ea13ed38be8706835a7"
|
||||
},
|
||||
"N8n": {
|
||||
"WebhookUrl": "https://n8n.kai.managing.live/webhook/fa9308b6-983b-42ec-b085-71599d655951"
|
||||
|
||||
Reference in New Issue
Block a user