Esempio n. 1
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this, '_');

            var rRaw = context.MaxRecordsCount == Int32.MaxValue
                ? await api.GetOrderBookAsync(pairCode).ConfigureAwait(false)
                : await api.GetOrderBookAsync(pairCode, context.MaxRecordsCount).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            if (r.bids == null || r.asks == null)
            {
                throw new AssetPairNotSupportedException(context.Pair, this);
            }

            var orderBook = new OrderBook(Network, context.Pair.Reversed); //POLONIEX IS REVERSING THE MARKET

            foreach (var i in r.bids)
            {
                orderBook.AddBid(i[0], i[1], true); //HH: Confirmed reversed on https://poloniex.com/exchange#btc_btcd
            }
            foreach (var i in r.asks)
            {
                orderBook.AddAsk(i[0], i[1], true);
            }

            return(orderBook.AsPair(context.Pair));
        }
Esempio n. 2
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api = ApiProvider.GetApi(context);

            var pairCode = context.Pair.ToTicker(this);

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

            CheckResponseErrors(rRaw, context.Pair);

            var r = rRaw.GetContent();

            var orderBook = new OrderBook(Network, context.Pair.Reversed); //HH: This is the reversed pair that is returned.

            var bids = context.MaxRecordsCount == Int32.MaxValue
                ? r.result.buy
                : r.result.buy.Take(context.MaxRecordsCount);
            var asks = context.MaxRecordsCount == Int32.MaxValue
                ? r.result.sell
                : r.result.sell.Take(context.MaxRecordsCount);

            foreach (var i in bids)
            {
                orderBook.AddBid(i.Rate, i.Quantity, true); //HH:CONFIRMED INVERTED ON https://bittrex.com/Market/Index?MarketName=BTC-BTCD
            }
            foreach (var i in asks)
            {
                orderBook.AddAsk(i.Rate, i.Quantity, true);
            }

            return(orderBook.AsPair(context.Pair));
        }
Esempio n. 3
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api = ApiProvider.GetApi(context);

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

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

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

            if (!context.Pair.Equals(new AssetPair("BTC", "GLD", this)))
            {
                throw new AssetPairNotSupportedException(context.Pair, this);
            }

            if (!r.status.Equals("success", StringComparison.OrdinalIgnoreCase))
            {
                throw new ApiResponseException("Error obtaining order books");
            }

            VaultoroSchema.OrderBookItemResponse[] arrAsks = null;
            VaultoroSchema.OrderBookItemResponse[] arrBids = null;

            foreach (var entry in r.data)
            {
                if (entry.b != null && entry.b.Length > 0)
                {
                    arrBids = entry.b;
                }

                if (entry.s != null && entry.s.Length > 0)
                {
                    arrAsks = entry.s;
                }
            }

            if (arrAsks == null || arrBids == null)
            {
                throw new ApiResponseException("No order books found");
            }

            foreach (var i in arrBids.Take(maxCount))
            {
                orderBook.AddBid(i.Gold_Price, i.Gold_Amount, true);
            }

            foreach (var i in arrAsks.Take(maxCount))
            {
                orderBook.AddAsk(i.Gold_Price, i.Gold_Amount, true);
            }

            return(orderBook.AsPair(context.Pair));
        }