154 lines
5.1 KiB
C#
154 lines
5.1 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using YLErp.Abstract.DataProviders;
|
|
using YLErp.DBModels;
|
|
using YLErp.Modules;
|
|
|
|
namespace YLErp.Helpers
|
|
{
|
|
class InnerUnderlyingDataProvider : IUnderlyingDataProvider
|
|
{
|
|
/// <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 new ExchangeListOption
|
|
{
|
|
CreateTime = DateTime.Now,
|
|
ContractSize = 10,
|
|
ContractCode = ContractCode,
|
|
ExerciseMode = "European",
|
|
MarginRate = 0,
|
|
MaturityDate = DateTime.Today.AddMonths(1),
|
|
MarketCode = "TEST",
|
|
OpenDate = DateTime.Today.AddDays(-10),
|
|
OptionType = ContractCode.Contains("-C-") ? "看涨" : "看跌",
|
|
PrevClosePrice = 12,
|
|
Price = 12.5,
|
|
PriceTick = 0.1,
|
|
PriceTime = DateTime.Now,
|
|
Strike = int.Parse(Regex.Match(ContractCode, "\\d+$").Value),
|
|
UnderlyingCode = "RB00"
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取组合标的
|
|
/// </summary>
|
|
public SyntheticUnderlying GetSyntheticUnderlying(string underlyingCode)
|
|
{
|
|
return DataCacheProvider.GetUnderlyingDataSource().GetSyntheticUnderlying(underlyingCode);
|
|
}
|
|
}
|
|
}
|