Example #1
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this).ToLower();

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

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

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

            if (r.message.Equals("ok", StringComparison.InvariantCultureIgnoreCase) == false || r.result == null)
            {
                throw new ApiResponseException(r.message);
            }

            var response = r.result;

            var asks = response.asks.Take(maxCount);
            var bids = response.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);
        }
Example #2
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this).ToLower();

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

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

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

            r.TryGetValue(pairCode, out var response);

            if (response == null)
            {
                throw new ApiResponseException("No depth info found");
            }

            var asks = response.sells.Take(maxCount);
            var bids = response.buys.Take(maxCount);

            foreach (var i in bids)
            {
                orderBook.AddBid(i, 0, true);
            }

            foreach (var i in asks)
            {
                orderBook.AddAsk(i, 0, true);
            }

            return(orderBook);
        }
Example #3
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, false).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

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

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

            var response = r.data;

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

            foreach (var i in bids)
            {
                orderBook.AddBid(i.price, i.amount, true);
            }

            foreach (var i in asks)
            {
                orderBook.AddAsk(i.price, i.amount, true);
            }

            return(orderBook);
        }
Example #4
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var maxValidCount = OrderBookValidRecordsCount.Max();
            var recordsCount  = context.MaxRecordsCount == Int32.MaxValue ? maxValidCount : context.MaxRecordsCount;

            CheckOrderRecordsInputNumber(recordsCount);

            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this);

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

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

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

            foreach (var i in r.bids.Select(GetOrderBookRecordData))
            {
                orderBook.AddBid(i.Price, i.Volume, true);
            }

            foreach (var i in r.asks.Select(GetOrderBookRecordData))
            {
                orderBook.AddAsk(i.Price, i.Volume, true);
            }

            return(orderBook);
        }
Example #5
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api = ApiProvider.GetApi(context);

            if (context.Pair.Equals(new AssetPair("BTC", "JPY")) == false)
            {
                throw new ApiResponseException("Invalid asset pair - only btc_jpy is supported.");
            }

            var r = await api.GetOrderBookAsync().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);
        }
Example #6
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this).ToLower();

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

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

            var maxCount = 1000;

            var asks = context.MaxRecordsCount == int.MaxValue ? r.asks.Take(maxCount) : r.asks.Take(context.MaxRecordsCount);
            var bids = context.MaxRecordsCount == int.MaxValue ? r.bids.Take(maxCount) : r.bids.Take(context.MaxRecordsCount);

            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);
        }
Example #7
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this);

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

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

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

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

            var asks = r.data.SELL.Take(maxCount);
            var bids = r.data.BUY.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);
        }
Example #8
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this, '_').ToLower();

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

            var bids = context.MaxRecordsCount.HasValue
                ? r.bids.Take(context.MaxRecordsCount.Value / 2)
                : r.bids;

            var asks = context.MaxRecordsCount.HasValue
                ? r.asks.Take(context.MaxRecordsCount.Value / 2)
                : r.asks;

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

            foreach (var i in bids)
            {
                orderBook.AddBid(i[0], i[1]);
            }

            foreach (var i in asks)
            {
                orderBook.AddAsk(i[0], i[1]);
            }

            return(orderBook);
        }
Example #9
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            if (context.Pair.Asset2.ToRemoteCode(this).Equals("BLR"))
            {
                var api = ApiProvider.GetApi(context);

                var r = await api.GetOrderBookAsync(context.Pair.Asset1.ToRemoteCode(this)).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);
            }
            else
            {
                throw new ApiResponseException("Quote asset must be BLR", this);
            }
        }
Example #10
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this, '_');

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

            var bids = context.MaxRecordsCount == Int32.MaxValue
                ? r.bids
                : r.bids.Take(context.MaxRecordsCount);

            var asks = context.MaxRecordsCount == Int32.MaxValue
                ? r.asks
                : r.asks.Take(context.MaxRecordsCount);

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

            foreach (var i in bids)
            {
                orderBook.AddBid(i.price, i.size);
            }

            foreach (var i in asks)
            {
                orderBook.AddAsk(i.price, i.size);
            }

            return(orderBook);
        }
Example #11
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this);

            //This API only accepts a depth of 100 maximum.
            var maxCount = Math.Min(100, context.MaxRecordsCount);

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

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

            if (r.success == false)
            {
                throw new ApiResponseException(r.message, this);
            }

            var response = r.result;

            var asks = response.sell;
            var bids = response.buy;

            foreach (var i in bids)
            {
                orderBook.AddBid(i.rate, i.quantity, true);
            }

            foreach (var i in asks)
            {
                orderBook.AddAsk(i.rate, i.quantity, true);
            }

            return(orderBook);
        }
Example #12
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);
        }
Example #13
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this);

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

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

            if (r == null || r.error || r.data == null)
            {
                throw new ApiResponseException(r.errorMessage, this);
            }

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

            var response = r.data;

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

            foreach (var i in bids)
            {
                orderBook.AddBid(i.price, i.amount, true);
            }

            foreach (var i in asks)
            {
                orderBook.AddAsk(i.price, i.amount, true);
            }

            return(orderBook);
        }
Example #14
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this).ToLower();

            var r = await api.GetOrderBookAsync(pairCode).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)
            {
                orderBook.AddBid(i.price, i.volume, true);
            }

            foreach (var i in asks)
            {
                orderBook.AddAsk(i.price, i.volume, true);
            }

            return(orderBook);
        }
Example #15
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var currency = context.Pair.Asset2.ShortCode.ToLower();

            var r = await api.GetOrderBookAsync(currency).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)
            {
                orderBook.AddBid(i.price, i.amount, true);
            }

            foreach (var i in asks)
            {
                orderBook.AddAsk(i.price, i.amount, true);
            }

            return(orderBook);
        }
Example #16
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));
        }
Example #17
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));
        }
Example #18
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api = ApiProvider.GetApi(context);

            var maxCountEmperical = 500;

            var r = context.MaxRecordsCount == Int32.MaxValue
                ? await api.GetOrderBookAsync(context.Pair.ToTicker(this), maxCountEmperical).ConfigureAwait(false)
                : await api.GetOrderBookAsync(context.Pair.ToTicker(this), context.MaxRecordsCount).ConfigureAwait(false);

            CheckResponseErrors(r);

            var data      = r.result.FirstOrDefault();
            var orderBook = new OrderBook(Network, context.Pair);

            var asks = data.Value.asks;
            var bids = data.Value.bids;

            foreach (var i in bids.Select(GetBidAskData))
            {
                orderBook.AddBid(i.Price, i.Volume);
            }

            foreach (var i in asks.Select(GetBidAskData))
            {
                orderBook.AddAsk(i.Price, i.Volume);
            }

            return(orderBook);
        }
Example #19
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = GdaxApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this);

            var r = await api.GetProductOrderBookAsync(pairCode, OrderBookDepthLevel.FullNonAggregated).ConfigureAwait(false);

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

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

            foreach (var i in bids.Select(ConvertToOrderBookRecord))
            {
                orderBook.AddBid(i.Price, i.Size);
            }

            foreach (var i in asks.Select(ConvertToOrderBookRecord))
            {
                orderBook.AddAsk(i.Price, i.Size);
            }

            return(orderBook);
        }
Example #20
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api = ApiProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "realCurrency", context.Pair.Asset2.ShortCode },
                { "cryptoCurrency", context.Pair.Asset1.ShortCode }
            };

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

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

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

            var asks = r.data.asks.Take(maxCount);
            var bids = r.data.bids.Take(maxCount);

            foreach (var i in bids)
            {
                orderBook.AddBid(i.price, i.amount, true);
            }

            foreach (var i in asks)
            {
                orderBook.AddAsk(i.price, i.amount, true);
            }

            return(orderBook);
        }
Example #21
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this);

            var body = new Dictionary <string, object>
            {
                { "productPair", pairCode }
            };

            var r = await api.GetOrderBookAsync(body).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)
            {
                orderBook.AddBid(i.px, i.qty, true);
            }

            foreach (var i in asks)
            {
                orderBook.AddAsk(i.px, i.qty, true);
            }

            return(orderBook);
        }
Example #22
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api = ApiProvider.GetApi(context);

            if (!context.Pair.Asset2.Equals(Asset.Krw))
            {
                throw new AssetPairNotSupportedException(context.Pair, this);
            }

            var r = context.MaxRecordsCount == Int32.MaxValue
                ? await api.GetOrderBookAsync(context.Pair.Asset1.ToRemoteCode(this)).ConfigureAwait(false)
                : await api.GetOrderBookAsync(context.Pair.Asset1.ToRemoteCode(this), context.MaxRecordsCount).ConfigureAwait(false);

            CheckResponseErrors(r);

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

            foreach (var rBid in r.data.bids)
            {
                orderBook.AddBid(rBid.price, rBid.quantity, true);
            }

            foreach (var rAsk in r.data.asks)
            {
                orderBook.AddAsk(rAsk.price, rAsk.quantity, true);
            }

            return(orderBook);
        }
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api = ApiProvider.GetApi(context);

            string pairCode = context.Pair.ToTicker(this);
            var    pairs    = pairCode.Split('_');

            if (pairs == null || pairs.Length < 2)
            {
                throw new ApiResponseException("Invalid asset pair passed as parameter");
            }

            var r = await api.GetOrderBookAsync(pairs[0].ToLower(), pairs[1].ToLower()).ConfigureAwait(false);

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

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

            var asks = r.SellOrders.Take(maxCount);
            var bids = r.BuyOrders.Take(maxCount);

            foreach (var i in bids)
            {
                orderBook.AddBid(i.Price, i.Volume, true);
            }

            foreach (var i in asks)
            {
                orderBook.AddAsk(i.Price, i.Volume, true);
            }

            return(orderBook);
        }
Example #24
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this).ToLower();

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

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

            if (r.Count == 0 || r.TryGetValue(pairCode, out var response) == false)
            {
                throw new ApiResponseException("No order book returned", this);
            }

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

            var asks = response.asks.Take(maxCount);
            var bids = response.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);
        }
Example #25
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this).ToLower();

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

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

            var maxCount = 1000; // Used to limit number of records when no limit is set (because it's too big).

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

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

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

            return(orderBook);
        }
Example #26
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api = ApiProvider.GetApi(context);

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

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

            CheckResponseErrors(r, context.Pair);

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

            var bids = context.MaxRecordsCount.HasValue
                ? r.result.buy.Take(context.MaxRecordsCount.Value / 2)
                : r.result.buy;
            var asks = context.MaxRecordsCount.HasValue
                ? r.result.sell.Take(context.MaxRecordsCount.Value / 2)
                : r.result.sell;

            foreach (var i in bids)
            {
                orderBook.AddBid(i.Rate, i.Quantity);
            }

            foreach (var i in asks)
            {
                orderBook.AddAsk(i.Rate, i.Quantity);
            }

            return(orderBook);
        }
Example #27
0
        public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            if (!PairCodeToProductId.TryGetValue(context.Pair, out var productId))
            {
                throw new ApiResponseException("No product found with specified asset pair", this);
            }

            var api = ApiProvider.GetApi(context);
            var r   = await api.GetOrderBookAsync(productId).ConfigureAwait(false);

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

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

            var asks = r.sell_price_levels.Take(maxCount);
            var bids = r.buy_price_levels.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);
        }
Example #28
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));
        }
Example #29
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, 0).ConfigureAwait(false)
                : await api.GetOrderBookAsync(pairCode, context.MaxRecordsCount).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            var buyAction  = "buy";
            var sellAction = "sell";

            var buys = context.MaxRecordsCount == Int32.MaxValue
                ? r.Where(x => x.side.ToLower().Equals(buyAction)).OrderBy(x => x.id).ToList()
                : r.Where(x => x.side.Equals(buyAction, StringComparison.OrdinalIgnoreCase)).OrderBy(x => x.id)
                       .Take(context.MaxRecordsCount).ToList();

            var sells = context.MaxRecordsCount == Int32.MaxValue
                ? r.Where(x => x.side.ToLower().Equals(sellAction)).OrderBy(x => x.id).ToList()
                : r.Where(x => x.side.Equals(sellAction, StringComparison.OrdinalIgnoreCase)).OrderBy(x => x.id)
                        .Take(context.MaxRecordsCount).ToList();

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

            foreach (var i in buys)
            {
                orderBook.AddBid(i.price, i.size);
            }

            foreach (var i in sells)
            {
                orderBook.AddAsk(i.price, i.size);
            }

            return(orderBook);
        }
Example #30
0
        public async Task<OrderBook> GetOrderBookAsync(OrderBookContext context)
        {
            var api = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this);

            var r = await api.GetOrderBookAsync(pairCode).ConfigureAwait(false);
            var orderBook = new OrderBook(Network, context.Pair);

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

            var response = r.payload;

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

            foreach (var i in bids)
                orderBook.AddBid(i.price, i.amount, true);

            foreach (var i in asks)
                orderBook.AddAsk(i.price, i.amount, true);

            return orderBook;
        }