示例#1
0
        /// <summary>
        /// Gets an list of ticks for a given CoinAPI source file.
        /// </summary>
        /// <param name="entryData">The entry data.</param>
        /// <param name="file">The file.</param>
        /// <returns></returns>
        /// <exception cref="Exception">CoinApiDataReader.ProcessCoinApiEntry(): CSV header not found for entry name: {entryData.Name}</exception>
        public IEnumerable <Tick> ProcessCoinApiEntry(CoinApiEntryData entryData, FileInfo file)
        {
            Log.Trace("CoinApiDataReader.ProcessTarEntry(): Processing " +
                      $"{entryData.Symbol.ID.Market}-{entryData.Symbol.Value}-{entryData.TickType} " +
                      $"for {entryData.Date:yyyy-MM-dd}");


            using (var stream = new GZipStream(file.OpenRead(), CompressionMode.Decompress))
                using (var reader = new StreamReader(stream))
                {
                    var headerLine = reader.ReadLine();
                    if (headerLine == null)
                    {
                        throw new Exception($"CoinApiDataReader.ProcessCoinApiEntry(): CSV header not found for entry name: {entryData.Name}");
                    }

                    var headerParts = headerLine.Split(';').ToList();

                    var tickList = entryData.TickType == TickType.Trade
                    ? ParseTradeData(entryData.Symbol, reader, headerParts)
                    : ParseQuoteData(entryData.Symbol, reader, headerParts);

                    foreach (var tick in tickList)
                    {
                        yield return(tick);
                    }
                }
        }
示例#2
0
        /// <summary>
        /// Gets an enumerable of ticks for the given CoinAPI tar entry
        /// </summary>
        /// <param name="tar">The tar input stream</param>
        /// <param name="entryData">The entry data</param>
        /// <returns>An <see cref="IEnumerable{Tick}"/> for the ticks read from the entry</returns>
        public IEnumerable <Tick> ProcessCoinApiEntry(TarInputStream tar, CoinApiEntryData entryData)
        {
            Log.Trace("CoinApiDataReader.ProcessTarEntry(): Processing " +
                      $"{entryData.Symbol.ID.Market}-{entryData.Symbol.Value}-{entryData.TickType} " +
                      $"for {entryData.Date:yyyy-MM-dd}");

            using (var gzipStream = new MemoryStream())
            {
                tar.CopyEntryContents(gzipStream);
                gzipStream.Seek(0, SeekOrigin.Begin);

                using (var innerStream = new GZipStream(gzipStream, CompressionMode.Decompress))
                {
                    using (var reader = new StreamReader(innerStream))
                    {
                        var headerLine = reader.ReadLine();
                        if (headerLine == null)
                        {
                            throw new Exception($"CoinApiDataReader.ProcessTarEntry(): CSV header not found for entry name: {entryData.Name}");
                        }

                        var headerParts = headerLine.Split(';').ToList();

                        var ticks = entryData.TickType == TickType.Trade
                            ? ParseTradeData(entryData.Symbol, reader, headerParts)
                            : ParseQuoteData(entryData.Symbol, reader, headerParts);

                        foreach (var tick in ticks)
                        {
                            yield return(tick);
                        }
                    }
                }
            }
        }