private static void ReqAndSubscribeCandlestick() { // Initialize a new instance var client = new CandlestickWebSocketClient(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", "1day", 0, 0, ""); client.Subscribe("btcusdt", "1day"); Console.WriteLine("Press ENTER to unsubscribe and stop...\n"); Console.ReadLine(); // Unsubscrive the specific topic //client.UnSubscribe("btcusdt", "1min"); //client.Subscribe("btcusdt", "1min", "j4ecd3s9rj.1610623898018.1.111"); // Delete handler // Delete handler client.OnDataReceived -= Client_OnDataReceived; }
private static void ReqAndSubscribeCandlestick() { // Initialize a new instance var client = new CandlestickWebSocketClient(); // Add connection open handler client.OnConnectionOpen += Client_OnConnectionOpen; void Client_OnConnectionOpen() { // Subscribe the specific topic client.Subscribe("btcusdt", "1min"); Console.WriteLine("Subscribed"); } // Add the response receive handler client.OnResponseReceived += Client_OnResponseReceived; void Client_OnResponseReceived(SubscribeCandlestickResponse 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 { foreach (var t in response.data) { Console.WriteLine($"id: {t.id}, count: {t.count}, vol: {t.vol}"); } Console.WriteLine($"There are total {response.data.Length} ticks"); } } } // Then connect to server and wait for the handler to handle the response client.Connect(); // Request full data client.Req("btcusdt", "1min", 1569361140, 1569366420); Console.WriteLine("Press ENTER to unsubscribe and stop...\n"); Console.ReadLine(); // Unsubscrive the specific topic client.UnSubscribe("btcusdt", "1min"); // Delete handler //client.OnResponseReceived -= Client_OnResponseReceived; client.Disconnect(); }