Exemplo n.º 1
0
        private async void buttonInit_ClickAsync(object sender, EventArgs e)
        {
            if (!comboBoxTrdServer.Enabled)
            {
                comboBoxTrdServer.Enabled = true;
                textBoxUname.Enabled      = true;
                textBoxApiKey.Enabled     = true;
                textBoxApiSecret.Enabled  = true;
                cli4trd = null;
                LOG($"[DEBUG] 重置结束,可以继续重新测试服务器连接了。\r\n");
                return;
            }

            try
            {
                var client = new RESTClient4Trade(comboBoxTrdServer.Text.Trim(), textBoxUname.Text.Trim(), Convert.ToInt32(textBoxVPID.Text), textBoxApiKey.Text.Trim(), textBoxApiSecret.Text.Trim());
                var info   = await client.GetUserInfoAsync();

                LOG($"[DEBUG] connect trade-server, GetUserInfo: {info}\r\n");

                cli4trd = client;
                comboBoxTrdServer.Enabled = false;
                textBoxUname.Enabled      = false;
                textBoxApiKey.Enabled     = false;
                textBoxApiSecret.Enabled  = false;
            }
            catch (Exception ex)
            {
                LOG("[ERROR] connect trade server Exception: " + ex.Message + "\r\n");
            }
        }
Exemplo n.º 2
0
        private async Task <RESTClient4Trade> GetClientAsync()
        {
            string uid = cli4trd?.GetCurrentUId();

            if (uid == null || uid.Length < 1)
            {
                if (comboBoxTrdServer.Text.Length < 1 || textBoxUname.Text.Length < 1 || textBoxApiKey.Text.Length < 1 || textBoxApiSecret.Text.Length < 1)
                {
                    LOG("[WARN] 请先正确填写参数。。。\r\n");
                    return(null);
                }
                try
                {
                    var client = new RESTClient4Trade(comboBoxTrdServer.Text, textBoxUname.Text, Convert.ToInt32(textBoxVPID.Text), textBoxApiKey.Text, textBoxApiSecret.Text);
                    var info   = await client.GetUserInfoAsync();

                    LOG($"[DEBUG] connect trade-server, get user info: {info}\r\n");
                    cli4trd = client;
                }
                catch (Exception ex)
                {
                    LOG("[ERROR] connect trade server Exception: " + ex.Message + "\r\n");
                    return(null);
                }
            }
            return(cli4trd);
        }