/// <summary>
        /// распаковать если необходимо
        /// </summary>
        public List<CandleDataPacked> GetCandles()
        {
            if (!packed) return unpacked;

            var result = new List<CandleDataPacked>(count);
            var unpackedStream = method == PackedMethod.FastGZip
                ? UnpackBytesGZip(candleStream)
                : CompressionHelper.DecompressBytes(candleStream);
            const int quoteSz = SizeofTime + SizeofPrice + SizeofHLC;
            var size = count * quoteSz;
            CandleDataPacked previousCandle = null;

            for (var offset = 0; offset < size; offset += quoteSz)
            {
                var q = new CandleDataPacked
                {
                    timeOpen = new DateTime(BitConverter.ToInt64(unpackedStream, offset)),
                    open = BitConverter.ToSingle(unpackedStream, offset + SizeofTime),
                    HLC = BitConverter.ToInt32(unpackedStream, offset + SizeofTime + SizeofPrice)
                };
                q.close = q.open; // default
                if (previousCandle != null)
                    previousCandle.close = q.open;
                previousCandle = q;
                result.Add(q);
            }

            return result;
        }
Example #2
0
        /// <summary>
        /// распаковать если необходимо
        /// </summary>
        public List <CandleDataPacked> GetCandles()
        {
            if (!packed)
            {
                return(unpacked);
            }

            var result         = new List <CandleDataPacked>(count);
            var unpackedStream = method == PackedMethod.FastGZip
                ? UnpackBytesGZip(candleStream)
                : CompressionHelper.DecompressBytes(candleStream);
            const int        quoteSz        = SizeofTime + SizeofPrice + SizeofHLC;
            var              size           = count * quoteSz;
            CandleDataPacked previousCandle = null;

            for (var offset = 0; offset < size; offset += quoteSz)
            {
                var q = new CandleDataPacked
                {
                    timeOpen = new DateTime(BitConverter.ToInt64(unpackedStream, offset)),
                    open     = BitConverter.ToSingle(unpackedStream, offset + SizeofTime),
                    HLC      = BitConverter.ToInt32(unpackedStream, offset + SizeofTime + SizeofPrice)
                };
                q.close = q.open; // default
                if (previousCandle != null)
                {
                    previousCandle.close = q.open;
                }
                previousCandle = q;
                result.Add(q);
            }

            return(result);
        }
        /// <summary>
        /// Вызывает хранимую процедуру 'GetLastQuote' или 'FindQuote'
        /// </summary>
        public QuoteData GetQuoteStoredProc(string ticker, DateTime? start = null)
        {
            if (string.IsNullOrEmpty(ticker)) return null;

            SqlConnection conn = null;
            SqlDataReader rdr = null;
            var tickerId = DalSpot.Instance.GetFXICodeBySymbol(ticker);
            var date = default(DateTime);
            var open = -1f;
            var lhc = -1;

            try
            {
                var connectionString = ConfigurationManager.ConnectionStrings["QuoteBase"].ConnectionString;
                conn = new SqlConnection(connectionString);
                conn.Open();

                var procName = start.HasValue ? "FindQuote" : "GetLastQuote";

                var cmd = new SqlCommand(procName, conn) { CommandType = CommandType.StoredProcedure };
                cmd.Parameters.Add(new SqlParameter("@ticker", tickerId));
                if (start.HasValue) cmd.Parameters.Add(new SqlParameter("@date", start.Value));

                rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    if (!int.TryParse(rdr["ticker"].ToString(), out tickerId)) return null;
                    if (!DateTime.TryParse(rdr["date"].ToString(), out date)) return null;
                    if (!float.TryParse(rdr["open"].ToString(), out open)) return null;
                    if (!int.TryParse(rdr["HLC"].ToString(), out lhc)) return null;
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Ошибка в методе GetQuoteStoredProc", ex);
                return null;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
                if (rdr != null)
                {
                    rdr.Close();
                }
            }

            var candelDataPacked = new CandleDataPacked
            {
                HLC = lhc,
                open = open,
                timeOpen = date,
                close = open // default
            };
            var candleData = new CandleData(candelDataPacked, DalSpot.Instance.GetPrecision10(ticker));
            var useOpen = start.HasValue && date == start.Value;
            return GetQuoteWithDefaultSpread(candleData, ticker, useOpen);
        }
Example #4
0
 public CandleData(CandleDataPacked spec, int pointCost)
 {
     open = spec.open;
     timeOpen = spec.timeOpen;
     timeClose = spec.timeOpen.AddMinutes(1);
     close = spec.close;
     MakeHlcFromOffset16(spec.HLC, pointCost);
 }