feat: add ?years= param to underlying-only chart endpoint

Endpoint standalone /api/chart/underlying/{id} caricava un TOP 350
fisso; ora accetta ?years= (default 5, clamp 1-20) e la SP filtra per
data invece che per numero di righe.

Il prezzo usato resta Px_close/Px_closeadj in base ad
AdjustedPrices, senza fallback incrociato tra i due campi: quando
Px_closeadj non è backfillato prima di uno split (es. Apple, valorizzato
solo da inizio 2019), un fallback avrebbe mischiato dati adjusted/raw
creando un gradino artificiale nel grafico. La SP ora taglia lo storico
dove il campo scelto non è popolato.

Fix collaterale: skip righe con prezzo NULL prima del cast a decimal,
evitava un InvalidCastException con storici lunghi.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-21 17:54:25 +02:00
parent d59f5a0faa
commit e36ef3fe47
4 changed files with 35 additions and 25 deletions

View File

@@ -184,23 +184,26 @@ public class ChartController : ControllerBase
/// Richiede SP cedlab_Chart_UnderlyingOnly nel DB.
/// Formati supportati: png (default), jpg/jpeg, pdf. Non supporta jpgEnc né ?save=true
/// (nessun alias-certificato applicabile a un sottostante puro).
/// ?years= (default 5, clamp 1-20): ampiezza storico prezzi caricato dalla SP.
/// </summary>
[HttpGet("underlying/{idUnderlyings:int}")]
public async Task<IActionResult> GenerateChartUnderlying(
int idUnderlyings,
[FromQuery] int width = 1100,
[FromQuery] int height = 700,
[FromQuery] string format = "png")
[FromQuery] string format = "png",
[FromQuery] int years = 5)
{
if (idUnderlyings <= 0)
return BadRequest("IDUnderlyings non valido.");
width = Math.Clamp(width, 400, 2000);
height = Math.Clamp(height, 300, 1500);
years = Math.Clamp(years, 1, 20);
try
{
var chartData = await _underlyingChartDataService.GetChartDataAsync(idUnderlyings);
var chartData = await _underlyingChartDataService.GetChartDataAsync(idUnderlyings, years);
if (chartData == null || chartData.Points.Count == 0)
{