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 { var 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); }
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); }