public SnapShot(RespRefreshSymbolPacket rp)
 {
     this.rp = rp;
     Volume  = BitConverter.ToInt32(rp.rawPayload, 62);
     //int vol = BitConverter.ToInt32(rp.rawPayload, 66);
     Bid     = rp.getPrice(rp.rawPayload, 70);
     Ask     = rp.getPrice(rp.rawPayload, 78);
     Last    = rp.getPrice(rp.rawPayload, 86);
     Low     = rp.getPrice(rp.rawPayload, 118);
     High    = rp.getPrice(rp.rawPayload, 110);
     Open    = rp.getPrice(rp.rawPayload, 94);
     Close   = rp.getPrice(rp.rawPayload, 102);
     BidSize = BitConverter.ToInt32(rp.rawPayload, 126);
     AskSize = BitConverter.ToInt32(rp.rawPayload, 130);
 }
Пример #2
0
        public static Packet GetPacket(Stream str)
        {
            byte[] lbuff  = new byte[2];
            int    count  = 0;
            ushort length = 0;

            byte[] pl = null;
            do
            {
                int lc = 0;
                do
                {
                    int c = str.Read(lbuff, lc, 2 - lc);
                    if (audit != null)
                    {
                        audit.Write(lbuff, lc, 2 - lc);
                    }
                    lc += c;
                } while (lc < 2);

                length = (ushort)(BitConverter.ToUInt16(lbuff, 0) - 2);
                int offset = 0;
                pl    = new byte[length];
                count = 0;
                while (count < length)
                {
                    int c = str.Read(pl, offset, length - count);
                    if (audit != null)
                    {
                        audit.Write(pl, offset, length - count);
                    }
                    count += c;
                    offset = count;
                }
                if (length < 2)
                {
                    Console.WriteLine("dropped packet");
                    //for(;;)
                    //{
                    //    Console.
                    //}
                }
            } while (length < 2);
            ushort pt = BitConverter.ToUInt16(pl, 0);

//            Console.WriteLine((PacketType)pt);
            if (pt != 501 && pt != 505 && pt != 504)
            {
                //Console.WriteLine((PacketType)pt);
            }
            Packet rv = null;

            // packetType = (PacketType)pt;
            switch ((PacketType)pt)
            {
            case PacketType.M_RESP_REFRESH_SYMBOL:
                rv = new RespRefreshSymbolPacket(length, pt, pl);
                break;

            case PacketType.M_LEVEL1:
                rv = new L1Packet(length, pt, pl);
                break;

            case PacketType.M_BOOK_MODIFY_QUOTE:
                rv = new BookModifyQuotePacket(length, pt, pl);
                break;

            case PacketType.M_BOOK_NEW_QUOTE:
                rv = new BookNewQuotePacket(length, pt, pl);
                break;

            case PacketType.M_BOOK_DELETE_QUOTE:
                rv = new BookDeleteQuotePacket(length, pt, pl);
                break;

            case PacketType.M_STOCK_IMBALANCE_INDICATOR:
                rv = new StockImbalanceIndicator(length, pt, pl);
                break;

            case PacketType.M_BOOK_ORDER_CANCELED:
                rv = new BookOrderCancelledPacket(length, pt, pl);
                break;

            case PacketType.M_BOOK_ORDER_EXECUTED:
                rv = new BookOrderExecutedPacket(length, pt, pl);
                break;

            case PacketType.M_TRADE_REPORT:
                rv = new TradeReportPacket(length, pt, pl);
                break;

            default:
                return(new Packet(length, pt, pl));
            }

            return(rv);
        }