Files
zszq-trs/YLErpDAL/Modules/UnderlyingModule/UnderlyingSpotPriceService.cs
T
2024-05-09 14:06:26 +08:00

92 lines
2.7 KiB
C#

using YLErp.BLL;
using YLErp.Modules.DataProviderModule;
namespace YLErp.Modules.UnderlyingModule
{
/// <summary>
/// 标的价格服务
/// </summary>
public class UnderlyingSpotPriceService : YLBaseService
{
public UnderlyingSpotPriceService(OptUserInfo userInfo) : base(userInfo)
{
}
/// <summary>
/// 获取标的价格
/// </summary>
public UnderlyingSpotPriceResult GetSpotPrice(UnderlyingSpotPriceRequest req)
{
if (req is null)
{
throw new ArgumentNullException(nameof(req));
}
if (string.IsNullOrEmpty(req.UnderlyingCode))
{
throw new ServiceException("缺少标的代码");
}
var um = DataCacheProvider.GetUnderlyingDataSource().GetData(req.UnderlyingCode);
if (um == null)
{
throw new ServiceException("标的信息未找到:" + req.UnderlyingCode);
}
var price = um.Price;
SyntheticPriceModel synthetic = null;
if (um.CommodityCode == "组合标的")
{
using var syntheService = new SyntheticUnderlyingPriceService(OptUser);
synthetic = req.ValueDate != null && req.ValueDate != DateTime.MinValue
? syntheService.GetPriceModel(req.UnderlyingCode, req.ValueDate.Value)
: syntheService.GetPriceModel(req.UnderlyingCode);
synthetic ??= new SyntheticPriceModel();
}
else if (req.ValueDate != null && req.ValueDate != valuedateBLL.ValueDate
&& EodPriceQueryService.TryGetEodPrice(req.ValueDate.Value, req.UnderlyingCode, out var eodPrice))
{
price = eodPrice.ClosePrice;
}
return new UnderlyingSpotPriceResult { SpotPrice = synthetic?.Price ?? price, Synthetic = synthetic };
}
}
/// <summary>
/// 标的价格请求
/// </summary>
public class UnderlyingSpotPriceRequest
{
/// <summary>
/// 标的代码
/// </summary>
public string UnderlyingCode { get; set; }
/// <summary>
/// 取值日期
/// </summary>
public DateTime? ValueDate { get; set; }
}
/// <summary>
/// 定价页面期初标的价格
/// </summary>
public class UnderlyingSpotPriceResult
{
/// <summary>
/// 标的价格
/// </summary>
public double? SpotPrice { get; set; }
/// <summary>
/// 组合标的价格信息
/// </summary>
public SyntheticPriceModel Synthetic { get; set; }
}
}