Add endpoint for indicator refiner
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using Managing.Api.Models.Requests;
|
||||
using Managing.Api.Models.Responses;
|
||||
using Managing.Application.Abstractions;
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Application.Shared;
|
||||
@@ -340,4 +341,54 @@ public class TradingController : BaseController
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates indicator values and generates signals for a given ticker, timeframe, and date range with selected indicators.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing ticker, timeframe, date range, and indicators configuration.</param>
|
||||
/// <returns>A response containing calculated indicator values and generated signals.</returns>
|
||||
[HttpPost("RefineIndicators")]
|
||||
public async Task<ActionResult<RefineIndicatorsResponse>> RefineIndicators(
|
||||
[FromBody] RefineIndicatorsRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Validate request
|
||||
if (request == null)
|
||||
{
|
||||
return BadRequest("Request cannot be null.");
|
||||
}
|
||||
|
||||
if (request.Indicators == null || request.Indicators.Count == 0)
|
||||
{
|
||||
return BadRequest("At least one indicator must be provided.");
|
||||
}
|
||||
|
||||
if (request.StartDate >= request.EndDate)
|
||||
{
|
||||
return BadRequest("Start date must be before end date.");
|
||||
}
|
||||
|
||||
// Call service - request.Indicators is already List<IndicatorRequest>
|
||||
var result = await _tradingService.RefineIndicatorsAsync(
|
||||
request.Ticker,
|
||||
request.Timeframe,
|
||||
request.StartDate,
|
||||
request.EndDate,
|
||||
request.Indicators);
|
||||
|
||||
// Map service result to API response
|
||||
return Ok(new RefineIndicatorsResponse
|
||||
{
|
||||
IndicatorsValues = result.IndicatorsValues,
|
||||
Signals = result.Signals
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error refining indicators for ticker {Ticker}, timeframe {Timeframe}",
|
||||
request?.Ticker, request?.Timeframe);
|
||||
return StatusCode(500, $"Error refining indicators: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user