Exemplo n.º 1
0
        private void parseCandlesMeta(Stream stream)
        {
            var bt = SecDBPrimitives.ReadByte(stream);

            if (bt != 0x03)//0x3 -  Candles metadata header
            {
                throw new FinancialException("CandlesMeta.Header != 0x03");
            }

            //Filler
            bt = SecDBPrimitives.ReadByte(stream);

            //HdrCount
            var icount = SecDBPrimitives.ReadUInt16(stream);

            var chdrs = new CandleHeader[icount];

            //CandleHeader
            for (var i = 0; i < icount; i++)
            {
                bt = SecDBPrimitives.ReadByte(stream);
                if (bt != 0x04)//0x4 -  Candle Header
                {
                    throw new FinancialException("CandleHeader.Header != 0x04");
                }

                //Filler
                bt = SecDBPrimitives.ReadByte(stream);

                var resolution = SecDBPrimitives.ReadUInt16(stream);
                var starttime  = SecDBPrimitives.ReadUInt32(stream);
                var count      = SecDBPrimitives.ReadUInt32(stream);
                var offset     = SecDBPrimitives.ReadUInt32(stream);


                if (resolution == 0)
                {
                    throw new FinancialException("CandleHeader.Resolution == 0x00");
                }

                var sdt = new DateTime(m_SystemHeader.Date.Year,
                                       m_SystemHeader.Date.Month,
                                       m_SystemHeader.Date.Day,
                                       0, 0, 0, DateTimeKind.Utc).AddSeconds(starttime);

                var ch = new CandleHeader(this, resolution, starttime, sdt, count, offset);
                chdrs[i] = ch;
            }
            m_Candles_Meta = new CandlesMeta(this, chdrs);
        }
Exemplo n.º 2
0
        private void parseMetadata(Stream stream)
        {
            var bt = SecDBPrimitives.ReadByte(stream);

            if (bt != 0x01)//0x1 - Streams header
            {
                throw new FinancialException("StreamsMeta.Header != 0x01");
            }

            //Compression
            bt = SecDBPrimitives.ReadByte(stream);
            if (bt == 0)
            {
                m_Streams_CompressionType = CompressionType.None;
            }
            else if (bt == 1)
            {
                m_Streams_CompressionType = CompressionType.GZip;
            }
            else
            {
                throw new FinancialException("StreamsMeta.Compression != 0 | 1");
            }

            //DataOffset
            m_Streams_DataOffset = SecDBPrimitives.ReadUInt32(stream);

            //Stream Count
            var scount = SecDBPrimitives.ReadByte(stream);

            m_Streams_Metas    = new StreamMeta[scount + 1];
            m_Streams_Metas[0] = new StreamMeta(StreamID.Seconds);

            //StreamMeta
            for (var i = 1; i <= scount; i++) //<= as scount does not include zeros element which is mandatory
            {
                bt = SecDBPrimitives.ReadByte(stream);
                if (bt != 0x02)//0x2 - Stream header
                {
                    throw new FinancialException("StreamMeta.Header != 0x02");
                }

                //StreamID
                bt = SecDBPrimitives.ReadByte(stream);
                if (bt > (byte)StreamID.MAX_ID)
                {
                    throw new FinancialException("StreamMeta.StreamID {0} = invalid".Args(bt));
                }

                var sid = (StreamID)bt;
                m_Streams_Metas[i] = new StreamMeta(sid);
            }

            //CandlesMeta
            parseCandlesMeta(stream);

            //Verify data start
            //Beginning of Stream Data Marker
            stream.Seek(m_Streams_DataOffset, SeekOrigin.Begin);
            var magic = SecDBPrimitives.ReadUInt32(stream);

            if (magic != 0xABBABABA)
            {
                throw new FinancialException("StreamDataMarker != 0xABBABABA");
            }
        }