private static void SubscribeOrderV2()
        {
            // Initialize a new instance
            var client = new SubscribeOrderWebSocketV2Client(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 if authentication passed
                    client.Subscribe("btcusdt");
                    Console.WriteLine("Subscription sent");
                }
                else
                {
                    Console.WriteLine($"Authentication fail, code: {response.code}, message: {response.message}");
                }
            }

            // Add the data receive handler
            client.OnDataReceived += Client_OnDataReceived;
            void Client_OnDataReceived(SubscribeOrderV2Response response)
            {
                if (response != null)
                {
                    if (response.action.Equals("sub"))
                    {
                        if (response.code == (int)ResponseCode.Success)
                        {
                            Console.WriteLine($"Subscribe topic {response.ch} successfully");
                        }
                        else
                        {
                            Console.WriteLine($"Subscribe topic {response.ch} fail, error code: {response.code}, error message: {response.message}");
                        }
                    }
                    else if (response.action.Equals("push") && response.data != null)
                    {
                        var o = response.data;
                        Console.WriteLine($"order update, event: {o.eventType}, symbol: {o.symbol}, type: {o.type}, status: {o.orderStatus}");
                    }
                }
            }

            // 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("btcusdt");

            // Delete handler
            client.OnDataReceived -= Client_OnDataReceived;
        }
Esempio n. 2
0
        private static SubscribeOrderWebSocketV2Client SubscribeOrderV2(string symbol)
        {
            // Initialize a new instance
            var client = new SubscribeOrderWebSocketV2Client(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 if authentication passed
                    client.Subscribe(symbol);
                    AppLogger.Info($"Order update {symbol} subscription sent");
                }
                else
                {
                    AppLogger.Info($"Authentication fail, code: {response.code}, message: {response.message}");
                }
            }

            // Add the data receive handler
            client.OnDataReceived += Client_OnDataReceived;
            void Client_OnDataReceived(SubscribeOrderV2Response response)
            {
                if (response != null)
                {
                    if (response.action.Equals("sub"))
                    {
                        if (response.code == (int)ResponseCode.Success)
                        {
                            AppLogger.Info($"Subscribe topic {response.ch} successfully");
                        }
                        else
                        {
                            AppLogger.Info($"Subscribe topic {response.ch} fail, error code: {response.code}, error message: {response.message}");
                        }
                    }
                    else if (response.action.Equals("push") && response.data != null)
                    {
                        var o = response.data;
                        AppLogger.Info($"order update, event: {o.eventType}, symbol: {o.symbol}, type: {o.type}, account id: {o.accountId}, status: {o.orderStatus}");
                    }
                }
            }

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

            return(client);
        }
        private static void SubscribeOrder()
        {
            // Initialize a new instance
            var client = new SubscribeOrderWebSocketV2Client(Config.AccessKey, Config.SecretKey, Config.Host);

            // Add the auth receive handler
            client.OnAuthenticationReceived += Client_OnAuthReceived;
            void Client_OnAuthReceived(WebSocketV2AuthResponse response)
            {
                if (response.code == (int)ResponseCode.Success)
                {
                    // Subscribe if authentication passed
                    client.Subscribe("btcusdt");
                }
                else
                {
                    AppLogger.Error($"WebSocket authentication fail, code={response.code}, message={response.message}");
                }
            }

            // 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();

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

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

            // Delete handler
            client.OnDataReceived -= Client_OnDataReceived;
        }
Esempio n. 4
0
        private static SubscribeOrderWebSocketV2Client SubscribeOrderV2(string symbol)
        {
            // Initialize a new instance
            var client = new SubscribeOrderWebSocketV2Client(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");
                    AppLogger.Info($"WebSocket authentication success, code={response.code}");
                }
                else
                {
                    AppLogger.Error($"WebSocket authentication fail, code={response.code}, message={response.message}");
                }
            }

            // 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();

            return(client);
        }
Esempio n. 5
0
 private static void UnsubscribeOrderV2(SubscribeOrderWebSocketV2Client client, string symbol)
 {
     // Unsubscrive the specific topic
     client.UnSubscribe(symbol);
 }