101 lines
3.5 KiB
C#
101 lines
3.5 KiB
C#
using YLErp.BLL.Eod;
|
|
using YLErp.Modules.DataProviderModule;
|
|
|
|
namespace YLErp.Modules.TradeRiskCalcModule
|
|
{
|
|
/// <summary>
|
|
/// 标的价格阈值监控
|
|
/// </summary>
|
|
public class UnderlyingPriceLimitService : YLBaseService
|
|
{
|
|
public UnderlyingPriceLimitService(OptUserInfo userInfo) : base(userInfo)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public UnderlyingPriceChangeLimition GetUnderlyingPriceLimit(string code)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(code))
|
|
{
|
|
throw new ArgumentException("传入的标的代码不能为空", nameof(code));
|
|
}
|
|
|
|
var um = DbContext.underlying_manager.Where(t => t.UnderlyingCode == code).FirstOrDefault();
|
|
if (um == null)
|
|
{
|
|
throw new ServiceException("找不到标的数据:" + code);
|
|
}
|
|
|
|
var date = EodOperationBase.GetLastSettlementDate(DateTime.Today);
|
|
var priceProvider = new EodPriceProvider(date);
|
|
var limit = new UnderlyingPriceChangeLimition
|
|
{
|
|
UnderlyingCode = code,
|
|
basePrice = priceProvider.GetPrice(code, DBModels.SettlementTypeEnum.ClosePrice),//获取最后一日收盘价
|
|
priceIncreaseRate = um.PriceIncreaseRate,
|
|
priceDecreaseRate = um.PriceDecreaseRate
|
|
};
|
|
return limit;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void SaveUnderlyingPriceLimit(UnderlyingPriceChangeLimition limition)
|
|
{
|
|
if (limition is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(limition));
|
|
}
|
|
|
|
var um = DbContext.underlying_manager.Where(t => t.UnderlyingCode == limition.UnderlyingCode).FirstOrDefault();
|
|
if (um == null)
|
|
{
|
|
throw new ServiceException("找不到标的数据:" + limition.UnderlyingCode);
|
|
}
|
|
um.PriceIncreaseRate = limition.priceIncreaseRate;
|
|
um.PriceDecreaseRate = limition.priceDecreaseRate;
|
|
DbContext.SaveChanges();
|
|
}
|
|
|
|
public List<UnderlyingPriceChangeLimition> GetUnderlyingPirceLimits()
|
|
{
|
|
var list = new List<UnderlyingPriceChangeLimition>();
|
|
var ums = DbContext.underlying_manager.Where(o => o.PriceIncreaseRate != 0 || o.PriceDecreaseRate != 0);
|
|
var date = EodOperationBase.GetLastSettlementDate(DateTime.Today);
|
|
var priceProvider = new EodPriceProvider(date);
|
|
foreach (var um in ums)
|
|
{
|
|
var basePrice = priceProvider.GetPrice(um.UnderlyingCode, DBModels.SettlementTypeEnum.ClosePrice);
|
|
list.Add(new UnderlyingPriceChangeLimition()
|
|
{
|
|
UnderlyingCode = um.UnderlyingCode,
|
|
basePrice = basePrice,
|
|
nowPrice = um.Price ?? 0,
|
|
priceIncreaseRate = um.PriceIncreaseRate,
|
|
priceDecreaseRate = um.PriceDecreaseRate
|
|
});
|
|
}
|
|
return list;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class UnderlyingPriceChangeLimition
|
|
{
|
|
public string UnderlyingCode { get; set; }
|
|
|
|
public double basePrice { get; set; }
|
|
|
|
public double nowPrice { get; set; }
|
|
|
|
public double priceIncreaseRate { get; set; }
|
|
|
|
public double priceDecreaseRate { get; set; }
|
|
}
|
|
}
|