Exemplo n.º 1
0
        // **********************************************************************

        public override void Read(bool push)
        {
            DealFlags flags = (DealFlags)dr.ReadByte();

            // ------------------------------------------------------------

            if ((flags & DealFlags.DateTime) != 0)
            {
                lastMilliseconds = dr.ReadGrowing(lastMilliseconds);
            }

            if ((flags & DealFlags.Id) != 0)
            {
                lastId = dr.ReadGrowing(lastId);
            }

            if ((flags & DealFlags.OrderId) != 0)
            {
                lastOrderId += dr.ReadLeb128();
            }

            if ((flags & DealFlags.Price) != 0)
            {
                lastPrice += (int)dr.ReadLeb128();
            }

            if ((flags & DealFlags.Volume) != 0)
            {
                lastVolume = (int)dr.ReadLeb128();
            }

            if ((flags & DealFlags.OI) != 0)
            {
                lastOI += (int)dr.ReadLeb128();
            }

            // ------------------------------------------------------------

            if (push && Handler != null)
            {
                Handler(new Deal()
                {
                    SecKey   = Security.Key,
                    Type     = (DealType)(flags & DealFlags.Type),
                    Id       = lastId,
                    OrderId  = lastOrderId,
                    DateTime = DateTimeHelper.FromMs(lastMilliseconds),
                    Price    = lastPrice,
                    Volume   = lastVolume,
                    OI       = lastOI
                });
            }
        }
Exemplo n.º 2
0
        // **********************************************************************

        public void Write(DateTime dateTime, Deal deal)
        {
            dw.WriteRecHeader(sid, dateTime);

            // ------------------------------------------------------------

            long      milliseconds = DateTimeHelper.ToMs(deal.DateTime);
            DealFlags flags        = (DealFlags)deal.Type & DealFlags.Type;

            if (lastMilliseconds != milliseconds)
            {
                flags |= DealFlags.DateTime;
            }

            if (deal.Id != 0)
            {
                flags |= DealFlags.Id;
            }

            //if(deal.OrderId != 0)
            //  flags |= DealFlags.OrderId;

            if (lastRawPrice != deal.Price)
            {
                lastRawPrice = deal.Price;
                flags       |= DealFlags.Price;
            }

            if (lastVolume != deal.Volume)
            {
                flags |= DealFlags.Volume;
            }

            if (lastOI != deal.OI)
            {
                flags |= DealFlags.OI;
            }

            // ------------------------------------------------------------

            dw.Write((byte)flags);

            // ------------------------------------------------------------

            if ((flags & DealFlags.DateTime) != 0)
            {
                dw.WriteGrowing(milliseconds, ref lastMilliseconds);
            }

            if ((flags & DealFlags.Id) != 0)
            {
                dw.WriteGrowing(deal.Id, ref lastId);
            }

            if ((flags & DealFlags.Price) != 0)
            {
                int p = s.GetTicks(deal.Price);

                dw.WriteLeb128(p - lastPrice);
                lastPrice = p;
            }

            if ((flags & DealFlags.Volume) != 0)
            {
                dw.WriteLeb128(deal.Volume);
                lastVolume = deal.Volume;
            }

            if ((flags & DealFlags.OI) != 0)
            {
                dw.WriteLeb128(deal.OI - lastOI);
                lastOI = deal.OI;
            }

            // ------------------------------------------------------------
        }