using Grpc.Core; using Microsoft.AspNetCore.Mvc; using Tinkoff.InvestApi; using Tinkoff.InvestApi.V1; namespace KLHZ.Trader.Service.Controllers { [ApiController] [Route("[controller]/[action]")] public class ExchangeDataController : ControllerBase { private readonly InvestApiClient _investApiClient; public ExchangeDataController(InvestApiClient investApiClient) { _investApiClient = investApiClient; } [HttpGet] public async Task GetFigi([FromQuery] string ticker, [FromQuery] string? classCode = "TQBR") { var req = new InstrumentRequest() { ClassCode = classCode, IdType = InstrumentIdType.Ticker, Id = ticker, }; try { var res = await _investApiClient.Instruments.GetInstrumentByAsync(req); return res.Instrument.Figi; } catch (RpcException ex) { if (ex.StatusCode == Grpc.Core.StatusCode.NotFound && classCode == "TQBR") { return await GetFigi(ticker, "SPBFUT"); } } return null; } [HttpGet] public async Task GetTicker([FromQuery] string figi) { var req = new InstrumentRequest() { ClassCode = "figi", IdType = InstrumentIdType.Figi, Id = figi, }; try { var res = await _investApiClient.Instruments.GetInstrumentByAsync(req); return res.Instrument.Ticker; } catch (Exception ex) { } return null; } } }