Ejemplo n.º 1
0
        public void Subscribe()
        {
            var symbol1 = Symbol.BTC_USDT;
            var symbol2 = Symbol.LTC_BTC;
            const CandlestickInterval interval = CandlestickInterval.Hour;

            Assert.Empty(_client.SubscribedStreams);

            // Subscribe to symbol.
            _client.Subscribe(symbol1, interval);
            Assert.Equal(CandlestickClient.GetStreamName(symbol1, interval), _client.SubscribedStreams.Single());

            // Re-Subscribe to same symbol doesn't fail.
            _client.Subscribe(symbol1, interval);
            Assert.Equal(CandlestickClient.GetStreamName(symbol1, interval), _client.SubscribedStreams.Single());

            // Subscribe to a different symbol.
            _client.Subscribe(symbol2, interval);
            Assert.True(_client.SubscribedStreams.Count() == 2);
            Assert.Contains(CandlestickClient.GetStreamName(symbol1, interval), _client.SubscribedStreams);
            Assert.Contains(CandlestickClient.GetStreamName(symbol2, interval), _client.SubscribedStreams);
        }
Ejemplo n.º 2
0
        public void LinkToClient()
        {
            var api      = new Mock <IBinanceApi>().Object;
            var client1  = new Mock <ICandlestickClient>().Object;
            var client2  = new CandlestickClient();
            var symbol1  = Symbol.BTC_USDT;
            var symbol2  = Symbol.LTC_BTC;
            var interval = CandlestickInterval.Hour;

            client2.Subscribe(symbol1, interval);

            var clientSubscribeStreams = client2.SubscribedStreams.ToArray();

            Assert.Equal(CandlestickClient.GetStreamName(symbol1, interval), clientSubscribeStreams.Single());

            var cache = new CandlestickCache(api, client1)
            {
                Client = client2 // link client.
            };

            // Client subscribed streams are unchanged after link to unsubscribed cache.
            Assert.Equal(clientSubscribeStreams, client2.SubscribedStreams);

            cache.Client = client1; // unlink client.

            // Subscribe cache to symbol.
            cache.Subscribe(symbol2, interval);

            // Cache is subscribed to symbol.
            Assert.Equal(CandlestickClient.GetStreamName(symbol2, interval), cache.SubscribedStreams.Single());

            cache.Client = client2; // link to client.

            // Client has second subscribed stream from cache.
            Assert.True(client2.SubscribedStreams.Count() == 2);
            Assert.Contains(CandlestickClient.GetStreamName(symbol2, interval), client2.SubscribedStreams);
        }