コード例 #1
0
 void LoadAccounts()
 {
     try
     {
         var accounts = from c in XElement.Load(accountsFile).Elements("Account")
                        select c;
         foreach (var account in accounts)
         {
             AccountItem ai = new AccountItem();
             ai.Label      = account.Attribute("Label").Value;
             ai.InvestorId = account.Attribute("InvestorId").Value;
             ai.Password   = account.Attribute("Password").Value;
             accountsList.Add(ai);
         }
     }
     catch (Exception)
     {
     }
 }
コード例 #2
0
 void LoadAccounts()
 {
     try
     {
         var accounts = from c in XElement.Load(accountsFile).Elements("Account")
                        select c;
         foreach (var account in accounts)
         {
             AccountItem ai = new AccountItem();
             ai.Label = account.Attribute("Label").Value;
             ai.InvestorId = account.Attribute("InvestorId").Value;
             ai.Password = account.Attribute("Password").Value;
             accountsList.Add(ai);
         }
     }
     catch (Exception)
     {
     }
 }
コード例 #3
0
        private void _Connect()
        {
            CTPZQAPI.GetInstance().__RegInstrumentDictionary(_dictInstruments);
            CTPZQAPI.GetInstance().__RegInstrumentCommissionRateDictionary(_dictCommissionRate);
            //CTPZQAPI.GetInstance().__RegInstrumentMarginRateDictionary(_dictMarginRate);
            CTPZQAPI.GetInstance().__RegDepthMarketDataDictionary(_dictDepthMarketData);

            server = null;
            account = null;

            bool bCheckOk = false;

            do
            {
                if (0 == serversList.Count)
                {
                    MessageBox.Show("您还没有设置 服务器 信息,目前只选择第一条进行连接");
                    break;
                }
                if (0 == serversList.Count)
                {
                    MessageBox.Show("您还没有设置 账号 信息,目前只选择第一条进行连接");
                    break;
                }

                server = serversList[0];
                account = accountsList[0];

                if (string.IsNullOrEmpty(server.BrokerID))
                {
                    MessageBox.Show("BrokerID不能为空");
                    break;
                }

                if (_bWantTdConnect &&0 == server.Trading.Count())
                {
                    MessageBox.Show("交易服务器地址不全");
                    break;
                }

                if (_bWantMdConnect &&0 == server.MarketData.Count())
                {
                    MessageBox.Show("行情服务器信息不全");
                    break;
                }

                if (string.IsNullOrEmpty(account.InvestorId)
                || string.IsNullOrEmpty(account.Password))
                {
                    MessageBox.Show("账号信息不全");
                    break;
                }

                bCheckOk = true;

            } while (false);

            if (false == bCheckOk)
            {
                ChangeStatus(ProviderStatus.Disconnected);
                EmitDisconnectedEvent();
                return;
            }

            //新建目录
            _newTempPath = ApiTempPath + Path.DirectorySeparatorChar + server.BrokerID + Path.DirectorySeparatorChar + account.InvestorId;
            Directory.CreateDirectory(_newTempPath);

            ChangeStatus(ProviderStatus.Connecting);
            //如果前面一次连接一直连不上,新改地址后也会没响应,所以先删除
            Disconnect_MD();
            Disconnect_TD();

            Connect_MsgQueue();
            if (_bWantMdConnect)
            {
                Connect_MD();
            }
            if (_bWantTdConnect)
            {
                Connect_TD();
            }

            if (_bWantMdConnect||_bWantTdConnect)
            {
                //建立消息队列读取线程
                if (null == _thread)
                {
                    _runThread = true;
                    _thread = new Thread(new ThreadStart(ThreadProc));
                    _thread.Start();
                }
            }
        }