private static void SubscribeAccountV2() { // Initialize a new instance var client = new SubscribeAccountWebSocketV2Client(Config.AccessKey, Config.SecretKey); // Add the auth receive handler client.OnAuthenticationReceived += Client_OnAuthReceived; void Client_OnAuthReceived(WebSocketV2AuthResponse response) { if (response.code == (int)ResponseCode.Success) { // Subscribe the specific topic client.Subscribe("1"); } else { AppLogger.Error($"WebSocket authentication fail, code={response.code}, message={response.message}"); } } // Add the data receive handler client.OnDataReceived += Client_OnDataReceived; void Client_OnDataReceived(SubscribeAccountV2Response response) { if (response != null) { if (response.action.Equals("sub")) { if (response.code == (int)ResponseCode.Success) { AppLogger.Info($"WebSocket subscribed successfully, topic={response.ch} "); } else { AppLogger.Info($"WebSocket subscribed topic fail, topic={response.ch}, errorCode={response.code}, errorMessage={response.message}"); } } else if (response.action.Equals("push") && response.data != null) { var b = response.data; if (b.changeTime == null) { AppLogger.Info($"WebSocket returned data, topic={response.ch}, currency={b.currency}, id={b.accountId}, balance={b.balance}, available={b.available}"); } else { AppLogger.Info($"WebSocket received data, topic={response.ch}, currency={b.currency}, id={b.accountId}, balance={b.balance}, available={b.available}, time={b.changeTime}"); } } } } // Then connect to server and wait for the handler to handle the response client.Connect(); Console.WriteLine("Press ENTER to unsubscribe and stop...\n"); Console.ReadLine(); // Unsubscrive the specific topic client.UnSubscribe("1"); // Delete handler client.OnDataReceived -= Client_OnDataReceived; }