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)) { var mre = new ManualResetEvent(false); wsClient.QuoteEvent += (s, i) => { mre.Set(); mssgCount++; }; wsClient.SendHelloMessage(helloMsg); mre.WaitOne(TimeSpan.FromSeconds(10)); Assert.AreNotEqual(0, mssgCount); } }
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)) { wsClient.OrderBookEvent += (s, i) => { mssgCount++; }; wsClient.SendHelloMessage(helloMsg); Thread.Sleep(10000); Assert.AreNotEqual(0, mssgCount); } }
public void TestTradesReceive() { 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[] { "trade" } }; using (var wsClient = new CoinApiWsClient(true)) { var mre = new ManualResetEvent(false); wsClient.TradeEvent += (s, i) => { mre.Set(); mssgCount++; }; wsClient.SendHelloMessage(helloMsg); mre.WaitOne(TimeSpan.FromSeconds(10)); Assert.AreNotEqual(0, mssgCount); } }
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)) { wsClient.VolumeEvent += (s, i) => { mssgCount++; }; wsClient.SendHelloMessage(helloMsg); Thread.Sleep(50000); 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); } }
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); } }
private void SendHelloMessage(IEnumerable <string> subscribeFilter) { var list = subscribeFilter.ToList(); if (list.Count == 0) { // If we use a null or empty filter in the CoinAPI hello message // we will be subscribing to all symbols for all active exchanges! // Only option is requesting an invalid symbol as filter. list.Add("$no_symbol_requested$"); } _client.SendHelloMessage(new Hello { apikey = Guid.Parse(_apiKey), heartbeat = true, subscribe_data_type = _streamingDataType, subscribe_filter_symbol_id = list.ToArray() }); _nextHelloMessageUtcTime = DateTime.UtcNow.Add(_minimumTimeBetweenHelloMessages); }
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"); } } }