示例#1
0
        public IRateProvider GetRateProvider(BTCPayNetwork network, RateRules rules)
        {
            rules = rules ?? new RateRules();
            var rateProvider = GetDefaultRateProvider(network);

            if (!rules.PreferredExchange.IsCoinAverage())
            {
                rateProvider = CreateExchangeRateProvider(network, rules.PreferredExchange);
            }
            rateProvider = CreateCachedRateProvider(network, rateProvider, rules.PreferredExchange);
            return(new TweakRateProvider(network, rateProvider, rules));
        }
示例#2
0
 public TweakRateProvider(BTCPayNetwork network, IRateProvider rateProvider, RateRules rateRules)
 {
     if (network == null)
     {
         throw new ArgumentNullException(nameof(network));
     }
     if (rateProvider == null)
     {
         throw new ArgumentNullException(nameof(rateProvider));
     }
     if (rateRules == null)
     {
         throw new ArgumentNullException(nameof(rateRules));
     }
     this.network      = network;
     this.rateProvider = rateProvider;
     this.rateRules    = rateRules;
 }
示例#3
0
        public Dictionary <CurrencyPair, Task <RateResult> > FetchRates(HashSet <CurrencyPair> pairs, RateRules rules, CancellationToken cancellationToken)
        {
            if (rules == null)
            {
                throw new ArgumentNullException(nameof(rules));
            }

            var fetchingRates     = new Dictionary <CurrencyPair, Task <RateResult> >();
            var fetchingExchanges = new Dictionary <string, Task <QueryRateResult> >();
            var consolidatedRates = new ExchangeRates();

            foreach (var i in pairs.Select(p => (Pair: p, RateRule: rules.GetRuleFor(p))))
            {
                var dependentQueries = new List <Task <QueryRateResult> >();
                foreach (var requiredExchange in i.RateRule.ExchangeRates)
                {
                    if (!fetchingExchanges.TryGetValue(requiredExchange.Exchange, out var fetching))
                    {
                        fetching = _rateProviderFactory.QueryRates(requiredExchange.Exchange, cancellationToken);
                        fetchingExchanges.Add(requiredExchange.Exchange, fetching);
                    }
                    dependentQueries.Add(fetching);
                }
                fetchingRates.Add(i.Pair, GetRuleValue(dependentQueries, i.RateRule));
            }
            return(fetchingRates);
        }
示例#4
0
 public async Task <RateResult> FetchRate(CurrencyPair pair, RateRules rules, CancellationToken cancellationToken)
 {
     return(await FetchRates(new HashSet <CurrencyPair>(new[] { pair }), rules, cancellationToken).First().Value);
 }
 public IRateProvider GetRateProvider(BTCPayNetwork network, RateRules rules)
 {
     return(_Mocks.FirstOrDefault(m => m.CryptoCode == network.CryptoCode));
 }