예제 #1
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api = ApiPublicProvider.GetApi(context);

            var r = await api.GetOrderBookAsync(context.Pair.Asset2.ShortCode, context.Pair.Asset1.ShortCode).ConfigureAwait(false);

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

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

            var asks = r.asks.Take(maxCount);
            var bids = r.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);
        }
예제 #2
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var api = ApiPublicProvider.GetApi(context);
            var r   = await api.GetTickerAsync(context.Pair.Asset2.ShortCode, context.Pair.Asset1.ShortCode).ConfigureAwait(false);

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

            r.TryGetValue("high", out var high);
            r.TryGetValue("vol", out var vol);
            r.TryGetValue("buy", out var buy);
            r.TryGetValue("last", out var last);
            r.TryGetValue("low", out var low);
            r.TryGetValue("pair", out var pair);
            r.TryGetValue("sell", out var sell);
            r.TryGetValue("vol_" + context.Pair.Asset2.ShortCode.ToLower(), out var volFiat);

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