示例#1
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);
            var r   = await api.GetTickersAsync().ConfigureAwait(false);

            var prices = new MarketPrices();

            //Treats results as dictionary just incase the API add more asset pairs later on.
            var rPairsDict     = r.ToDictionary(x => x.ticker.ToAssetPair(this, 3), x => x);
            var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs;

            foreach (var pair in pairsQueryable)
            {
                rPairsDict.TryGetValue(pair, out var currentTicker);

                if (currentTicker == null)
                {
                    prices.MissedPairs.Add(pair);
                }
                else
                {
                    prices.Add(new MarketPrice(Network, pair, currentTicker.last_traded_price)
                    {
                        PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.ask, currentTicker.bid, currentTicker.low, currentTicker.high),
                        Volume          = new NetworkPairVolume(Network, pair, currentTicker.total_volume_24h)
                    });
                }
            }

            return(prices);
        }
示例#2
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);

            var rRaw = await api.GetTickersAsync().ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = ParseTicker(rRaw);

            var prices   = new MarketPrices();
            var krwAsset = Asset.Krw;

            foreach (var pair in context.Pairs)
            {
                var ticker = new CoinoneSchema.TickerEntryResponse();
                if (!r.TryGetValue(pair.Asset1.ShortCode.ToLower(), out ticker) || !pair.Asset2.Equals(krwAsset))
                {
                    prices.MissedPairs.Add(pair);
                    continue;
                }

                prices.Add(new MarketPrice(Network, pair, ticker.last));
            }

            return(prices);
        }
示例#3
0
        public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);
            var r   = await api.GetLastPricesAsync().ConfigureAwait(false);

            CheckResponseError(r);

            var dictPairsPrices = r.data.ToDictionary(x => new AssetPair(x.symbol1, x.symbol2, this), x => x);
            var pairsQueryable  = context.IsRequestAll ? dictPairsPrices.Keys.ToList() : context.Pairs;

            var prices = new MarketPrices();

            foreach (var pair in pairsQueryable)
            {
                if (!dictPairsPrices.TryGetValue(pair, out var rPair))
                {
                    prices.MissedPairs.Add(pair);
                    continue;
                }

                prices.Add(new MarketPrice(Network, pair, rPair.lprice));
            }

            return(prices);
        }
示例#4
0
        public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);
            var r   = await api.GetLatestPricesAsync().ConfigureAwait(false);

            var pairsDict = r.ToDictionary(x => new AssetPair(x.underlying, x.quoteCurrency, this), x => x);

            var pairsQueryable = context.IsRequestAll
                ? pairsDict.Keys.ToList()
                : context.Pairs;

            var prices = new MarketPrices();

            foreach (var pair in pairsQueryable)
            {
                if (!pairsDict.TryGetValue(pair, out var data) || data.lastPrice.HasValue == false)
                {
                    prices.MissedPairs.Add(pair);
                    continue;
                }

                prices.Add(new MarketPrice(Network, pair, data.lastPrice.Value)
                {
                    PriceStatistics = new PriceStatistics(Network, pair.Asset2, data.askPrice, data.bidPrice, data.lowPrice, data.highPrice),
                    Volume          = new NetworkPairVolume(Network, pair, data.volume24h)
                });
            }

            return(prices);
        }
示例#5
0
        public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);
            var r   = await api.GetTickersAsync().ConfigureAwait(false);

            if (r == null || r.responseStatus?.message?.Equals("OK", StringComparison.InvariantCultureIgnoreCase) == false || r.tickers == null || r.tickers.Length == 0)
            {
                throw new ApiResponseException("No tickers returned", this);
            }

            var prices = new MarketPrices();

            var rPairsDict     = r.tickers.ToDictionary(x => x.currencyPair.ToAssetPair(this, 3), x => x);
            var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs;

            foreach (var pair in pairsQueryable)
            {
                rPairsDict.TryGetValue(pair, out var currentTicker);

                if (currentTicker == null)
                {
                    prices.MissedPairs.Add(pair);
                }
                else
                {
                    prices.Add(new MarketPrice(Network, pair, currentTicker.last)
                    {
                        PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.ask, currentTicker.bid, currentTicker.low, currentTicker.high),
                        Volume          = new NetworkPairVolume(Network, pair, currentTicker.volume)
                    });
                }
            }

            return(prices);
        }
示例#6
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);
            var r   = await api.GetTickersAsync().ConfigureAwait(false);

            if (r == null || r.Count == 0)
            {
                throw new ApiResponseException("No tickers returned", this);
            }

            var prices = new MarketPrices();

            var rPairsDict     = r.Values.ToDictionary(x => new AssetPair(x.primary_currency, x.secondary_currency, this), x => x);
            var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs;

            foreach (var pair in pairsQueryable)
            {
                rPairsDict.TryGetValue(pair, out var currentTicker);

                if (currentTicker == null)
                {
                    prices.MissedPairs.Add(pair);
                }
                else
                {
                    prices.Add(new MarketPrice(Network, pair, 1 / currentTicker.last_price)
                    {
                        PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.orderbook.asks.highbid, currentTicker.orderbook.bids.highbid),
                        Volume          = new NetworkPairVolume(Network, pair, currentTicker.volume_24hours)
                    });
                }
            }

            return(prices);
        }
示例#7
0
        public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var products = await GetAllProductsAsync().ConfigureAwait(false);

            var prices = new MarketPrices();

            var rPairsDict     = products.ToDictionary(x => x.currency_pair_code.ToAssetPair(this, 3), x => x);
            var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs;

            foreach (var pair in pairsQueryable)
            {
                rPairsDict.TryGetValue(pair, out var currentTicker);

                if (currentTicker == null)
                {
                    prices.MissedPairs.Add(pair);
                }
                else
                {
                    prices.Add(new MarketPrice(Network, pair, (decimal?)currentTicker.last_traded_price ?? 0)
                    {
                        PriceStatistics = new PriceStatistics(Network, pair.Asset2, (decimal)currentTicker.high_market_ask, (decimal)currentTicker.low_market_bid),
                        Volume          = new NetworkPairVolume(Network, pair, currentTicker.volume_24h)
                    });
                }
            }

            return(prices);
        }
示例#8
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);

            var pairsCsv = string.Join(",", context.Pairs.Select(x => x.ToTicker(this, "")));

            var r = await api.GetTickerInformationAsync(pairsCsv).ConfigureAwait(false);

            CheckResponseErrors(r);

            var prices = new MarketPrices();

            foreach (var pair in context.Pairs)
            {
                var rTicker = r.result.Where(x => ComparePairs(pair, x.Key)).ToArray();

                if (!rTicker.Any())
                {
                    prices.MissedPairs.Add(pair);
                    continue;
                }

                var ticker = rTicker.First().Value;

                prices.Add(new MarketPrice(Network, pair, ticker.c[0])
                {
                    PriceStatistics = new PriceStatistics(Network, pair.Asset2, ticker.a[0], ticker.b[0], ticker.l[1], ticker.h[1]),
                    Volume          = new NetworkPairVolume(Network, pair, ticker.v[1])
                });
            }

            return(prices);
        }
示例#9
0
        public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);
            var r   = await api.GetTickersAsync().ConfigureAwait(false);

            if (r?.Count == 0)
            {
                throw new ApiResponseException("No tickers returned", this);
            }

            var prices = new MarketPrices();

            var rPairsDict     = r.ToDictionary(x => x.Key.ToAssetPair(this), x => x.Value);
            var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs;

            foreach (var pair in pairsQueryable)
            {
                rPairsDict.TryGetValue(pair, out var currentTicker);

                if (currentTicker == null)
                {
                    prices.MissedPairs.Add(pair);
                }
                else
                {
                    prices.Add(new MarketPrice(Network, pair, currentTicker.last)
                    {
                        PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.lowestAsk, currentTicker.highestBid, currentTicker.low24hr, currentTicker.high24hr),
                        Volume          = new NetworkPairVolume(Network, pair, currentTicker.baseVolume, currentTicker.quoteVolume)
                    });
                }
            }

            return(prices);
        }
示例#10
0
        private async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);

            var r = await api.GetMarketInfos().ConfigureAwait(false);

            var pairsDict = r.ToDictionary(x => x.pair.ToAssetPair(this), x => x);

            var pairsQueryable = context.IsRequestAll
                ? pairsDict.Keys.ToArray()
                : context.Pairs;

            var prices = new MarketPrices();

            foreach (var pair in pairsQueryable)
            {
                if (!pairsDict.TryGetValue(pair, out var price))
                {
                    prices.MissedPairs.Add(pair);
                    continue;
                }

                prices.Add(new MarketPrice(Network, pair, price.rate));
            }

            return(prices);
        }
示例#11
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);
            var r   = await api.GetTickersAsync().ConfigureAwait(false);

            if (r == null || r.Count == 0)
            {
                throw new ApiResponseException("No tickers returned", this);
            }

            var prices = new MarketPrices();

            var pairsQueryable = context.IsRequestAll ? r.Keys.Select(x => x.ToAssetPair(this, 3)).ToList() : context.Pairs;

            foreach (var pair in pairsQueryable)
            {
                r.TryGetValue(pair.ToTicker(this).ToLower(), out var currentTicker);

                if (currentTicker == null)
                {
                    prices.MissedPairs.Add(pair);
                }
                else
                {
                    prices.Add(new MarketPrice(Network, pair, currentTicker.last)
                    {
                        PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.ask, currentTicker.bid, currentTicker.low, currentTicker.high),
                        Volume          = new NetworkPairVolume(Network, pair, currentTicker.volume)
                    });
                }
            }

            return(prices);
        }
示例#12
0
        private async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var privateCtx = new NetworkProviderPrivateContext(UserContext.Current);
            var api        = ApiProvider.GetApi(privateCtx);

            var pairsCsv = string.Join(",", context.Pairs.Select(x => x.ToTicker(this)));

            var r = await api.GetPrices(pairsCsv).ConfigureAwait(false);

            var prices = new MarketPrices();

            foreach (var pair in context.Pairs)
            {
                if (!r.TryGetValue(pair.ToTicker(this), out var price))
                {
                    prices.MissedPairs.Add(pair);
                    continue;
                }

                prices.Add(new MarketPrice(Network, pair, (price.ask + price.bid) / 2)
                {
                    PriceStatistics = new PriceStatistics(Network, pair.Asset2, price.ask, price.bid)
                });
            }

            return(prices);
        }
示例#13
0
        public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var r = await ApiProvider.GetTickersAsync().ConfigureAwait(false);

            if (r == null || r.Length == 0)
            {
                throw new ApiResponseException("No tickers returned", this);
            }

            var prices = new MarketPrices();

            var rPairsDict     = r.ToDictionary(x => x.Symbol.ToAssetPair(this, 3), x => x);
            var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs;

            foreach (var pair in pairsQueryable)
            {
                rPairsDict.TryGetValue(pair, out var currentTicker);

                if (currentTicker == null)
                {
                    prices.MissedPairs.Add(pair);
                }
                else
                {
                    prices.Add(new MarketPrice(Network, pair, currentTicker.LastBuyPrice)
                    {
                        PriceStatistics = new PriceStatistics(Network, pair.Asset2, r[0].BestAsk, r[0].BestBid),
                        Volume          = new NetworkPairVolume(Network, pair, r[0].DailyTradedTotalVolume)
                    });
                }
            }

            return(prices);
        }
示例#14
0
        protected virtual async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var api      = ApiProviderPublic.GetApi(context);
            var pairsCsv = string.Join("-", context.Pairs.Select(x => x.ToTicker(this).ToLower()));
            var r        = await api.GetTickerAsync(pairsCsv).ConfigureAwait(false);

            if (r == null || r.Count == 0)
            {
                throw new ApiResponseException("No tickers returned", this);
            }

            var prices = new MarketPrices();

            foreach (var pair in context.Pairs)
            {
                var currentTicker = r.FirstOrDefault(x => x.Key.ToAssetPair(this).Equals(pair)).Value;

                if (currentTicker == null)
                {
                    prices.MissedPairs.Add(pair);
                }
                else
                {
                    prices.Add(new MarketPrice(Network, pair, currentTicker.last)
                    {
                        PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.sell, currentTicker.buy, currentTicker.low, currentTicker.high),
                        Volume          = new NetworkPairVolume(Network, pair, currentTicker.vol)
                    });
                }
            }

            return(prices);
        }
示例#15
0
        public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);
            var r   = await api.GetTickersAsync().ConfigureAwait(false);

            if (r.success == false || r.data == null)
            {
                throw new ApiResponseException(r.msg, this);
            }

            var prices = new MarketPrices();

            var rPairsDict     = r.data.ToDictionary(x => x.symbol.ToAssetPair(this), x => x);
            var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs;

            foreach (var pair in pairsQueryable)
            {
                rPairsDict.TryGetValue(pair, out var currentTicker);

                if (currentTicker == null)
                {
                    prices.MissedPairs.Add(pair);
                }
                else
                {
                    prices.Add(new MarketPrice(Network, pair, currentTicker.lastDealPrice)
                    {
                        PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.sell, currentTicker.buy, currentTicker.low, currentTicker.high),
                        Volume          = new NetworkPairVolume(Network, pair, currentTicker.vol)
                    });
                }
            }

            return(prices);
        }
示例#16
0
        public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);
            var r   = await api.GetMarketSummariesAsync().ConfigureAwait(false);

            CheckResponseErrors(r);

            var rPairsDict = r.result.ToDictionary(x => x.MarketName.ToAssetPair(this), x => x);

            var pairsQueryable = context.IsRequestAll
                ? rPairsDict.Keys.ToList()
                : context.Pairs;

            var prices = new MarketPrices();

            foreach (var pair in pairsQueryable)
            {
                if (!rPairsDict.TryGetValue(pair, out var e))
                {
                    prices.MissedPairs.Add(pair);
                    continue;
                }

                prices.Add(new MarketPrice(Network, pair, 1 / e.Last)
                {
                    PriceStatistics = new PriceStatistics(Network, pair.Asset2, e.Ask, e.Bid, e.Low, e.High),
                    Volume          = new NetworkPairVolume(Network, pair, e.BaseVolume, e.Volume)
                });
            }

            return(prices);
        }
示例#17
0
        public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);
            var r   = await api.GetTickersAsync().ConfigureAwait(false);

            if (r?.tickers == null || r.tickers.Length == 0)
            {
                throw new ApiResponseException("No tickers returned", this);
            }

            var prices = new MarketPrices();

            var rPairsDict     = r.tickers.ToDictionary(x => x.pair.ToAssetPair(this, 3), x => x);
            var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs;

            foreach (var pair in pairsQueryable)
            {
                rPairsDict.TryGetValue(pair, out var currentTicker);

                if (currentTicker == null)
                {
                    prices.MissedPairs.Add(pair);
                }
                else
                {
                    prices.Add(new MarketPrice(Network, pair, currentTicker.last_trade)
                    {
                        PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.ask, currentTicker.bid),
                        Volume          = new NetworkPairVolume(Network, pair, currentTicker.rolling_24_hour_volume)
                    });
                }
            }

            return(prices);
        }
示例#18
0
        public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);
            var r   = await api.GetSymbolPriceTickerAsync().ConfigureAwait(false);

            var prices     = new MarketPrices();
            var knownPairs = new AssetPairs();

            if (context.IsRequestAll)
            {
                foreach (var rPrice in r.OrderBy(x => x.symbol.Length))
                {
                    var tPair = AssetsUtilities.GetAssetPair(rPrice.symbol, knownPairs);

                    if (!tPair.HasValue)
                    {
                        continue;
                    }

                    var pair = new AssetPair(tPair.Value.AssetCode1, tPair.Value.AssetCode2, this);

                    knownPairs.Add(pair);

                    prices.Add(new MarketPrice(Network, pair, rPrice.price));
                }
            }
            else
            {
                foreach (var pair in context.Pairs)
                {
                    var lowerPairTicker = pair.ToTicker(this).ToLower();

                    var lpr = r.FirstOrDefault(x => x.symbol.ToLower().Equals(lowerPairTicker));

                    if (lpr == null)
                    {
                        prices.MissedPairs.Add(pair);
                        continue;
                    }

                    prices.Add(new MarketPrice(Network, pair, lpr.price));
                }
            }

            return(prices);
        }
示例#19
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var rates = await GetRatesAsync().ConfigureAwait(false);

            var lp = new MarketPrices();

            foreach (var pair in context.Pairs)
            {
                var rate = rates.FirstOrDefault(x => Equals(x.Key, pair));
                if (rate.Key == null)
                {
                    continue;
                }

                lp.Add(new MarketPrice(Network, rate.Key, rate.Value));
            }

            return(lp);
        }
示例#20
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var api   = GetApi <ICryptoCompareApi>();
            var froms = string.Join(",", context.Pairs.Select(x => x.Asset1).Distinct().Select(x => x.ShortCode));
            var tos   = string.Join(",", context.Pairs.Select(x => x.Asset2).Distinct().Select(x => x.ShortCode));
            var str   = await api.GetPricesAsync(froms, tos, Name, "prime", "false", "false").ConfigureAwait(false);

            if (str.Contains("market does not exist for this coin pair"))
            {
                throw new AssetPairNotSupportedException(context.Pair, this);
            }

            var apir   = JsonConvert.DeserializeObject <CryptoCompareSchema.PriceMultiResult>(str);
            var prices = new MarketPrices();

            foreach (var i in context.Pairs)
            {
                var a1 = i.Asset1.ShortCode.ToLower();
                var k  = apir.FirstOrDefault(x => x.Key.ToLower() == a1);

                if (k.Key == null)
                {
                    prices.MissedPairs.Add(i);
                    continue;
                }

                var a2 = i.Asset2.ShortCode.ToLower();
                var r  = k.Value.FirstOrDefault(x => x.Key.ToLower() == a2);

                if (r.Key == null)
                {
                    prices.MissedPairs.Add(i);
                    continue;
                }

                prices.Add(new MarketPrice(Network, i, (decimal)r.Value));
            }

            return(prices);
        }
示例#21
0
        public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);
            var r   = await api.GetAllTickers().ConfigureAwait(false);

            var prices = new MarketPrices();

            var rPairsDict     = r.ToDictionary(x => x.Key.ToAssetPair(this), x => x.Value);
            var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs;

            foreach (var pair in pairsQueryable)
            {
                rPairsDict.TryGetValue(pair, out var currentTicker);

                if (currentTicker == null)
                {
                    prices.MissedPairs.Add(pair);
                }
                else
                {
                    if (currentTicker.last != null)
                    {
                        prices.Add(new MarketPrice(Network, pair, currentTicker.last.Value)
                        {
                            PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.sell,
                                                                  currentTicker.buy, currentTicker.low, currentTicker.high),
                            Volume = new NetworkPairVolume(Network, pair, currentTicker.volume_left,
                                                           currentTicker.volume_right)
                        });
                    }
                    else
                    {
                        prices.MissedPairs.Add(pair);
                    }
                }
            }

            return(prices);
        }
示例#22
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var api  = ApiProvider.GetApi(context);
            var rRaw = await api.GetTickerAsync().ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            var rPaired        = r.ToDictionary(x => x.Key.ToAssetPair(this), y => y.Value);
            var pairsQueryable = context.IsRequestAll ? rPaired.Select(x => x.Key) : context.Pairs;

            var prices = new MarketPrices();

            foreach (var pair in pairsQueryable)
            {
                var rTickers = rPaired.Where(x => x.Key.Equals(pair)).ToList();

                if (rTickers.Count == 0)
                {
                    prices.MissedPairs.Add(pair);
                    continue;
                }

                var rTicker = rTickers[0];
                var v       = rTicker.Value;

                var price = new MarketPrice(Network, pair.Reversed, v.last)
                {
                    PriceStatistics = new PriceStatistics(Network, pair.Asset2, v.lowestAsk, v.highestBid, v.low24hr, v.high24hr),
                    Volume          = new NetworkPairVolume(Network, pair, v.baseVolume, v.quoteVolume)
                };

                prices.Add(price.Reversed);
            }

            return(prices);
        }
示例#23
0
        public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var api  = ApiProvider.GetApi(context);
            var rRaw = await api.GetTickersAsync().ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = ParseTickerResponse(rRaw);

            var krwAsset = Asset.Krw;

            var prices = new MarketPrices();

            var pairsQueryable = context.IsRequestAll
                ? r.Select(x => new AssetPair(x.Key.ToAsset(this), krwAsset)).ToList()
                : context.Pairs;

            foreach (var pair in pairsQueryable)
            {
                var rTickers = r.Where(x => x.Key.ToAsset(this).Equals(pair.Asset1)).ToArray();
                if (!rTickers.Any() || !pair.Asset2.Equals(krwAsset))
                {
                    prices.MissedPairs.Add(pair);
                    continue;
                }

                var rTicker = rTickers[0];
                var vals    = rTicker.Value;
                prices.Add(new MarketPrice(Network, pair, vals.sell_price)
                {
                    Volume          = new NetworkPairVolume(Network, pair, vals.volume_1day),
                    PriceStatistics = new PriceStatistics(Network, pair.Asset2, null, null, vals.min_price, vals.max_price)
                });
            }

            return(prices);
        }
示例#24
0
        public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);
            var r   = await api.GetTickersAsync().ConfigureAwait(false);

            if (r.success)
            {
                var prices = new MarketPrices();

                var pairsQueryable = context.IsRequestAll ? r.payload.Select(x => x.book.ToAssetPair(this)) : context.Pairs;

                foreach (var pair in pairsQueryable)
                {
                    var currentTicker = r.payload.FirstOrDefault(x => x.book.ToAssetPair(this).Equals(pair));

                    if (currentTicker == null)
                    {
                        prices.MissedPairs.Add(pair);
                    }
                    else
                    {
                        prices.Add(new MarketPrice(Network, pair, currentTicker.last)
                        {
                            PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.ask,
                                                                  currentTicker.bid, currentTicker.low, currentTicker.high),
                            Volume = new NetworkPairVolume(Network, pair, currentTicker.volume)
                        });
                    }
                }

                return(prices);
            }
            else
            {
                throw new ApiResponseException("Error processing request", this);
            }
        }