示例#1
0
        public void GetData()
        {
            List <RealtimeDataCenter.RealtimeData> ltRd = new List <RealtimeDataCenter.RealtimeData>();
            StringBuilder sErrInfo = new StringBuilder(256);
            StringBuilder sResult  = new StringBuilder(1024 * 1024);

            while (true)
            {
                if (!isTradingTime(DateTime.Now))
                {
                    System.Threading.Thread.Sleep(1000);
                    continue;
                }

                int idConn = ThreadGetDataFromTradeX.connectTDX();
                if (idConn < 0)
                {
                    Console.WriteLine("没有可用的TDX行情服务器!  请检查网络...... 重连......" + DateTime.Now);

                    System.Threading.Thread.Sleep(1000);

                    continue;
                }

                bool bRet = true;
                while (bRet)
                {
                    if (!isTradingTime(DateTime.Now))
                    {
                        bRet = false;
                        TradeXB.TdxHq_Disconnect(idConn);
                        Console.WriteLine("is not trading time");

                        break;
                    }

                    if (this.bChanged)
                    {
                        generateCodeMarketGrp();
                    }

                    foreach (var item in ltCodeMarket)
                    {
                        sResult.Clear();
                        sErrInfo.Clear();
                        short count = item.Item3[0];

                        bRet = TradeXB.TdxHq_GetSecurityQuotes(idConn, item.Item2, item.Item1, ref count, sResult, sErrInfo);
                        if (bRet)
                        {
                            string[] rows = sResult.ToString().Split(new char[] { '\n' });
                            foreach (var row in rows)
                            {
                                RealtimeDataCenter.RealtimeData rd = analyseRD(row);
                                if (null != rd)
                                {
                                    ltRd.Add(rd);
                                }
                            }

                            if (ltRd.Count > 0)
                            {
                                this.rdc.recv(ltRd);
                                ltRd.Clear();
                            }
                        }
                        else
                        {
                            string szErrorInfo = sErrInfo.ToString();
                            Console.WriteLine(szErrorInfo);
                            if (szErrorInfo.Contains("连接断开"))
                            {
                                TradeXB.TdxHq_Disconnect(idConn);

                                break;
                            }
                        }
                    }

                    if (bRet)
                    {
                        System.Threading.Thread.Sleep(800);
                    }
                }

                TradeXB.TdxHq_Disconnect(idConn);
                System.Threading.Thread.Sleep(1000);
            }
        }