using YLErp.Abstract.DataProviders; using YLErp.Modules.DataProviderModule; using YLErp.Modules.UnderlyingModule; using YLErp.Modules.UnderlyingModule.ApiModudle; namespace YLWebAPI.ApiModule.ManagerApi { /// /// 标的资产API /// [ManagerAuth] public class UnderlyingController : BaseApiController { [HttpPost, Route("api/v1/getUnderlyingList")] public IEnumerable GetUnderlyingList() { return new ApiDataQueryService(CurUser).GetUnderlyingList(); } [HttpPost, Route("api/v1/getExchangeOptionList")] public IEnumerable GetExchangeOptionList() { return new ApiDataQueryService(CurUser).GetExchangeOptionList(); } /// /// 实时价格查询(获取标的资产实时价格) /// [HttpPost] [Route("api/v1/underlying/prices")] public ApiResponseModel UnderlyingPrices([FromBody] UnderlyingPriceRequest req) { var dataSource = DataCacheProvider.GetUnderlyingDataSource(); if (req?.UnderlyingCodes is null || !req.UnderlyingCodes.Any()) { var list = dataSource.AsQueryable().Select(n => new { Code = n.UnderlyingCode, Price = n.IsBasket() ? BasketUnderlyingHelper.GetBasketPrice(n, dataSource as IBasketPriceProvider, true).Price : n.Price }); return JsonSuccess(list); } else { var list = req.UnderlyingCodes.ToHashSet(StringComparer.OrdinalIgnoreCase).Select(n => new { Code = n, Price = dataSource.TryGetPrice(n, out var p) ? (double?)p : null }); return JsonSuccess(list); } } /// /// 日终价格查询(获取标的资产历史日期结算价) /// [HttpPost] [Route("api/v1/underlying/eod_prices")] public ApiResponseModel UnderlyingEodPrices([FromBody] UnderlyingEodPriceRequest req) { if (req is null || req.ValueDate == default) { return JsonError("缺少必要的请求参数"); } var eodPriceProvider = new EodPriceProvider(req.ValueDate).Initialize(req.UnderlyingCodes); var list = eodPriceProvider.GetEodPriceList(); if (list != null && list.Count() > 0) { list = list.Where(p => p != null); } if (list != null && list.Count() > 0) { return JsonSuccess(list.Select(n => new { Code = n.UnderlyingCode, High = n.HighPrice, Low = n.LowPrice, Close = n.ClosePrice, Settle = n.SettlePrice, Refer = n.ReferencePrice })); } else { return JsonSuccess(null); } } /// /// 分红率查询(获取标的资产分红率) /// [HttpPost] [Route("api/v1/underlying/dividend_rate")] public ApiResponseModel UnderlyingDividendRate([FromBody] SingleUnderlyingRequest req) { var list = new UnderlyingDividendService(CurUser).GetHisList(req?.UnderlyingCode); var list2 = list.Select(n => new { ValueDate = n.ValueDate.OtcFormatDate(), n.DividendRate }); return JsonSuccess(list2); } } }