using YLErp.Abstract.DataProviders;
using YLErp.Models;
namespace YLErp.Modules.TradeRiskCalcModule.TaskRunner
{
///
/// 用于价格试算的标的价格价格数据源
///
class UnderlyingFixedPriceProvider : IPriceProvider
{
readonly IEnumerable _underlyingPrices;
public UnderlyingFixedPriceProvider(IEnumerable underlyingPrices)
{
_underlyingPrices = underlyingPrices ?? throw new ArgumentNullException(nameof(underlyingPrices));
}
public double GetPrice(string instrumentId)
{
return TryGetPrice(instrumentId, out var price) ? price : 0;
}
public bool TryGetPrice(string instrumentId, out double price)
{
price = 0;
if (string.IsNullOrEmpty(instrumentId))
{
return false;
}
var data = _underlyingPrices.FirstOrDefault(n => n?.InstrumentCode != null && n.InstrumentCode.Equals(instrumentId, StringComparison.OrdinalIgnoreCase));
if (data != null)
{
price = data.Price;
return true;
}
return false;
}
}
}