using Backend.ServiceHander; using Backend.MarketDataRequest; using Microsoft.AspNetCore.Mvc; using IBApi; namespace BackendApi.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 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 = _marketDataService.GetHistorical( symbol.ToUpperInvariant(), endDateTime, duration, barSize, whatToShow, useRth ); return Ok(data); } catch (Exception ex) { return StatusCode(500, new { error = ex.ToString() }); } } [HttpGet("historical-line")] public 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 = _marketDataService.GetHistoricalLine( symbol.ToUpperInvariant(), endDateTime, duration, barSize, whatToShow, useRth ); return Ok(data); } catch (Exception ex) { return StatusCode(500, new { error = ex.ToString() }); } } } }