示例#1
0
        void _ResolveL1Quote(BinaryReader br)
        {
            if (_dictSERef == null)
            {
                return;
            }

            int count = br.ReadInt32();
            int size  = br.ReadInt32();

            _hsAltered.Clear();
            for (int i = 0; i < count; i++)
            {
                var code = Encoding.ASCII.GetString(br.ReadBytes(16)).ToLower().Substring(1).Split(new char[] { '\0' })[0];
                if (code.Length == 0)
                {
                    br.ReadBytes(170 - 16);
                    break;
                }
                var name   = Encoding.GetEncoding(936).GetString(br.ReadBytes(16)).Split(new char[] { '\0' })[0];
                var factor = code.StartsWith("h510") || code.StartsWith("z160") ? 1000.0f : 100.0f;
                var pc     = br.ReadInt32() / factor;
                var lh     = br.ReadInt32() / factor;
                var ll     = br.ReadInt32() / factor;

                StockEntity se = null;
                if (_dictSERef.ContainsKey(code))
                {
                    se = _dictSERef[code];
                }
                else
                {
                    se = new StockEntity()
                    {
                        UniqueCode = code,
                        Code       = code.Substring(1),
                        Name       = name
                    };
                    _dictSERef[code] = se;
                }

                DateTime dt;
                lock (se)
                {
                    se.PreClose  = pc;
                    se.LimitHigh = lh;
                    se.LimitLow  = ll;

                    br.ReadBytes(2);     // 忽略一个字段SHORT
                    dt = _dtScrach.AddSeconds(br.ReadUInt32());

                    se.Open    = br.ReadInt32() / factor;
                    se.Highest = br.ReadInt32() / factor;
                    se.Lowest  = br.ReadInt32() / factor;
                    se.Latest  = br.ReadInt32() / factor;
                    var VOL     = br.ReadUInt32() * 100;
                    var VOL_old = se.TotalVolume;
                    se.TotalVolume = VOL;

                    if (VOL > VOL_old)
                    {
                        se.DataInfoList.Add(new NewDataInfo()
                        {
                            Delta_num  = (int)(VOL - VOL_old),
                            Close_num  = (int)VOL,
                            Last_price = se.Latest,
                            Time       = dt.ToString("hh:mm:ss")
                        });

                        if (se.DataInfoList.Count > 30)
                        {
                            se.DataInfoList.RemoveAt(0);
                        }
                    }

                    se.TotalAmount     = (UInt64)br.ReadDouble();
                    se.TotalDealtCount = br.ReadUInt32();

                    for (int k = 0; k < 5; k++)
                    {
                        se.BidPairs[k].Price = br.ReadInt32() / factor;
                    }
                    for (int k = 0; k < 5; k++)
                    {
                        se.BidPairs[k].Count = br.ReadInt32() * 100;
                    }
                    for (int k = 0; k < 5; k++)
                    {
                        se.AskPairs[k].Price = br.ReadInt32() / factor;
                    }
                    for (int k = 0; k < 5; k++)
                    {
                        se.AskPairs[k].Count = br.ReadInt32() * 100;
                    }
                }

                var rn1 = br.ReadInt32();
                var rn2 = br.ReadInt32();

                _hsAltered.Add(se.UniqueCode);
                //if(se.UniqueCode.Contains("002796"))
                writelog(DateTime.Now.ToString("yyyyMMdd") + "\\盘口\\" + se.Code + ".txt", string.Format("收到 {0} 卖一盘口:{1},{2}", se.Name, se.AskPairs[0].Price, se.AskPairs[0].Count));
                //writelog("dzh_log_pk.txt", string.Format("收到 {0} 买一盘口:{1},{2}", se.Name, se.BidPairs[0].Price, se.BidPairs[0].Count));

                //Console.ForegroundColor = ConsoleColor.Red;
                //Console.Write("new quote arrvies:");
                //Console.ForegroundColor = ConsoleColor.Green;
                //Console.Write(string.Format("{0} 最新价:{1} 时间:{2}\n", se.UniqueCode, se.Latest, dt.ToShortTimeString()));
            }
        }