void LoginTrade(string[] front, string _Broker, string _Investor, string _Password) { if ((DateTime.Now - _logTime).TotalSeconds < 3) { return; } if (_t != null) { if (_t.IsLogin) { _t.ReqUserLogout(); } _t = null; } _logTime = DateTime.Now; LogWarn("connecting ..."); _t = new TradeExt { Broker = _Broker, Investor = _Investor, Password = _Password, }; _t.OnFrontConnected += trade_OnFrontConnected; _t.OnRspUserLogin += trade_OnRspUserLogin; _t.OnRtnExchangeStatus += trade_OnRtnExchangeStatus; //接口相关信息 _t.OnInfo += trade_OnInfo; _t.OnRspUserLogout += trade_OnRspUserLogout; _t.OnRtnNotice += trade_OnRtnNotice; _t.ReqConnect(front); }
//登录 private void buttonLogin_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.textBoxUser.Text) || string.IsNullOrEmpty(this.textBoxPwd.Text)) { return; } if (_t != null && _t.IsLogin) { return; //已经登陆成功,返回. } if (_t != null) { _t.ReqUserLogout(); _t = null; } var svr = (FutureBroker)this.comboBoxServer.SelectedItem; _t = new TradeExt();// (Trade)Activator.CreateInstance(ass.GetType($"HaiFeng.{svr.Type}Trade")); _investor = this.textBoxUser.Text; _password = this.textBoxPwd.Text; _t.FrontAddr = svr.TradeAddr; _t.Broker = svr.Broker; _t.Investor = _investor; _t.Password = _password; // SE新增 _t.ProductInfo = this.textBoxProductInfo.Text; _t.AppID = this.textBoxAppID.Text; _t.AuthCode = this.textBoxAuthCode.Text; _t.OnFrontConnected += (snd, ea) => { ShowMsg($"交易连接成功"); _t.ReqUserLogin(); }; _t.OnRtnPasswordUpdate += (snd, ea) => ShowMsg($"密码更新{ea.ErrorMsg}"); _t.OnRspUserLogin += RspLogin; _t.OnRspUserLogout += (snd, ea) => ShowMsg($"[{_investor}]交易退出:{ea.Value}"); _t.OnRtnOrder += OnOrder; _t.OnRtnCancel += OnCancel; _t.OnRtnTrade += OnTrade; _t.OnRtnErrOrder += OnErrOrder; _t.OnRtnErrCancel += OnErrCancel; _t.OnRtnExchangeStatus += (snd, ea) => ShowMsg($"[{_investor}][{ea.Exchange,8}{ea.Status}]"); _t.OnRtnNotice += (snd, ea) => ShowMsg($"[{_investor}]提醒信息:{ea.Value}"); ShowMsg($"登录中..."); this.Text += $"({_t.Version.Split(' ')[0]})"; _t.ReqConnect(); }
void LoginTrade(string[] front, string _Broker, string _Investor, string _Password) { if ((DateTime.Now - _logTime).TotalSeconds < 3) { return; } if (_t != null) { if (_t.IsLogin) { _t.ReqUserLogout(); } _t = null; } _logTime = DateTime.Now; LogWarn("connecting ..."); _t = new TradeExt { FrontAddr = front[0], Broker = _Broker, Investor = _Investor, Password = _Password, ProductInfo = this.textBoxProductInfo.Text, AppID = this.textBoxAppID.Text, AuthCode = this.textBoxAuthCode.Text, }; _t.OnFrontConnected += trade_OnFrontConnected; _t.OnRspUserLogin += trade_OnRspUserLogin; _t.OnRtnExchangeStatus += trade_OnRtnExchangeStatus; //接口相关信息 _t.OnInfo += trade_OnInfo; _t.OnRspUserLogout += trade_OnRspUserLogout; _t.OnRtnNotice += trade_OnRtnNotice; _t.ReqConnect(); }