Exemple #1
0
 private CachedRateProvider CreateCachedRateProvider(BTCPayNetwork network, IRateProvider rateProvider, string additionalScope)
 {
     return(new CachedRateProvider(network.CryptoCode, rateProvider, _Cache)
     {
         CacheSpan = CacheSpan, AdditionalScope = additionalScope
     });
 }
Exemple #2
0
 public RatesController(IRateDataWriter dataWriter, IRateProvider provider, IBookProvider bookProvider, IBookDataWriter bookDataWriter)
 {
     _dataWriter     = dataWriter;
     _provider       = provider;
     _bookProvider   = bookProvider;
     _bookDataWriter = bookDataWriter;
 }
 public BackgroundFetcherRateProvider(IRateProvider inner)
 {
     if (inner == null)
     {
         throw new ArgumentNullException(nameof(inner));
     }
     _Inner = inner;
 }
Exemple #4
0
 public BooksController(IBookDataWriter dataWriter, IBookProvider provider, ICommentDataWriter commentDataWriter, ICommentProvider commentProvider, IRateDataWriter rateDataWriter, IRateProvider rateProvider)
 {
     _dataWriter        = dataWriter;
     _provider          = provider;
     _commentDataWriter = commentDataWriter;
     _commentProvider   = commentProvider;
     _rateDataWriter    = rateDataWriter;
     _rateProvider      = rateProvider;
 }
        public Functions(Cobra tradingSystem, IRateProvider rateProvider)
        {
            if (tradingSystem == null)
            {
                throw new ArgumentNullException("system");
            }

            this.tradingSystem = tradingSystem;
            this.rateProvider = rateProvider;
        }
Exemple #6
0
        public decimal Value(Currency currency, IRateProvider rateProvider)
        {
            decimal amount = 0;

            foreach (var stock in _stockList)
            {
                var rate = rateProvider.Rate(stock.StockType, currency);
                amount += rate * stock.Value;
            }

            return(amount);
        }
Exemple #7
0
 public BackgroundFetcherRateProvider(string exchangeName, IRateProvider inner)
 {
     if (inner == null)
     {
         throw new ArgumentNullException(nameof(inner));
     }
     if (exchangeName == null)
     {
         throw new ArgumentNullException(nameof(exchangeName));
     }
     _Inner       = inner;
     ExchangeName = exchangeName;
 }
Exemple #8
0
        public Resampler(ISampleSource source, IRateProvider rate)
        {
            _source = source;
            _rate   = rate;

            AudioSettings.OnAudioConfigurationChanged += OnAudioConfigurationChanged;
            OnAudioConfigurationChanged(false);

            _resampler = new WdlResampler();
            _resampler.SetMode(true, 2, false);
            _resampler.SetFilterParms();
            _resampler.SetFeedMode(false);
        }
Exemple #9
0
 public CachedRateProvider(IRateProvider inner, IMemoryCache memoryCache)
 {
     if (inner == null)
     {
         throw new ArgumentNullException(nameof(inner));
     }
     if (memoryCache == null)
     {
         throw new ArgumentNullException(nameof(memoryCache));
     }
     this._Inner       = inner;
     this._MemoryCache = memoryCache;
 }
 public CachedRateProvider(string exchangeName, IRateProvider inner, IMemoryCache memoryCache)
 {
     if (inner == null)
     {
         throw new ArgumentNullException(nameof(inner));
     }
     if (memoryCache == null)
     {
         throw new ArgumentNullException(nameof(memoryCache));
     }
     this._Inner       = inner;
     this.MemoryCache  = memoryCache;
     this.ExchangeName = exchangeName;
 }
 public CachedRateProvider(string cryptoCode, IRateProvider inner, IMemoryCache memoryCache)
 {
     if (inner == null)
     {
         throw new ArgumentNullException(nameof(inner));
     }
     if (memoryCache == null)
     {
         throw new ArgumentNullException(nameof(memoryCache));
     }
     this._Inner      = inner;
     this.MemoryCache = memoryCache;
     this._CryptoCode = cryptoCode;
 }
Exemple #12
0
        public void GetExchangeRates_InvalidURL_ThrowsException()
        {
            Mock <IRateProviderSettings> settingsMock = new Mock <IRateProviderSettings>();

            settingsMock.Setup(mock => mock.CZKExchangeRateProviderUrl).Returns("Invalid Url");

            IRateProvider rateProvider = ContainerConfiguration.Container.Resolve <IRateProvider>(
                new Unity.Resolution.ParameterOverride("rateProviderSettings", settingsMock.Object)
                );

            Assert.ThrowsException <ArgumentException>(() =>
            {
                rateProvider.GetExchangeRates();
            });
        }
        private List <ShippingRate> doGetShipmentRates(IRateProvider provider)
        {
            // arrage
            var from         = new Address("Annapolis", "MD", "21401", "US");
            var to           = new Address("Fitchburg", "WI", "53711", "US");
            var packageItems = new List <Package>();

            packageItems.Add(new Package(4, 3, 2, 2, 2.2m));
            packageItems.Add(new Package(7, 7, 7, 6, 0));
            var shipment = new Shipment(from, to, packageItems);

            shipment.TransactionId = "10000001";

            // act
            return(provider.GetShipmentRates(shipment));
        }
Exemple #14
0
 public TweakRateProvider(BTCPayNetwork network, IRateProvider rateProvider, List <RateRule> 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;
 }
Exemple #15
0
        /// <summary>
        /// Should return exchange rates among the specified currencies that are defined by the source. But only those defined
        /// by the source, do not return calculated exchange rates. E.g. if the source contains "EUR/USD" but not "USD/EUR",
        /// do not return exchange rate "USD/EUR" with value calculated as 1 / "EUR/USD". If the source does not provide
        /// some of the currencies, ignore them.
        /// </summary>
        public IEnumerable <ExchangeRate> GetExchangeRates(IEnumerable <Currency> currencies)
        {
            List <ExchangeRate> exchangeRates = new List <ExchangeRate>();

            IRateProvider rateProvider = RateProviderFactory.Create();

            IDictionary <string, decimal> exchangeRatesDictionary = rateProvider.GetExchangeRates();

            foreach (Currency currency in currencies)
            {
                if (exchangeRatesDictionary.ContainsKey(currency.Code))
                {
                    ExchangeRate exchangeRate = ExchangeRateFactory.Create(rateProvider.SourceCurrencyCode, currency, exchangeRatesDictionary[currency.Code]);

                    exchangeRates.Add(exchangeRate);
                }
            }

            return(exchangeRates);
        }
Exemple #16
0
 public InvoiceController(
     Network network,
     InvoiceRepository invoiceRepository,
     UserManager <ApplicationUser> userManager,
     BTCPayWallet wallet,
     IRateProvider rateProvider,
     StoreRepository storeRepository,
     InvoiceWatcher watcher,
     ExplorerClient explorerClient,
     IFeeProvider feeProvider)
 {
     _Explorer          = explorerClient ?? throw new ArgumentNullException(nameof(explorerClient));
     _StoreRepository   = storeRepository ?? throw new ArgumentNullException(nameof(storeRepository));
     _Network           = network ?? throw new ArgumentNullException(nameof(network));
     _InvoiceRepository = invoiceRepository ?? throw new ArgumentNullException(nameof(invoiceRepository));
     _Wallet            = wallet ?? throw new ArgumentNullException(nameof(wallet));
     _RateProvider      = rateProvider ?? throw new ArgumentNullException(nameof(rateProvider));
     _Watcher           = watcher ?? throw new ArgumentNullException(nameof(watcher));
     _UserManager       = userManager;
     _FeeProvider       = feeProvider ?? throw new ArgumentNullException(nameof(feeProvider));
 }
Exemple #17
0
        public void GetExchangeRates_CNBRateUrl_ReturnRateWithAmount1()
        {
            Mock <IRateProviderSettings> settingsMock = new Mock <IRateProviderSettings>();

            settingsMock.Setup(mock => mock.CZKExchangeRateProviderUrl).Returns(
                "https://www.cnb.cz/en/financial-markets/foreign-exchange-market/central-bank-exchange-rate-fixing/central-bank-exchange-rate-fixing/daily.txt"
                );

            IRateProvider rateProvider = ContainerConfiguration.Container.Resolve <IRateProvider>(
                new Unity.Resolution.ParameterOverride("rateProviderSettings", settingsMock.Object)
                );

            var rates = rateProvider.GetExchangeRates(new DateTime(2020, 1, 1));

            if (rates.ContainsKey("PHP"))
            {
                Assert.AreEqual((decimal)(44.661 / 100), rates["PHP"]);
            }
            else
            {
                Assert.Fail();
            }
        }
 public InvoiceController(InvoiceRepository invoiceRepository,
                          CurrencyNameTable currencyNameTable,
                          UserManager <ApplicationUser> userManager,
                          BTCPayWallet wallet,
                          IRateProvider rateProvider,
                          StoreRepository storeRepository,
                          EventAggregator eventAggregator,
                          InvoiceWatcherAccessor watcher,
                          ExplorerClient explorerClient,
                          BTCPayNetworkProvider networkProvider,
                          IFeeProviderFactory feeProviderFactory)
 {
     _CurrencyNameTable  = currencyNameTable ?? throw new ArgumentNullException(nameof(currencyNameTable));
     _Explorer           = explorerClient ?? throw new ArgumentNullException(nameof(explorerClient));
     _StoreRepository    = storeRepository ?? throw new ArgumentNullException(nameof(storeRepository));
     _InvoiceRepository  = invoiceRepository ?? throw new ArgumentNullException(nameof(invoiceRepository));
     _Wallet             = wallet ?? throw new ArgumentNullException(nameof(wallet));
     _RateProvider       = rateProvider ?? throw new ArgumentNullException(nameof(rateProvider));
     _Watcher            = (watcher ?? throw new ArgumentNullException(nameof(watcher))).Instance;
     _UserManager        = userManager;
     _FeeProviderFactory = feeProviderFactory ?? throw new ArgumentNullException(nameof(feeProviderFactory));
     _EventAggregator    = eventAggregator;
     _NetworkProvider    = networkProvider;
 }
 public IRateProvider ApplyRateRules(BTCPayNetwork network, IRateProvider rateProvider)
 {
     if (!PreferredExchange.IsCoinAverage())
     {
         // If the original rateProvider is a cache, use the same inner provider as fallback, and same memory cache to wrap it all
         if (rateProvider is CachedRateProvider cachedRateProvider)
         {
             rateProvider = new FallbackRateProvider(new IRateProvider[] {
                 new CoinAverageRateProvider(network.CryptoCode)
                 {
                     Exchange = PreferredExchange
                 },
                 cachedRateProvider.Inner
             });
             rateProvider = new CachedRateProvider(network.CryptoCode, rateProvider, cachedRateProvider.MemoryCache)
             {
                 AdditionalScope = PreferredExchange
             };
         }
         else
         {
             rateProvider = new FallbackRateProvider(new IRateProvider[] {
                 new CoinAverageRateProvider(network.CryptoCode)
                 {
                     Exchange = PreferredExchange
                 },
                 rateProvider
             });
         }
     }
     if (RateRules == null || RateRules.Count == 0)
     {
         return(rateProvider);
     }
     return(new TweakRateProvider(network, rateProvider, RateRules.ToList()));
 }
Exemple #20
0
 public AssetConverter(IRateProvider rateProvider)
 {
     _rateProvider = rateProvider ?? throw new ArgumentNullException(nameof(rateProvider));
 }
 public UpdatePricesTask(ISessionManager sessionManager, IClock clock, IRateProvider rateProvider)
 {
     _sessionManager = sessionManager;
     _clock = clock;
     _rateProvider = rateProvider;
 }
Exemple #22
0
 public BackgroundFetcherRateProvider(IRateProvider inner)
 {
     ArgumentNullException.ThrowIfNull(inner);
     _Inner = inner;
 }
Exemple #23
0
 public RateMyShizzleController(IRateProvider rateProvider)
 {
     _rateProvider = rateProvider;
 }
Exemple #24
0
 public InfoQueryHandler(IBudgetDbContext context, IRateProvider rates, IMapper mapper)
 {
     _context = context;
     _rates   = rates;
     _mapper  = mapper;
 }
 public RateController(IRateProvider rateProvider)
 {
     this.rateProvider = rateProvider;
 }
Exemple #26
0
 public RateController(IRateProvider rateProvider, CurrencyNameTable currencyNameTable)
 {
     _RateProvider      = rateProvider ?? throw new ArgumentNullException(nameof(rateProvider));
     _CurrencyNameTable = currencyNameTable ?? throw new ArgumentNullException(nameof(currencyNameTable));
 }
Exemple #27
0
        public Cobra(Adx adx,
            Ema fastEmaHigh,
            Ema fastEmaLow,
            Sma slowSmaHigh,
            Sma slowSmaLow,
            IDateProvider dateProvider,
            string instrument,
            int periodInMinutes,
            ITradingAdapter tradingAdapter,
            IRateProvider rateProvider,
            int accountId,
            bool isbacktesting = false,
            IEnumerable<Candle> initialCandles = null)
        {
            if (adx == null)
            {
                throw new ArgumentNullException(nameof(adx));
            }
            if (fastEmaHigh == null)
            {
                throw new ArgumentNullException(nameof(fastEmaHigh));
            }
            if (fastEmaLow == null)
            {
                throw new ArgumentNullException(nameof(fastEmaLow));
            }
            if (slowSmaHigh == null)
            {
                throw new ArgumentNullException(nameof(slowSmaHigh));
            }
            if (slowSmaLow == null)
            {
                throw new ArgumentNullException(nameof(slowSmaLow));
            }
            if (dateProvider == null)
            {
                throw new ArgumentNullException(nameof(dateProvider));
            }
            if (tradingAdapter == null)
            {
                throw new ArgumentNullException(nameof(tradingAdapter));
            }
            if (string.IsNullOrWhiteSpace(instrument))
            {
                throw new ArgumentNullException(nameof(instrument));
            }

            this.adx = adx;
            this.fastEmaHigh = fastEmaHigh;
            this.fastEmaLow = fastEmaLow;
            this.slowSmaHigh = slowSmaHigh;
            this.slowSmaLow = slowSmaLow;
            this.dateProvider = dateProvider;
            this.Instrument = instrument;
            this.tradingAdapter = tradingAdapter;
            this.rateProvider = rateProvider;
            this.AccountId = accountId;
            this.isbacktesting = isbacktesting;
            this.PeriodInMinutes = periodInMinutes;
            this.candles = new List<Candle>();

            if (!(initialCandles?.Any()).GetValueOrDefault(false) && rateProvider != null)
            {
                var _initialCandles = rateProvider.GetLastCandles(instrument, periodInMinutes, MinNbOfCandles).ToList();

                try
                {
                    this.AddCandles(initialCandles);
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }
            else if ((initialCandles?.Any()).GetValueOrDefault(false))
            {
                this.AddCandles(initialCandles);
            }
            else if (rateProvider == null)
            {
                throw new ArgumentNullException(nameof(rateProvider));
            }

            this.Id = Guid.NewGuid().ToString();

            candleBuilder = new CandleBuilder(TimeSpan.FromMinutes(periodInMinutes));
            candleBuilder.NewCandleCreated += (o, e) => {
                try
                {
                    this.AddCandle(e.NewCandle);
                }
                catch(Exception ex)
                {
                    validations.AddErrorMessage(ex.Message);
                }
            };
        }
Exemple #28
0
 public CompanyTaxCalcluator(ITaxCalculator calc, IEmployeeProvider empProvider, IRateProvider rateProvider)
 {
     _provider      = empProvider;
     _rateProvider  = rateProvider;
     _taxCalculator = calc;
 }
 public RateMyShizzleController(IRateProvider rateProvider)
 {
     _rateProvider = rateProvider;
 }
 public CurrencyCalculator(IRateProvider rateProvider)
 {
     _rateprovider = rateProvider;
 }
 public WrapperRateProvider(IRateProvider inner)
 {
     _inner = inner;
 }
Exemple #32
0
 public PaymentController(IPaymentProvider paymentProvider, IMemberProvider memberProvider, IRateProvider rateProvider)
 {
     this.paymentProvider = paymentProvider;
     this.memberProvider  = memberProvider;
     this.rateProvider    = rateProvider;
 }