Пример #1
0
        private void Handle(MarketTradeDetailUpdateMessage msg)
        {
            for (var i = 0; i < msg.Tick?.Data.Length; ++i)
            {
                var item = msg.Tick.Data[i];

                _logger.LogInformation(
                    $"Market trade detail update {msg.ParseSymbolFromTopic()}, id={msg.Tick.Id}, ts={msg.Tick.Timestamp} | [item {i}: amount={item.Amount} ts={item.Timestamp} id={item.Id} tradeId={item.TradeId} price={item.Price} direction={item.Direction}]");
            }
        }
Пример #2
0
        public void ParseSymbolFromTopic_InvalidTopic_ThrowsException(string topic)
        {
            // Arrange
            var updateMessage = new MarketTradeDetailUpdateMessage(
                topic,
                DateTimeOffset.UtcNow,
                new MarketTradeDetailTick(1, DateTimeOffset.UtcNow, Array.Empty <MarketTradeDetailTickDataItem>()));

            // Act & Assert
            Assert.Throws <HuobiWebsocketClientException>(() => updateMessage.ParseSymbolFromTopic());
        }
 private void HandleTradeSafe(MarketTradeDetailUpdateMessage response)
 {
     try
     {
         HandleTrade(response);
     }
     catch (Exception e)
     {
         Log.Error(e, $"[Huobi] Failed to handle trade info, error: '{e.Message}'");
     }
 }
        private void HandleTrade(MarketTradeDetailUpdateMessage response)
        {
            var converted = response
                            .Tick
                            .Data
                            .Select(
                trade => ConvertTrade(
                    response.ParseSymbolFromTopic(),
                    trade,
                    response.Timestamp.UtcDateTime))
                            .ToArray();

            TradesSubject.OnNext(converted);
        }
Пример #5
0
        private bool TryHandleUpdateMessages(string message)
        {
            if (MarketCandlestickUpdateMessage.TryParse(Serializer, message, out var marketCandlestick))
            {
                Streams.CandlestickUpdateSubject.OnNext(marketCandlestick);
                return(true);
            }

            if (MarketDepthUpdateMessage.TryParse(Serializer, message, out var marketDepth))
            {
                Streams.DepthUpdateSubject.OnNext(marketDepth);
                return(true);
            }

            if (MarketByPriceRefreshUpdateMessage.TryParse(Serializer, message, out var marketByPriceRefresh))
            {
                Streams.MarketByPriceRefreshUpdateSubject.OnNext(marketByPriceRefresh);
                return(true);
            }

            if (MarketBestBidOfferUpdateMessage.TryParse(Serializer, message, out var marketBestBidOffer))
            {
                Streams.BestBidOfferUpdateSubject.OnNext(marketBestBidOffer);
                return(true);
            }

            if (MarketTradeDetailUpdateMessage.TryParse(Serializer, message, out var marketTradeDetail))
            {
                Streams.TradeDetailUpdateSubject.OnNext(marketTradeDetail);
                return(true);
            }

            if (MarketDetailsUpdateMessage.TryParse(Serializer, message, out var marketDetails))
            {
                Streams.MarketDetailsUpdateSubject.OnNext(marketDetails);
                return(true);
            }

            return(false);
        }