Ejemplo n.º 1
0
        private void trade_OnRspUserLogin(object sender, ErrorEventArgs e)
        {
            if (e.ErrorID == 0)
            {
                LogWarn("登录成功.");
                _tradingDay = ((Trade)sender).TradingDay;

                if (!string.IsNullOrEmpty(fs[3]))
                {
                    LoginQuote(fs[3].Split(','), fs[1], this.textBoxUser.Text, this.textBoxPwd.Text);
                }

                A_.Trade = _t;  //赋值处理策略的A函数

                this.Invoke(new Action(() =>
                {
                    this.pictureBox1.Image = Properties.Resources.Open;
                    this.toolTip1.SetToolTip(this.pictureBox1, "已连接");
                    //this.toolTip1.Show("已连接.", this.pictureBox1, 6000);

                    this.toolTip1.SetToolTip(this.ComboBoxType, "策略文件(dll)放置在(./strategies)目录中.");
                    this.toolTip1.Show("策略文件(dll)放置在(./strategies)目录中.", this.ComboBoxType, 6000);
                }));
            }
            else
            {
                LogError("login error:" + e.ErrorMsg);
                _t.ReqUserLogout();
                _t = null;
                _q = null;
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        //登录
        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();
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
 void _timer_Tick(object sender, EventArgs e)
 {
     //自动启停控制
     if (_t == null)
     {
         if (_tradingDate.IndexOf(DateTime.Today.ToString("yyyyMMdd")) < 0)
         {
             //LogError($"{DateTime.Today.ToString("yyyyMMdd")} 非交易日");
         }
         else
         {
             //如果时间在设定的开始时间的5分钟内则重启接口
             var now = DateTime.Now.TimeOfDay;
             if ((new[] { _cfg.OpenTime1.TimeOfDay, _cfg.OpenTime2.TimeOfDay }).Count(n => now > n && now < n.Add(TimeSpan.FromMinutes(5))) > 0)
             {
                 LogInfo("接口隔夜启动");
                 this.ButtonLogin_Click(null, null);
             }
         }
     }
     else if (_t.IsLogin)
     {//退出接口:1.全部结束  2.2:00:00后全部非交易状态
         if ((_t.DicExcStatus.Count(n => n.Value != ExchangeStatusType.Closed) == 0) || (DateTime.Now.TimeOfDay > TimeSpan.Parse("02:00:00") && DateTime.Now.TimeOfDay < TimeSpan.Parse("03:00:00") && _t.DicExcStatus.Count(n => n.Value == ExchangeStatusType.Trading) == 0))
         {
             Thread.Sleep(1000 * 5);
             if (_t != null)
             {
                 _t.ReqUserLogout();
                 _t = null;
             }
             if (_q != null) //行情未登出???
             {
                 _q.ReqUserLogout();
                 _q = null;
             }
             LogInfo("接口退出");
         }
         else
         {
             //更新时间与交易所状态
             foreach (DataGridViewRow row in this.DataGridViewStrategies.Rows)
             {
                 Strategy stra;
                 if (_dicStrategies.TryGetValue((string)row.Cells["StraName"].Value, out stra))
                 {
                     if (stra.Datas.Count > 0)
                     {
                         row.Cells["UpdateTime"].Value = string.IsNullOrEmpty(stra.Tick.UpdateTime) ? stra.D[0].ToString() : stra.Tick.UpdateTime.Split(' ')[1];
                         //持仓更新
                         row.Cells["Position"].Value = $"L={stra.PositionLong};S={stra.PositionShort}";
                         ExchangeStatusType status;
                         if (_t.DicExcStatus.Count == 1)
                         {
                             row.Cells["ExcStatus"].Value = _t.DicExcStatus.ElementAt(0).Value;
                         }
                         else if (_t.DicExcStatus.TryGetValue(stra.InstrumentInfo.ProductID, out status))
                         {
                             row.Cells["ExcStatus"].Value = status;
                         }
                     }
                 }
             }
         }
     }
 }