Пример #1
0
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            _cfg.WindowState = this.WindowState;

            var gss  = new[] { "OrderLayer", "TradeLayer", "PosiLayer", "AccLayer", "InstLayer", "InfoLayer" };
            var dgvs = new[] { this.dataGridViewOrder, this.dataGridViewTrade, this.dataGridViewPosition, this.dataGridViewAccount, this.dataGridViewInstrument, this.dataGridViewInfo /*, this.dataGridViewQuote */ };

            for (int i = 0; i < dgvs.Length; ++i)
            {
                _cfg.GetType().GetProperty(gss[i], System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).SetValue(_cfg, dgvs[i].SaveStyle()); //直接用=赋值,不正确
            }

            File.WriteAllText("./config.json", JsonConvert.SerializeObject(_cfg, Formatting.Indented));
            File.WriteAllText("./server.json", JsonConvert.SerializeObject((this.comboBoxServer.DataSource as BindingSource).DataSource, Formatting.Indented), Encoding.GetEncoding("GB2312"));

            if (_t != null && _t.IsLogin)
            {
                _t.ReqUserLogout();
            }
            if (_q != null && _q.IsLogin)
            {
                _q.ReqUserLogout();
            }
        }
Пример #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
 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;
                         }
                     }
                 }
             }
         }
     }
 }