Example #1
0
        public async Task <ExchangeRates> GetRatesAsync()
        {
            var result  = new ExchangeRates();
            var symbols = await GetSymbolsAsync();

            var    normalizedPairsList = symbols.Where(s => !notFoundSymbols.ContainsKey(s)).Select(s => _Helper.NormalizeSymbol(s)).ToList();
            var    csvPairsList        = string.Join(",", normalizedPairsList);
            JToken apiTickers          = await MakeJsonRequestAsync <JToken>("/0/public/Ticker", null, new Dictionary <string, object> {
                { "pair", csvPairsList }
            });

            var tickers = new List <KeyValuePair <string, ExchangeTicker> >();

            foreach (string symbol in symbols)
            {
                var ticker = ConvertToExchangeTicker(symbol, apiTickers[symbol]);
                if (ticker != null)
                {
                    try
                    {
                        string global  = null;
                        var    mapped1 = _TickerMapping.Where(t => symbol.StartsWith(t.Key, StringComparison.OrdinalIgnoreCase))
                                         .Select(t => new { KrakenTicker = t.Key, PayTicker = t.Value }).SingleOrDefault();
                        if (mapped1 != null)
                        {
                            var p2 = symbol.Substring(mapped1.KrakenTicker.Length);
                            if (_TickerMapping.TryGetValue(p2, out var mapped2))
                            {
                                p2 = mapped2;
                            }
                            global = $"{p2}_{mapped1.PayTicker}";
                        }
                        else
                        {
                            global = _Helper.ExchangeSymbolToGlobalSymbol(symbol);
                        }
                        if (CurrencyPair.TryParse(global, out var pair))
                        {
                            result.Add(new ExchangeRate("kraken", pair.Inverse(), new BidAsk(ticker.Bid, ticker.Ask)));
                        }
                        else
                        {
                            notFoundSymbols.TryAdd(symbol, symbol);
                        }
                    }
                    catch (ArgumentException)
                    {
                        notFoundSymbols.TryAdd(symbol, symbol);
                    }
                }
            }
            return(result);
        }
Example #2
0
        public async Task <ExchangeRates> GetRatesAsync()
        {
            var result  = new ExchangeRates();
            var symbols = await GetSymbolsAsync();

            var    normalizedPairsList = symbols.Where(s => !notFoundSymbols.ContainsKey(s)).Select(s => _Helper.NormalizeSymbol(s)).ToList();
            var    csvPairsList        = string.Join(",", normalizedPairsList);
            JToken apiTickers          = await MakeJsonRequestAsync <JToken>("/0/public/Ticker", null, new Dictionary <string, object> {
                { "pair", csvPairsList }
            });

            var tickers = new List <KeyValuePair <string, ExchangeTicker> >();

            foreach (string symbol in symbols)
            {
                var ticker = ConvertToExchangeTicker(symbol, apiTickers[symbol]);
                if (ticker != null)
                {
                    try
                    {
                        string global = null;
                        if (symbol.StartsWith("DASH", StringComparison.OrdinalIgnoreCase))
                        {
                            var p2 = symbol.Substring(4);
                            p2     = p2 == "XBT" ? "BTC" : p2;
                            global = $"{p2}_{symbol.Substring(0, 4)}";
                        }
                        else
                        {
                            global = _Helper.ExchangeSymbolToGlobalSymbol(symbol);
                        }
                        if (CurrencyPair.TryParse(global, out var pair))
                        {
                            result.Add(new ExchangeRate("kraken", pair.Inverse(), new BidAsk(ticker.Bid, ticker.Ask)));
                        }
                        else
                        {
                            notFoundSymbols.TryAdd(symbol, symbol);
                        }
                    }
                    catch (ArgumentException)
                    {
                        notFoundSymbols.TryAdd(symbol, symbol);
                    }
                }
            }
            return(result);
        }