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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
42
src/Managing.Api/Models/Requests/RefineIndicatorsRequest.cs
Normal file
42
src/Managing.Api/Models/Requests/RefineIndicatorsRequest.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Managing.Domain.Backtests;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Models.Requests;
|
||||
|
||||
/// <summary>
|
||||
/// Request model for refining indicators and generating signals.
|
||||
/// </summary>
|
||||
public class RefineIndicatorsRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// The ticker symbol (e.g., "BTC", "ETH").
|
||||
/// </summary>
|
||||
[Required]
|
||||
public Ticker Ticker { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The timeframe for the candles (e.g., "FifteenMinutes", "OneHour", "OneDay").
|
||||
/// </summary>
|
||||
[Required]
|
||||
public Timeframe Timeframe { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The start date for the date range (ISO 8601 format).
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTime StartDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The end date for the date range (ISO 8601 format).
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTime EndDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Array of selected indicators with their parameters.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public List<IndicatorRequest> Indicators { get; set; } = new();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using Managing.Domain.Indicators;
|
||||
using Managing.Domain.Strategies.Base;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Models.Responses;
|
||||
|
||||
/// <summary>
|
||||
/// Response model for refined indicators and signals.
|
||||
/// </summary>
|
||||
public class RefineIndicatorsResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Dictionary of indicator types to their calculated values over time.
|
||||
/// </summary>
|
||||
public Dictionary<IndicatorType, IndicatorsResultBase> IndicatorsValues { get; set; } =
|
||||
new Dictionary<IndicatorType, IndicatorsResultBase>();
|
||||
|
||||
/// <summary>
|
||||
/// Array of signals generated for the date range.
|
||||
/// </summary>
|
||||
public List<LightSignal> Signals { get; set; } = new List<LightSignal>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user