示例#1
0
        public async Task <bool> TestPublicApiAsync(NetworkProviderContext context)
        {
            var api = ApiProviderPublic.GetApi(context);
            var r   = await api.GetAssetPairsAsync().ConfigureAwait(false);

            return(r.pairs?.Count > 0);
        }
示例#2
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = ApiProviderPublic.GetApi(context);
            var pairCode = context.Pair.ToTicker(this).ToLower();

            var r = await api.GetOrderBookAsync(pairCode).ConfigureAwait(false);

            var orderBook = new OrderBook(Network, context.Pair);

            r.TryGetValue(pairCode, out var currentOrderBook);

            if (currentOrderBook == null)
            {
                throw new ApiResponseException("No order book returned", this);
            }

            var maxCount = Math.Min(1000, context.MaxRecordsCount);

            var asks = currentOrderBook.asks.Take(maxCount);
            var bids = currentOrderBook.bids.Take(maxCount);

            foreach (var i in bids.Select(GetBidAskData))
            {
                orderBook.AddBid(i.Item1, i.Item2, true);
            }

            foreach (var i in asks.Select(GetBidAskData))
            {
                orderBook.AddAsk(i.Item1, i.Item2, true);
            }

            return(orderBook);
        }
示例#3
0
        public 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);
        }
示例#4
0
        public async Task <MarketPrices> GetPriceAsync(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 ticker = r.FirstOrDefault().Value;

            if (ticker != null)
            {
                return(new MarketPrices(new MarketPrice(Network, context.Pair, ticker.last)
                {
                    PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, ticker.sell, ticker.buy, ticker.low, ticker.high),
                    Volume = new NetworkPairVolume(Network, context.Pair, ticker.vol)
                }));
            }
            else
            {
                throw new ApiResponseException("No data returned", this);
            }
        }
示例#5
0
        public async Task <AssetPairs> GetAssetPairsAsync(NetworkProviderContext context)
        {
            var api = ApiProviderPublic.GetApi(context);

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

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

            var pairs = new AssetPairs();

            foreach (var rCurrentTicker in r.pairs)
            {
                pairs.Add(rCurrentTicker.Key.ToAssetPair(this, 3));
            }

            return(pairs);
        }
示例#6
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var api      = ApiProviderPublic.GetApi(context);
            var pairCode = context.Pair.ToTicker(this).ToLower();
            var r        = await api.GetTickerAsync(pairCode).ConfigureAwait(false);

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

            r.TryGetValue(pairCode, out var currentTicker);

            if (currentTicker == null)
            {
                throw new ApiResponseException("No ticker returned", this);
            }

            return(new MarketPrices(new MarketPrice(Network, context.Pair, currentTicker.last)
            {
                PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, currentTicker.sell, currentTicker.buy, currentTicker.low, currentTicker.high),
                Volume = new NetworkPairVolume(Network, context.Pair, currentTicker.vol)
            }));
        }