135 lines
4.5 KiB
C#
135 lines
4.5 KiB
C#
using YLErp.Abstract.DataProviders;
|
|
|
|
namespace YLErp.Modules.DataProviderModule
|
|
{
|
|
/// <summary>
|
|
/// 标的信息提供接口实现
|
|
/// </summary>
|
|
public class UnderlyingDataProvider : IUnderlyingDataProvider, IPriceProvider
|
|
{
|
|
/// <summary>
|
|
/// 获取标的数据
|
|
/// </summary>
|
|
public underlying_manager GetUnderlying(int underlyingId)
|
|
{
|
|
return DataCacheProvider.GetUnderlyingDataSource().GetData(underlyingId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取标的数据
|
|
/// </summary>
|
|
public underlying_manager GetUnderlying(string underlyingCode)
|
|
{
|
|
return DataCacheProvider.GetUnderlyingDataSource().GetData(underlyingCode);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public underlying_manager GetUnderlying(string underlyingCode, out double contractSize)
|
|
{
|
|
var um = DataCacheProvider.GetUnderlyingDataSource().GetData(underlyingCode);
|
|
contractSize = um?.ContractSize ?? 1;
|
|
return um;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取品种数据
|
|
/// </summary>
|
|
public Variety GetVariety(int varietyId)
|
|
{
|
|
return DataCacheProvider.GetVarietyDataSource().GetData(varietyId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取品种信息
|
|
/// </summary>
|
|
public Variety GetVariety(string underlyingCode, out double contractSize)
|
|
{
|
|
var um = GetUnderlying(underlyingCode);
|
|
contractSize = um?.ContractSize ?? 1;
|
|
return DataCacheProvider.GetVarietyDataSource().GetData(um?.UnderlyingTypeId ?? 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取品种数据
|
|
/// </summary>
|
|
/// <param name="underlyingCode">标的代码</param>
|
|
public Variety GetVariety(string underlyingCode)
|
|
{
|
|
var um = GetUnderlying(underlyingCode);
|
|
return DataCacheProvider.GetVarietyDataSource().GetData(um?.UnderlyingTypeId ?? 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据标的代码获取份额和数量的乘积因子
|
|
/// </summary>
|
|
public int GetCountRatio(string underlyingCode)
|
|
{
|
|
return DataCacheProvider.GetUnderlyingDataSource().GetCountRatio(underlyingCode);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 尝试获取标的过期日(股票:2099-01-01)
|
|
/// </summary>
|
|
public bool TryGetMaturityDate(string underlyingCode, out DateTime date)
|
|
{
|
|
date = DateTime.MinValue;
|
|
|
|
if (string.IsNullOrEmpty(underlyingCode))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var data = DataCacheProvider.GetUnderlyingDataSource().GetData(underlyingCode);
|
|
|
|
if (data == null) return false;
|
|
|
|
date = data.UnderlyingInstrumentType == "Stock" ? DateTime.Now.AddYears(3) : data.MaturityDate ?? DateTime.MinValue;
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据标的代码获取当前价格
|
|
/// </summary>
|
|
public double GetPrice(string underlyingCode)
|
|
{
|
|
return DataCacheProvider.GetUnderlyingDataSource().TryGetPrice(underlyingCode, out var price) ? price : 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据标的代码获取当前价格
|
|
/// </summary>
|
|
public bool TryGetPrice(string underlyingCode, out double price)
|
|
{
|
|
return DataCacheProvider.GetUnderlyingDataSource().TryGetPrice(underlyingCode, out price);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取相关性
|
|
/// </summary>
|
|
public virtual CorrelationTable GetCorrelation(int underlyingId1, int underlyingId2)
|
|
{
|
|
return DataCacheProvider.GetCorrelationDataSource().AsQueryable().FirstOrDefault(
|
|
n => (n.UnderlyingId1 == underlyingId1 && n.UnderlyingId2 == underlyingId2) || (n.UnderlyingId1 == underlyingId2 && n.UnderlyingId2 == underlyingId1));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取场外期权标的信息
|
|
/// </summary>
|
|
public virtual ExchangeListOption GetExchange_List_Option(string ContractCode)
|
|
{
|
|
return DataCacheProvider.GetExchangeListOptionDataSource().GetData(ContractCode);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取组合标的
|
|
/// </summary>
|
|
public SyntheticUnderlying GetSyntheticUnderlying(string underlyingCode)
|
|
{
|
|
return DataCacheProvider.GetUnderlyingDataSource().GetSyntheticUnderlying(underlyingCode);
|
|
}
|
|
}
|
|
}
|