Esempio n. 1
0
        public void Throws()
        {
            var client = new TradeWebSocketClient();

            Assert.Throws <ArgumentNullException>("symbol", () => client.Subscribe((string)null));
            Assert.Throws <ArgumentNullException>("symbol", () => client.Subscribe(string.Empty));
        }
Esempio n. 2
0
        private static void ReqAndSubscribeTrade()
        {
            // Initialize a new instance
            var client = new TradeWebSocketClient(Config.Host);

            // Add the data receive handler
            client.OnDataReceived += Client_OnDataReceived;
            void Client_OnDataReceived(String response)
            {
                if (response != null)
                {
                    AppLogger.Info($"WebSocket returned data={response}");
                }
            }

            // Then connect to server and wait for the handler to handle the response
            client.Connect();

            // Request full data
            client.Req("btcusdt", "");

            client.Subscribe("btcusdt", "");

            Console.WriteLine("Press ENTER to unsubscribe and stop...\n");
            Console.ReadLine();

            // Unsubscrive the specific topic
            client.UnSubscribe("btcusdt", "");

            // Delete handler
            // Delete handler
            client.OnDataReceived -= Client_OnDataReceived;
        }
        private static void ReqAndSubscribeTrade()
        {
            // Initialize a new instance
            var client = new TradeWebSocketClient();

            // Add connection open handler
            client.OnConnectionOpen += Client_OnConnectionOpen;
            void Client_OnConnectionOpen()
            {
                // Subscribe the specific topic
                client.Subscribe("btcusdt");

                Console.WriteLine("Subscribed");
            }

            // Add the response receive handler
            client.OnResponseReceived += Client_OnResponseReceived;
            void Client_OnResponseReceived(SubscribeTradeResponse response)
            {
                if (response != null)
                {
                    if (response.tick != null && response.tick.data != null) // Parse subscription data
                    {
                        foreach (var t in response.tick.data)
                        {
                            Console.WriteLine($"tradeid: {t.tradeid}, direction: {t.direction}, [{t.price}, {t.amount}]");
                        }
                    }
                    else if (response.data != null) // Parse request data
                    {
                        foreach (var t in response.data)
                        {
                            Console.WriteLine($"tradeid: {t.tradeid}, direction: {t.direction}, [{t.price}, {t.amount}]");
                        }
                        Console.WriteLine($"There are total {response.data.Length} trades");
                    }
                }
            }

            // Then connect to server and wait for the handler to handle the response
            client.Connect();

            // Request full data
            client.Req("btcusdt");

            Console.WriteLine("Press ENTER to unsubscribe and stop...\n");
            Console.ReadLine();

            // Unsubscrive the specific topic
            client.UnSubscribe("btcusdt");

            // Delete handler
            client.OnResponseReceived -= Client_OnResponseReceived;
        }
Esempio n. 4
0
        public void Subscribe()
        {
            var client = new TradeWebSocketClient();

            Assert.Empty(client.SubscribedStreams);
            Assert.Empty(client.Publisher.PublishedStreams);

            client.Subscribe(Symbol.BTC_USDT);

            Assert.True(client.SubscribedStreams.Count() == 1);
            Assert.True(client.Publisher.PublishedStreams.Count() == 1);
        }