internal CandleHeader(SecDBFileReader file,
                       ushort resolutionSec,
                       uint startTimeOffsetSec,
                       DateTime startTimeDt,
                       uint count,
                       uint offset)
 {
     File          = file;
     ResolutionSec = resolutionSec;
     StartTimeMidnightOffsetSec = startTimeOffsetSec;
     StartTime   = startTimeDt;
     CandleCount = count;
     DataOffset  = offset;
 }
            internal QuoteSample(SecDBFileReader file, QuoteSample ps, DateTime ts, Stream stream) : base(ts)
            {
                var bt = SecDBPrimitives.ReadByte(stream);

                BidCount = bt & 0xf;
                AskCount = (bt & 0xf0) >> 4;
                var cnt = BidCount + AskCount;

                if (cnt == 0)
                {
                    throw new FinancialException(StringConsts.SECDB_FILE_HEADER_ERROR + "QuoteSample: no px levels");
                }

                PriceLevels = new PxLevel[cnt];

                var pxStep = file.SystemHeader.PriceStep;

                var currentPrice = 0L;

                for (var i = 0; i < cnt; i++)
                {
                    var price = SecDBPrimitives.ReadSLEB128(stream);
                    if (i == 0)
                    {
                        if (ps == null)
                        {
                            currentPrice = price;
                        }
                        else
                        {
                            currentPrice  = ps.PriceLevels[0].PriceStep;
                            currentPrice += price;
                        }
                    }
                    else
                    {
                        currentPrice += price;
                    }

                    var qty = SecDBPrimitives.ReadSLEB128(stream);

                    var pl = new PxLevel {
                        PriceStep = currentPrice, Price = currentPrice * pxStep, Quantity = qty
                    };
                    PriceLevels[i] = pl;
                }
            }
            internal CandleData(SecDBFileReader file, int sampleNumber, DateTime timestamp, Stream stream)
            {
                File = file;

                SampleNumber = sampleNumber;
                TimeStamp    = timestamp;

                OpenSteps  = SecDBPrimitives.ReadInt32(stream);
                HighSteps  = SecDBPrimitives.ReadInt32(stream);
                LowSteps   = SecDBPrimitives.ReadInt32(stream);
                CloseSteps = SecDBPrimitives.ReadInt32(stream);

                BuyVolume  = SecDBPrimitives.ReadInt32(stream);
                SellVolume = SecDBPrimitives.ReadInt32(stream);

                FirstStreamOffset = SecDBPrimitives.ReadUInt64(stream);
            }
            internal OrderSample(SecDBFileReader file, OrderSample ps, DateTime ts, Stream stream) : base(ts)
            {
                var flags = SecDBPrimitives.ReadByte(stream);

                InternalOrder = (flags & (1)) != 0;
                CancelAll     = (flags >> 1) != 0;

                if (!CancelAll)
                {
                    IsActive      = (flags >> 2) != 0;
                    IsReplacement = (flags >> 3) != 0;
                    Side          = (SideType)((flags >> 4) & 0x1);

                    IsTakeProfit = (flags >> 5) != 0;
                    IsStopLoss   = (flags >> 6) != 0;

                    OrderID = SecDBPrimitives.ReadSLEB128(stream);

                    if (IsActive)
                    {
                        var price = SecDBPrimitives.ReadSLEB128(stream);
                        if (ps == null)
                        {
                            PriceStep = price;
                        }
                        else
                        {
                            PriceStep = ps.PriceStep + price;
                        }

                        Price = PriceStep * file.SystemHeader.PriceStep;

                        Qty = SecDBPrimitives.ReadSLEB128(stream);
                    }

                    if (IsReplacement)
                    {
                        OldOrderID = SecDBPrimitives.ReadSLEB128(stream);
                    }
                }
            }
            internal TradeSample(SecDBFileReader file, TradeSample ps, DateTime ts, Stream stream) : base(ts)
            {
                var flags = SecDBPrimitives.ReadByte(stream);

                InternalTrade = (flags & (1)) != 0;
                Aggressor     = (AggressorType)((flags >> 1) & 0x3);
                Side          = (SideType)((flags >> 3) & 0x1);

                IsQty     = (flags & (1 << 4)) != 0;
                IsTradeID = (flags & (1 << 5)) != 0;
                IsOrderID = (flags & (1 << 6)) != 0;

                var price = SecDBPrimitives.ReadSLEB128(stream);

                if (ps == null)
                {
                    PriceStep = price;
                }
                else
                {
                    PriceStep = ps.PriceStep + price;
                }

                Price = PriceStep * file.SystemHeader.PriceStep;

                if (IsQty)
                {
                    Qty = SecDBPrimitives.ReadSLEB128(stream);
                }
                if (IsTradeID)
                {
                    TradeID = SecDBPrimitives.ReadULEB128(stream);
                }
                if (IsOrderID)
                {
                    OrderID = SecDBPrimitives.ReadULEB128(stream);
                }
            }
 internal CandlesMeta(SecDBFileReader file, CandleHeader[] candles)
 {
     File = file; Candles = candles;
 }