using YLErp.BLL;
using YLErp.Modules.DataProviderModule;
namespace YLErp.Modules.UnderlyingModule
{
///
/// 标的价格服务
///
public class UnderlyingSpotPriceService : YLBaseService
{
public UnderlyingSpotPriceService(OptUserInfo userInfo) : base(userInfo)
{
}
///
/// 获取标的价格
///
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 };
}
}
///
/// 标的价格请求
///
public class UnderlyingSpotPriceRequest
{
///
/// 标的代码
///
public string UnderlyingCode { get; set; }
///
/// 取值日期
///
public DateTime? ValueDate { get; set; }
}
///
/// 定价页面期初标的价格
///
public class UnderlyingSpotPriceResult
{
///
/// 标的价格
///
public double? SpotPrice { get; set; }
///
/// 组合标的价格信息
///
public SyntheticPriceModel Synthetic { get; set; }
}
}