Exemplo n.º 1
0
        //登录响应
        private void RspLogin(object sender, IntEventArgs e)
        {
            var t = (Trade)sender;

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


            if (e.Value == 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 = (Quote)Activator.CreateInstance(ass.GetType($"HaiFeng.{svr.Type}Quote"), _t);
                    //this.Invoke(new Action(() => this.comboBoxInstrument.Items.Add("000001")));
                }
                else
                {
                    _q = (Quote)Activator.CreateInstance(ass.GetType($"HaiFeng.{svr.Type}Quote"), "./dll/ctp_quote.dll");
                }

                _q.OnFrontConnected += (snd, ea) =>
                {
                    ShowMsg($"行情连接成功");
                    _q.ReqUserLogin(_investor, _password, svr.Broker);
                };
                _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($"[{_broker}]行情退出:{ea.Value}"); };
                _q.ReqConnect(svr.QuoteAddr);
            }
        }
Exemplo n.º 2
0
        //登录响应
        private void RspLogin(object sender, IntEventArgs e)
        {
            var t = (Trade)sender;

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


            if (e.Value == 0)
            {
                FutureBroker svr = (this.comboBoxServer.DataSource as BindingSource).Current as FutureBroker;

                if (svr == null)
                {
                    ShowMsg("前置配置为空无法登录行情");
                    return;
                }
                _q = new CTPQuote();
                _q.OnFrontConnected += (snd, ea) =>
                {
                    ShowMsg($"行情连接成功");
                    _q.ReqUserLogin(_investor, _password, svr.Broker);
                };
                _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($"[{_broker}]行情退出:{ea.Value}"); };
                _q.ReqConnect($"tcp://{svr.QuoteIP}:{svr.QuotePort}");
            }
        }