42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using YLErp.Abstract.DataProviders;
|
|
using YLErp.Models;
|
|
|
|
namespace YLErp.Modules.TradeRiskCalcModule.TaskRunner
|
|
{
|
|
/// <summary>
|
|
/// 用于价格试算的标的价格价格数据源
|
|
/// </summary>
|
|
class UnderlyingFixedPriceProvider : IPriceProvider
|
|
{
|
|
readonly IEnumerable<PriceModel> _underlyingPrices;
|
|
|
|
public UnderlyingFixedPriceProvider(IEnumerable<PriceModel> 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;
|
|
}
|
|
}
|
|
}
|