コード例 #1
0
ファイル: Plat.cs プロジェクト: yutiansut/hf_at
        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;
            }
        }
コード例 #2
0
 private void LoginQuote(string[] front, string _Broker, string _Investor, string _Password)
 {
     if (_q != null)
     {
         if (_q.IsLogin)
         {
             _q.ReqUserLogout();
         }
         _q = null;
     }
     _q = new QuoteExt
     {
         Broker   = _Broker,
         Investor = _Investor,
         Password = _Password,
     };
     _q.OnFrontConnected += quote_OnFrontConnected;
     _q.OnRspUserLogin   += quote_OnRspUserLogin;
     _q.OnRspUserLogout  += quote_OnRspUserLogout;
     _q.OnRtnTick        += quote_OnRtnTick;
     _q.ReqConnect(front);
 }
コード例 #3
0
ファイル: Plat.cs プロジェクト: yutiansut/hf_at
 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;
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #4
0
        //登录响应
        private void RspLogin(object sender, ErrorEventArgs e)
        {
            var t = (Trade)sender;

            ShowMsg($"[{_investor}]登录:{e.ErrorID}=={e.ErrorMsg}");

            if (e.ErrorID == 140)
            {
                _t.ReqUserPasswordUpdate(_t.Password, "Hf123456");
            }
            if (e.ErrorID == 0)
            {
                this.Invoke(new Action(() =>
                {
                    foreach (var posi in _t.DicPositionField.Values)
                    {
                        _bsPosi.Add(posi);
                    }
                }));
                FutureBroker svr = (this.comboBoxServer.DataSource as BindingSource).Current as FutureBroker;

                if (svr == null)
                {
                    ShowMsg("前置配置为空无法登录行情");
                    return;
                }
                if (_q != null)
                {
                    _q.ReqUserLogout();
                    _q = null;
                }
                if (svr.Type == ProxyType.Tdx)
                {
                    _q = new QuoteExt(); // (Quote)Activator.CreateInstance(ass.GetType($"HaiFeng.{svr.Type}Quote"));
                                         //this.Invoke(new Action(() => this.comboBoxInstrument.Items.Add("000001")));
                }
                else
                {
                    _q = new QuoteExt();// (Quote)Activator.CreateInstance(ass.GetType($"HaiFeng.{svr.Type}Quote"));
                }
                _q.Broker    = svr.Broker;
                _q.FrontAddr = svr.QuoteAddr;
                _q.Investor  = _investor;
                _q.Password  = _password;

                _q.OnFrontConnected += (snd, ea) =>
                {
                    ShowMsg($"行情连接成功");
                    _q.ReqUserLogin();
                };
                _q.OnRspUserLogin += (snd, ea) =>
                {
                    foreach (var v in _t.DicPositionField.Values)
                    {
                        ((Quote)snd).ReqSubscribeMarketData(v.InstrumentID);
                    }
                    ShowMsg($"行情登录成功");
                    LogSucceed();
                };
                _q.OnRtnTick       += this.OnTick;
                _q.OnRspUserLogout += (snd, ea) => { ShowMsg($"[{_investor}]行情退出:{ea.Value}"); };
                _q.ReqConnect();
            }
        }