Files
zszq-trs/Framework/SharedWebApi/ManagerApi/UnderlyingController.cs
T
2024-05-09 14:06:26 +08:00

107 lines
3.7 KiB
C#

using YLErp.Abstract.DataProviders;
using YLErp.Modules.DataProviderModule;
using YLErp.Modules.UnderlyingModule;
using YLErp.Modules.UnderlyingModule.ApiModudle;
namespace YLWebAPI.ApiModule.ManagerApi
{
/// <summary>
/// 标的资产API
/// </summary>
[ManagerAuth]
public class UnderlyingController : BaseApiController
{
[HttpPost, Route("api/v1/getUnderlyingList")]
public IEnumerable<ApiUnderlyingInfo> GetUnderlyingList()
{
return new ApiDataQueryService(CurUser).GetUnderlyingList();
}
[HttpPost, Route("api/v1/getExchangeOptionList")]
public IEnumerable<ApiUnderlyingInfo> GetExchangeOptionList()
{
return new ApiDataQueryService(CurUser).GetExchangeOptionList();
}
/// <summary>
/// 实时价格查询(获取标的资产实时价格)
/// </summary>
[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);
}
}
/// <summary>
/// 日终价格查询(获取标的资产历史日期结算价)
/// </summary>
[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);
}
}
/// <summary>
/// 分红率查询(获取标的资产分红率)
/// </summary>
[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);
}
}
}