示例#1
0
        public async Task <GdaxOrderBook> GetFullOrderBook(string pair,
                                                           CancellationToken cancellationToken = default,
                                                           EventHandler <SentHttpRequest> sentHttpRequestHandler          = default,
                                                           EventHandler <ReceivedHttpResponse> receivedHttpRequestHandler = default)
        {
            var response = await _restClient.ExecuteRestMethod <GdaxOrderBookRawResponse>(HttpMethod.Get,
                                                                                          string.Format(_orderBookRequestUrl, pair), new GdaxPostContentBase(), cancellationToken, sentHttpRequestHandler,
                                                                                          receivedHttpRequestHandler);

            var orderBook = new GdaxOrderBook
            {
                Sequence = response.Sequence,
                Asks     = response.Asks.Select(ask => new GdaxOrderBookEntityRow
                {
                    Price   = decimal.Parse(ask[0], CultureInfo.InvariantCulture),
                    Size    = decimal.Parse(ask[1], CultureInfo.InvariantCulture),
                    OrderId = Guid.Parse(ask[2])
                }).ToList(),
                Bids = response.Bids.Select(bid => new GdaxOrderBookEntityRow
                {
                    Price   = decimal.Parse(bid[0], CultureInfo.InvariantCulture),
                    Size    = decimal.Parse(bid[1], CultureInfo.InvariantCulture),
                    OrderId = Guid.Parse(bid[2])
                }).ToList()
            };

            return(orderBook);
        }
示例#2
0
        private async Task HandleRetrievedOrderBook(string symbol, GdaxOrderBook orderBook)
        {
            var orders = orderBook.Asks.Select(order =>
                                               _converters.GdaxOrderBookItemToOrderBookItem(symbol, false, order))
                         .Union(orderBook.Bids.Select(order =>
                                                      _converters.GdaxOrderBookItemToOrderBookItem(symbol, true, order)));

            await HandleOrderBookSnapshotAsync(symbol, DateTime.UtcNow, orders);

            _symbolsLastSequenceNumbers[symbol] = orderBook.Sequence;
        }