Exemple #1
0
        public void TestOhlcvReceive()
        {
            var config = new ConfigurationBuilder().AddJsonFile("config.json").Build();

            int mssgCount = 0;
            var helloMsg  = new Hello()
            {
                apikey = System.Guid.Parse(config["TestApiKey"]),
                subscribe_data_type = new string[] { "ohlcv" }
            };

            using (var wsClient = new CoinApiWsClient(false))
            {
                wsClient.OHLCVEvent += (s, i) =>
                {
                    mssgCount++;
                };

                wsClient.SendHelloMessage(helloMsg);

                Thread.Sleep(10000);

                Assert.AreNotEqual(0, mssgCount);
            }
        }
Exemple #2
0
        public void TestOrderBookReceive()
        {
            var config = new ConfigurationBuilder().AddJsonFile("config.json").Build();

            int mssgCount = 0;
            var helloMsg  = new Hello()
            {
                apikey = System.Guid.Parse(config["TestApiKey"]),
                subscribe_data_type        = new string[] { "book" },
                subscribe_filter_symbol_id = new string[] { "BITSTAMP_SPOT_BTC_USD", "GEMINI_SPOT_BTC_USD COINBASE_SPOT_BTC_USD" }
            };

            using (var wsClient = new CoinApiWsClient(false))
            {
                var mre = new ManualResetEvent(false);
                wsClient.OrderBookEvent += (s, i) =>
                {
                    mre.Set();
                    mssgCount++;
                };

                wsClient.SendHelloMessage(helloMsg);

                mre.WaitOne(TimeSpan.FromSeconds(10));
                Assert.AreNotEqual(0, mssgCount);
            }
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CoinApiDataQueueHandler"/> class
 /// </summary>
 public CoinApiDataQueueHandler()
 {
     _client             = new CoinApiWsClient();
     _client.TradeEvent += OnTrade;
     _client.QuoteEvent += OnQuote;
     _client.Error      += OnError;
 }
Exemple #4
0
        public void TestVolumeReceive()
        {
            var config = new ConfigurationBuilder().AddJsonFile("config.json").Build();

            int mssgCount = 0;
            var helloMsg  = new Hello()
            {
                apikey = System.Guid.Parse(config["TestApiKey"]),
                subscribe_data_type = new string[] { "volume" }
            };

            using (var wsClient = new CoinApiWsClient(false))
            {
                var mre = new ManualResetEvent(false);
                wsClient.VolumeEvent += (s, i) =>
                {
                    mre.Set();
                    mssgCount++;
                };

                wsClient.SendHelloMessage(helloMsg);

                mre.WaitOne(TimeSpan.FromSeconds(50));
                Assert.AreNotEqual(0, mssgCount);
            }
        }
Exemple #5
0
        public void TestQuoteReceive()
        {
            var config = new ConfigurationBuilder().AddJsonFile("config.json").Build();

            int mssgCount = 0;
            var helloMsg  = new Hello()
            {
                apikey = System.Guid.Parse(config["TestApiKey"]),
                subscribe_data_type        = new string[] { "quote" },
                subscribe_filter_symbol_id = new string[] { "BITSTAMP_SPOT_BTC_USD", "GEMINI_SPOT_BTC_USD COINBASE_SPOT_BTC_USD" }
            };

            using (var wsClient = new CoinApiWsClient(false))
            {
                wsClient.QuoteEvent += (s, i) =>
                {
                    mssgCount++;
                };

                wsClient.SendHelloMessage(helloMsg);

                Thread.Sleep(10000);

                Assert.AreNotEqual(0, mssgCount);
            }
        }
        public void TestMessageReceivedAfterReconnect()
        {
            var config = new ConfigurationBuilder().AddJsonFile("config.json").Build();

            int mssgCount = 0;
            var helloMsg  = new Hello()
            {
                apikey = System.Guid.Parse(config["TestApiKey"]),
                subscribe_data_type = new string[] { "book", "quote", "trade" }
            };

            using (var wsClient = new CoinApiWsClient(false))
            {
                wsClient.OrderBookEvent += (s, i) =>
                {
                    mssgCount++;
                };

                wsClient.SendHelloMessage(helloMsg);

                Thread.Sleep(5000);

                for (int i = 0; i < 100; i++)
                {
                    Thread.Sleep(300);
                    wsClient.ForceReconnectUsedOnlyTestPurpose();
                }


                mssgCount = 0;

                Thread.Sleep(5000);
                Assert.AreNotEqual(0, mssgCount);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CoinApiDataQueueHandler"/> class
 /// </summary>
 public CoinApiDataQueueHandler(IDataAggregator dataAggregator)
 {
     _client             = new CoinApiWsClient();
     _client.TradeEvent += OnTrade;
     _client.QuoteEvent += OnQuote;
     _client.Error      += OnError;
     _dataAggregator     = dataAggregator;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CoinApiDataQueueHandler"/> class
 /// </summary>
 public CoinApiDataQueueHandler()
 {
     _client              = new CoinApiWsClient();
     _client.TradeEvent  += OnTrade;
     _client.QuoteEvent  += OnQuote;
     _client.Error       += OnError;
     _subscriptionManager = new EventBasedDataQueueHandlerSubscriptionManager();
     _subscriptionManager.SubscribeImpl   += (s, t) => Subscribe(s);
     _subscriptionManager.UnsubscribeImpl += (s, t) => Unsubscribe(s);
 }
Exemple #9
0
        public void TestSilenceNoReconnect()
        {
            var config = new ConfigurationBuilder().AddJsonFile("config.json").Build();

            int mssgCount = 0;
            var helloMsg  = new Hello()
            {
                apikey = Guid.Parse(config["TestApiKey"]),
                subscribe_data_type          = new string[] { "quote", "trade" },
                subscribe_filter_exchange_id = new string[] { "EXCHANGETHATDOESNOTEXISTS" }
            };

            using (var wsClient = new CoinApiWsClient(false))
            {
                var mre = new ManualResetEvent(false);
                wsClient.TradeEvent += (s, i) =>
                {
                    mre.Set();
                    mssgCount++;
                };
                wsClient.QuoteEvent += (s, i) =>
                {
                    mre.Set();
                    mssgCount++;
                };

                Task.Run(() => wsClient.SendHelloMessage(helloMsg));
                if (!wsClient.ConnectedEvent.WaitOne(TimeSpan.FromSeconds(10)))
                {
                    Assert.Fail("Not connected ...");
                }

                if (mre.WaitOne(TimeSpan.FromSeconds(10)))
                {
                    Assert.Fail("Received some message.");
                }

                if (wsClient.ConnectedEvent.WaitOne(TimeSpan.FromSeconds(30)))
                {
                    Assert.Fail("He is reconnecting...");
                }

                if (mre.WaitOne(TimeSpan.FromSeconds(1)))
                {
                    Assert.Fail("Received some message.");
                }

                Assert.AreEqual(0, mssgCount);
            }
        }
Exemple #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CoinApiDataQueueHandler"/> class
        /// </summary>
        public CoinApiDataQueueHandler()
        {
            var product = Config.GetValue <CoinApiProduct>("coinapi-product");

            _streamingDataType = product < CoinApiProduct.Streamer
                ? new[] { "trade" }
                : new[] { "trade", "quote" };

            Log.Trace($"CoinApiDataQueueHandler(): using plan '{product}'. Available data types: '{string.Join(",", _streamingDataType)}'");

            _client              = new CoinApiWsClient();
            _client.TradeEvent  += OnTrade;
            _client.QuoteEvent  += OnQuote;
            _client.Error       += OnError;
            _subscriptionManager = new EventBasedDataQueueHandlerSubscriptionManager();
            _subscriptionManager.SubscribeImpl   += (s, t) => Subscribe(s);
            _subscriptionManager.UnsubscribeImpl += (s, t) => Unsubscribe(s);
        }
Exemple #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CoinApiDataQueueHandler"/> class
        /// </summary>
        public CoinApiDataQueueHandler()
        {
            _dataAggregator = Composer.Instance.GetPart <IDataAggregator>();
            if (_dataAggregator == null)
            {
                _dataAggregator =
                    Composer.Instance.GetExportedValueByTypeName <IDataAggregator>(Config.Get("data-aggregator", "QuantConnect.Lean.Engine.DataFeeds.AggregationManager"));
            }
            var product = Config.GetValue <CoinApiProduct>("coinapi-product");

            _streamingDataType = product < CoinApiProduct.Streamer
                ? new[] { "trade" }
                : new[] { "trade", "quote" };

            Log.Trace($"CoinApiDataQueueHandler(): using plan '{product}'. Available data types: '{string.Join(",", _streamingDataType)}'");

            _client              = new CoinApiWsClient();
            _client.TradeEvent  += OnTrade;
            _client.QuoteEvent  += OnQuote;
            _client.Error       += OnError;
            _subscriptionManager = new EventBasedDataQueueHandlerSubscriptionManager();
            _subscriptionManager.SubscribeImpl   += (s, t) => Subscribe(s);
            _subscriptionManager.UnsubscribeImpl += (s, t) => Unsubscribe(s);
        }
        public void TestTradesReceive()
        {
            var config = new ConfigurationBuilder().AddJsonFile("config.json").Build();

            var helloMsg = new Hello()
            {
                apikey = System.Guid.Parse(config["TestApiKey"]),
                subscribe_data_type          = new string[] { "trade", "quote" },
                subscribe_filter_exchange_id = new string[] { "BITSTAMP" }
            };

            using (var wsClient = new CoinApiWsClient(false))
            {
                var mre_bs = new ManualResetEvent(false);
                var mre_cb = new ManualResetEvent(false);
                wsClient.TradeEvent += (s, i) =>
                {
                    if (i.symbol_id.StartsWith("COINBASE"))
                    {
                        mre_cb.Set();
                    }
                    else if (i.symbol_id.StartsWith("BITSTAMP"))
                    {
                        mre_bs.Set();
                    }
                };
                wsClient.QuoteEvent += (s, i) =>
                {
                    if (i.symbol_id.StartsWith("COINBASE"))
                    {
                        mre_cb.Set();
                    }
                    else if (i.symbol_id.StartsWith("BITSTAMP"))
                    {
                        mre_bs.Set();
                    }
                };

                // BITSTAMP
                wsClient.SendHelloMessage(helloMsg);

                if (!wsClient.ConnectedEvent.WaitOne(TimeSpan.FromSeconds(10)))
                {
                    Assert.Fail("should connect");
                }

                if (!mre_bs.WaitOne(TimeSpan.FromSeconds(10)))
                {
                    Assert.Fail("bistamp should be");
                }

                if (mre_cb.WaitOne(TimeSpan.FromSeconds(10)))
                {
                    Assert.Fail("coinbase should not");
                }

                // coinbase hello
                helloMsg = new Hello()
                {
                    apikey = System.Guid.Parse(config["TestApiKey"]),
                    subscribe_data_type          = new string[] { "trade", "quote" },
                    subscribe_filter_exchange_id = new string[] { "COINBASE" }
                };

                wsClient.SendHelloMessage(helloMsg);

                // received for coinbase - change of hello
                mre_cb.Reset();

                if (!mre_cb.WaitOne(TimeSpan.FromSeconds(10)))
                {
                    Assert.Fail("dont received for coinbase");
                }

                mre_bs.Reset();

                if (mre_bs.WaitOne(TimeSpan.FromSeconds(10)))
                {
                    Assert.Fail("received for bitstapm after coinbase");
                }
            }
        }