Example #1
0
        public void SubscribingToExchangeUpdates_Should_ReceiveUpdate()
        {
            // arrange
            var socket = new TestSocket();

            socket.SetProxyResponse(true);
            socket.CanConnect = true;
            var client = TestHelpers.CreateSocketClient(socket, new BittrexSocketClientOptions()
            {
                LogVerbosity = LogVerbosity.Debug
            });

            BittrexStreamOrderBookUpdate result = null;
            var subResponse = client.SubscribeToOrderBookUpdates("BTC-ETH", (test) => result = test);

            var data =
                new BittrexStreamOrderBookUpdate()
            {
                Nonce  = 1,
                Symbol = "BTC-ETH",
                Buys   = new List <BittrexStreamOrderBookUpdateEntry> {
                    new BittrexStreamOrderBookUpdateEntry()
                    {
                        Quantity = 0.1m, Price = 0.2m, Type = OrderBookEntryType.NewEntry
                    }
                },
                Sells = new List <BittrexStreamOrderBookUpdateEntry> {
                    new BittrexStreamOrderBookUpdateEntry()
                    {
                        Quantity = 0.4m, Price = 0.5m, Type = OrderBookEntryType.RemoveEntry
                    }
                },
                Fills = new List <BittrexStreamFill> {
                    new BittrexStreamFill()
                    {
                        Rate = 0.6m, Quantity = 0.7m, OrderType = OrderSide.Buy, Timestamp = new DateTime(2018, 1, 1)
                    }
                }
            };


            // act
            socket.InvokeMessage(WrapResult("uE", data));

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(TestHelpers.AreEqual(data, result, "Buys", "Sells", "Fills"));
            Assert.IsTrue(TestHelpers.AreEqual(data.Buys.ToList()[0], result.Buys.ToList()[0]));
            Assert.IsTrue(TestHelpers.AreEqual(data.Sells.ToList()[0], result.Sells.ToList()[0]));
            Assert.IsTrue(TestHelpers.AreEqual(data.Fills.ToList()[0], result.Fills.ToList()[0]));
        }
 private void HandleUpdate(BittrexStreamOrderBookUpdate data)
 {
     UpdateOrderBook(data.Nonce, data.Buys, data.Sells);
 }