Пример #1
0
        private async Task <QueryRateResult> QueryRates(string exchangeName)
        {
            List <IRateProvider> providers = new List <IRateProvider>();

            if (DirectProviders.TryGetValue(exchangeName, out var directProvider))
            {
                providers.Add(directProvider);
            }
            if (_CoinAverageSettings.AvailableExchanges.ContainsKey(exchangeName))
            {
                providers.Add(new CoinAverageRateProvider()
                {
                    Exchange      = exchangeName,
                    Authenticator = _CoinAverageSettings
                });
            }
            var fallback = new FallbackRateProvider(providers.ToArray());
            var cached   = new CachedRateProvider(exchangeName, fallback, _Cache)
            {
                CacheSpan = CacheSpan
            };
            var value = await cached.GetRatesAsync();

            return(new QueryRateResult()
            {
                CachedResult = !fallback.Used,
                ExchangeRates = value,
                Exceptions = fallback.Exceptions
                             .Select(c => new ExchangeException()
                {
                    Exception = c, ExchangeName = exchangeName
                }).ToList()
            });
        }
Пример #2
0
        private void InitExchanges()
        {
            // We need to be careful to only add exchanges which OnGetTickers implementation make only 1 request
            Providers.Add("binance", new ExchangeSharpRateProvider("binance", new ExchangeBinanceAPI(), true));
            Providers.Add("bittrex", new ExchangeSharpRateProvider("bittrex", new ExchangeBittrexAPI(), true));
            Providers.Add("poloniex", new ExchangeSharpRateProvider("poloniex", new ExchangePoloniexAPI(), true));
            Providers.Add("hitbtc", new ExchangeSharpRateProvider("hitbtc", new ExchangeHitbtcAPI(), false));
            Providers.Add("cryptopia", new ExchangeSharpRateProvider("cryptopia", new ExchangeCryptopiaAPI(), false));

            // Handmade providers
            Providers.Add("bitpay", new BitpayRateProvider(new NBitpayClient.Bitpay(new NBitcoin.Key(), new Uri("https://bitpay.com/"))));
            Providers.Add(QuadrigacxRateProvider.QuadrigacxName, new QuadrigacxRateProvider());
            Providers.Add(CoinAverageRateProvider.CoinAverageName, new CoinAverageRateProvider()
            {
                Exchange = CoinAverageRateProvider.CoinAverageName, HttpClient = _httpClientFactory?.CreateClient(), Authenticator = _CoinAverageSettings
            });
            Providers.Add("kraken", new KrakenExchangeRateProvider()
            {
                HttpClient = _httpClientFactory?.CreateClient()
            });

            // Those exchanges make multiple requests when calling GetTickers so we remove them
            //DirectProviders.Add("gdax", new ExchangeSharpRateProvider("gdax", new ExchangeGdaxAPI()));
            //DirectProviders.Add("gemini", new ExchangeSharpRateProvider("gemini", new ExchangeGeminiAPI()));
            //DirectProviders.Add("bitfinex", new ExchangeSharpRateProvider("bitfinex", new ExchangeBitfinexAPI()));
            //DirectProviders.Add("okex", new ExchangeSharpRateProvider("okex", new ExchangeOkexAPI()));
            //DirectProviders.Add("bitstamp", new ExchangeSharpRateProvider("bitstamp", new ExchangeBitstampAPI()));

            foreach (var provider in Providers.ToArray())
            {
                var prov = new BackgroundFetcherRateProvider(Providers[provider.Key]);
                prov.RefreshRate        = provider.Key == CoinAverageRateProvider.CoinAverageName ? CacheSpan : TimeSpan.FromMinutes(1.0);
                Providers[provider.Key] = prov;
            }

            var cache = new MemoryCache(_CacheOptions);

            foreach (var supportedExchange in GetSupportedExchanges())
            {
                if (!Providers.ContainsKey(supportedExchange.Key))
                {
                    var coinAverage = new CoinAverageRateProvider()
                    {
                        Exchange      = supportedExchange.Key,
                        HttpClient    = _httpClientFactory?.CreateClient(),
                        Authenticator = _CoinAverageSettings
                    };
                    var cached = new CachedRateProvider(supportedExchange.Key, coinAverage, cache)
                    {
                        CacheSpan = CacheSpan
                    };
                    Providers.Add(supportedExchange.Key, cached);
                }
            }
        }
Пример #3
0
        private void InitExchanges()
        {
            // We need to be careful to only add exchanges which OnGetTickers implementation make only 1 request
            Providers.Add("binance", new ExchangeSharpRateProvider("binance", new ExchangeBinanceAPI(), true));
            Providers.Add("bittrex", new ExchangeSharpRateProvider("bittrex", new ExchangeBittrexAPI(), true));
            Providers.Add("poloniex", new ExchangeSharpRateProvider("poloniex", new ExchangePoloniexAPI(), true));
            Providers.Add("hitbtc", new ExchangeSharpRateProvider("hitbtc", new ExchangeHitbtcAPI(), false));

            // Cryptopia is often not available
            // Disabled because of https://twitter.com/Cryptopia_NZ/status/1085084168852291586
            // Providers.Add("cryptopia", new ExchangeSharpRateProvider("cryptopia", new ExchangeCryptopiaAPI(), false));

            // Handmade providers
            Providers.Add(QuadrigacxRateProvider.QuadrigacxName, new QuadrigacxRateProvider());
            Providers.Add(CoinAverageRateProvider.CoinAverageName, new CoinAverageRateProvider()
            {
                Exchange = CoinAverageRateProvider.CoinAverageName, HttpClient = _httpClientFactory?.CreateClient("EXCHANGE_COINAVERAGE"), Authenticator = _CoinAverageSettings
            });
            Providers.Add("kraken", new KrakenExchangeRateProvider()
            {
                HttpClient = _httpClientFactory?.CreateClient("EXCHANGE_KRAKEN")
            });
            Providers.Add("bylls", new ByllsRateProvider(_httpClientFactory?.CreateClient("EXCHANGE_BYLLS")));

            // Those exchanges make multiple requests when calling GetTickers so we remove them
            //DirectProviders.Add("gdax", new ExchangeSharpRateProvider("gdax", new ExchangeGdaxAPI()));
            //DirectProviders.Add("gemini", new ExchangeSharpRateProvider("gemini", new ExchangeGeminiAPI()));
            //DirectProviders.Add("bitfinex", new ExchangeSharpRateProvider("bitfinex", new ExchangeBitfinexAPI()));
            //DirectProviders.Add("okex", new ExchangeSharpRateProvider("okex", new ExchangeOkexAPI()));
            //DirectProviders.Add("bitstamp", new ExchangeSharpRateProvider("bitstamp", new ExchangeBitstampAPI()));

            foreach (var provider in Providers.ToArray())
            {
                if (provider.Key == "cryptopia") // Shitty exchange, rate often unavailable, it spams the logs
                {
                    continue;
                }
                var prov = new BackgroundFetcherRateProvider(Providers[provider.Key]);
                if (provider.Key == CoinAverageRateProvider.CoinAverageName)
                {
                    prov.RefreshRate  = CacheSpan;
                    prov.ValidatyTime = CacheSpan + TimeSpan.FromMinutes(1.0);
                }
                else
                {
                    prov.RefreshRate  = TimeSpan.FromMinutes(1.0);
                    prov.ValidatyTime = TimeSpan.FromMinutes(5.0);
                }
                Providers[provider.Key] = prov;
            }

            var cache = new MemoryCache(_CacheOptions);

            foreach (var supportedExchange in GetSupportedExchanges())
            {
                if (!Providers.ContainsKey(supportedExchange.Key))
                {
                    var coinAverage = new CoinAverageRateProvider()
                    {
                        Exchange      = supportedExchange.Key,
                        HttpClient    = _httpClientFactory?.CreateClient(),
                        Authenticator = _CoinAverageSettings
                    };
                    var cached = new CachedRateProvider(supportedExchange.Key, coinAverage, cache)
                    {
                        CacheSpan = CacheSpan
                    };
                    Providers.Add(supportedExchange.Key, cached);
                }
            }
        }
Пример #4
0
        void InitExchanges()
        {
            // We need to be careful to only add exchanges which OnGetTickers implementation make only 1 request
            Providers.Add("binance", new ExchangeSharpRateProvider("binance", new ExchangeBinanceAPI(), true));
            Providers.Add("bittrex", new ExchangeSharpRateProvider("bittrex", new ExchangeBittrexAPI(), true));
            Providers.Add("poloniex", new ExchangeSharpRateProvider("poloniex", new ExchangePoloniexAPI(), true));
            Providers.Add("hitbtc", new ExchangeSharpRateProvider("hitbtc", new ExchangeHitBTCAPI(), true));
            Providers.Add("ndax", new ExchangeSharpRateProvider("ndax", new ExchangeNDAXAPI(), true));

            // Handmade providers
            Providers.Add(CoinGeckoRateProvider.CoinGeckoName, new CoinGeckoRateProvider(_httpClientFactory));
            Providers.Add(CoinAverageRateProvider.CoinAverageName, new CoinAverageRateProvider()
            {
                Exchange = CoinAverageRateProvider.CoinAverageName, HttpClient = _httpClientFactory?.CreateClient("EXCHANGE_COINAVERAGE"), Authenticator = _CoinAverageSettings
            });
            Providers.Add("kraken", new KrakenExchangeRateProvider()
            {
                HttpClient = _httpClientFactory?.CreateClient("EXCHANGE_KRAKEN")
            });
            Providers.Add("bylls", new ByllsRateProvider(_httpClientFactory?.CreateClient("EXCHANGE_BYLLS")));
            Providers.Add("bitbank", new BitbankRateProvider(_httpClientFactory?.CreateClient("EXCHANGE_BITBANK")));
            Providers.Add("bitpay", new BitpayRateProvider(_httpClientFactory?.CreateClient("EXCHANGE_BITPAY")));

            // Those exchanges make multiple requests when calling GetTickers so we remove them
            //DirectProviders.Add("gemini", new ExchangeSharpRateProvider("gemini", new ExchangeGeminiAPI()));
            //DirectProviders.Add("bitfinex", new ExchangeSharpRateProvider("bitfinex", new ExchangeBitfinexAPI()));
            //DirectProviders.Add("okex", new ExchangeSharpRateProvider("okex", new ExchangeOkexAPI()));
            //DirectProviders.Add("bitstamp", new ExchangeSharpRateProvider("bitstamp", new ExchangeBitstampAPI()));

            foreach (var provider in Providers.ToArray())
            {
                if (provider.Key == "cryptopia") // Shitty exchange, rate often unavailable, it spams the logs
                {
                    continue;
                }
                var prov = new BackgroundFetcherRateProvider(provider.Key, Providers[provider.Key]);
                if (provider.Key == CoinGeckoRateProvider.CoinGeckoName)
                {
                    prov.RefreshRate  = CacheSpan;
                    prov.ValidatyTime = CacheSpan + TimeSpan.FromMinutes(1.0);
                }
                else
                {
                    prov.RefreshRate  = TimeSpan.FromMinutes(1.0);
                    prov.ValidatyTime = TimeSpan.FromMinutes(5.0);
                }
                Providers[provider.Key] = prov;
            }

            var cache = new MemoryCache(_CacheOptions);

            foreach (var supportedExchange in GetCoinGeckoSupportedExchanges())
            {
                if (!Providers.ContainsKey(supportedExchange.Id))
                {
                    var coinAverage = new CoinGeckoRateProvider(_httpClientFactory)
                    {
                        Exchange = supportedExchange.Id
                    };
                    var cached = new CachedRateProvider(supportedExchange.Id, coinAverage, cache)
                    {
                        CacheSpan = CacheSpan
                    };
                    Providers.Add(supportedExchange.Id, cached);
                }
            }
            foreach (var supportedExchange in GetCoinAverageSupportedExchanges())
            {
                if (!Providers.ContainsKey(supportedExchange.Id))
                {
                    var coinAverage = new CoinGeckoRateProvider(_httpClientFactory)
                    {
                        Exchange = supportedExchange.Id
                    };
                    var cached = new CachedRateProvider(supportedExchange.Id, coinAverage, cache)
                    {
                        CacheSpan = CacheSpan
                    };
                    Providers.Add(supportedExchange.Id, cached);
                }
            }
        }