예제 #1
0
파일: MarketTcpIp.cs 프로젝트: ssh352/ctp-1
        /// <summary>
        /// 接受行情
        /// </summary>
        /// <param name="obj"></param>
        public override void doOneReceivedData(string str)
        {
            try
            {
                if (!string.IsNullOrEmpty(str))
                {
                    NetInfo ni = new NetInfo();
                    ni.MyReadString(str);
                    if (!string.IsNullOrEmpty(ni.infoT) && ni.code == CommandCode.MARKET01)
                    {
                        if (mainWindow != null)
                        {
                            //将行情收到阻塞线程里面
                            MarketInfo data = new MarketInfo();
                            data.MyReadString(ni.infoT);

                            //if (mainWindow.DaFutures.Equals(mainWindow.marketType))
                            //{
                            //    if ("2".Equals(data.type))
                            //    {
                            //        //if (data.code == "CL1609")
                            //        //{
                            //        //}
                            //        if ("0".Equals(data.currPrice) || "0".Equals(data.currNumber))
                            //        {
                            //            return;
                            //        }
                            //        mainWindow.AddMarketBlock(data);
                            //    }
                            //}
                            //else
                            //{
                            //    if ("0".Equals(data.currPrice) || "0".Equals(data.currNumber))
                            //    {
                            //        return;
                            //    }
                            //    mainWindow.AddMarketBlock(data);
                            //}
                            if (mainWindow.marketBlockingCollection.Count > 500)
                            {
                                Console.WriteLine(mainWindow.marketBlockingCollection.Count);
                                //超过500项先扔掉
                                return;
                            }
                            mainWindow.AddMarketBlock(data);
                        }
                    }
                    else if ((!string.IsNullOrEmpty(ni.infoT) && ni.code == CommandCode.GetSettlePrice))
                    {
                        string   temp = ni.infoT;
                        string[] arr  = temp.Split('^');
                        for (int i = 0; i < arr.Count(); i++)
                        {
                            string     t     = arr[i];
                            string[]   value = t.Split('@');
                            MarketInfo data  = new MarketInfo();
                            data.code     = value[0];
                            data.oldClose = value[1];
                            mainWindow.AddMarketBlock(data);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                mainWindow.marketErrorLoger.log(LogLevel.SYSTEMERROR, str + Environment.NewLine + ex.ToString());
            }
        }