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 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 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() }); } } } }