SoftTraderBackend/Controller/MarketDataController.cs
2026-03-20 10:42:48 -04:00

88 lines
1.9 KiB
C#

using Backend.ServiceHander;
using Backend.MarketDataRequest;
using Microsoft.AspNetCore.Mvc;
namespace Backend.Controller
{
[ApiController]
[Route("api/market")]
public class MarketController : ControllerBase
{
private readonly MarketDataService _marketDataService;
public MarketController(MarketDataService marketDataService)
{
_marketDataService = marketDataService;
}
[HttpGet("live/{symbol}")]
public IActionResult GetLive(string symbol)
{
try
{
var data = _marketDataService.GetLiveQuote(symbol.ToUpperInvariant());
return Ok(data);
}
catch (Exception ex)
{
return StatusCode(500, new { error = ex.ToString() });
}
}
[HttpGet("historical")]
public async Task<IActionResult> GetHistorical(
[FromQuery] string symbol,
[FromQuery] string endDateTime,
[FromQuery] string duration,
[FromQuery] HistoricalBarSize barSize,
[FromQuery] HistoricalWhatToShow whatToShow = HistoricalWhatToShow.Trades,
[FromQuery] bool useRth = true)
{
try
{
var data = await _marketDataService.GetHistoricalAsync(
symbol.ToUpperInvariant(),
endDateTime,
duration,
barSize,
whatToShow,
useRth
);
return Ok(data);
}
catch (Exception ex)
{
return StatusCode(500, new { error = ex.ToString() });
}
}
[HttpGet("historical-line")]
public async Task<IActionResult> GetHistoricalLine(
[FromQuery] string symbol,
[FromQuery] string endDateTime,
[FromQuery] string duration,
[FromQuery] HistoricalBarSize barSize,
[FromQuery] HistoricalWhatToShow whatToShow = HistoricalWhatToShow.Trades,
[FromQuery] bool useRth = true)
{
try
{
var data = await _marketDataService.GetHistoricalLineAsync(
symbol.ToUpperInvariant(),
endDateTime,
duration,
barSize,
whatToShow,
useRth
);
return Ok(data);
}
catch (Exception ex)
{
return StatusCode(500, new { error = ex.ToString() });
}
}
}
}