예제 #1
0
        private async Task PublishOrderBookAndTickPrice(OrderBook orderBook)
        {
            if (IsStale(orderBook))
            {
                _log.Info("Stale instrument.", new { orderBook.Asset });

                return;
            }

            InternalMetrics.OrderBookOutCount
            .WithLabels(orderBook.Asset)
            .Inc();

            InternalMetrics.OrderBookOutDelayMilliseconds
            .WithLabels(orderBook.Asset)
            .Set((DateTime.UtcNow - orderBook.Timestamp).TotalMilliseconds);

            await _orderBookPublisher.PublishAsync(orderBook);

            var tickPrice = TickPrice.FromOrderBook(orderBook);

            InternalMetrics.QuoteOutCount
            .WithLabels(tickPrice.Asset)
            .Inc();

            InternalMetrics.QuoteOutSidePrice
            .WithLabels(tickPrice.Asset, "ask")
            .Set((double)tickPrice.Ask);

            InternalMetrics.QuoteOutSidePrice
            .WithLabels(tickPrice.Asset, "bid")
            .Set((double)tickPrice.Bid);

            await _tickPricePublisher.PublishAsync(tickPrice);
        }
        private async Task PublishOrderBookAsync(OrderBook orderBook)
        {
            if (!orderBook.IsEmpty)
            {
                await _orderBookPublisher.PublishAsync(_exchangeName, orderBook);

                await _tickPricePublisher.PublishAsync(TickPrice.FromOrderBook(_exchangeName, orderBook));
            }
        }