private static void ReqAndSubscribeLast24Candlestick() { // Initialize a new instance var client = new Last24hCandlestickWebSocketClient(Config.Host); // Add the response receive handler 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(); // Subscribe the specific topic client.Subscribe(null); Console.WriteLine("Press ENTER to unsubscribe and stop...\n"); Console.ReadLine(); // Unsubscrive the specific topic client.UnSubscribe(null); // Delete handler client.OnDataReceived -= Client_OnDataReceived; }
private static void ReqAndSubscribeLast24Candlestick() { // Initialize a new instance var client = new Last24hCandlestickWebSocketClient(); // 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(SubscribeLast24hCandlestickResponse response) { if (response != null) { if (response.tick != null) // Parse subscription data { Console.WriteLine($"id: {response.tick.id}, count: {response.tick.count}, vol: {response.tick.vol}"); } else if (response.data != null) // Parse request data { Console.WriteLine($"id: {response.data.id}, count: {response.data.count}, vol: {response.data.vol}"); } } } // 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; }