Example #1
0
        /// <summary>
        /// Enumerate over the tick zip file and return a list of BaseData.
        /// </summary>
        /// <returns>IEnumerable of ticks</returns>
        public IEnumerable <BaseData> Parse()
        {
            var     factory = (BaseData)ObjectActivator.GetActivator(_config.Type).Invoke(new object[0]);
            ZipFile zipFile;

            using (var unzipped = Compression.Unzip(_zipPath, out zipFile))
            {
                string line;
                while ((line = unzipped.ReadLine()) != null)
                {
                    yield return(factory.Reader(_config, line, _date, false));
                }
            }
            zipFile.Dispose();
        }
Example #2
0
        /// <summary>
        /// Enumerate over the tick zip file and return a list of BaseData.
        /// </summary>
        /// <returns>IEnumerable of ticks</returns>
        public IEnumerable <BaseData> Parse()
        {
            var factory = (BaseData)ObjectActivator.GetActivator(_config.Type).Invoke(new object[0]);

            // for futures and options if no entry was provided we just read all
            if (_zipentry == null && (_config.SecurityType == SecurityType.Future || _config.SecurityType == SecurityType.Option || _config.SecurityType == SecurityType.FutureOption))
            {
                foreach (var entries in Compression.Unzip(_zipPath))
                {
                    // we get the contract symbol from the zip entry
                    var symbol = LeanData.ReadSymbolFromZipEntry(_config.Symbol, _config.Resolution, entries.Key);
                    foreach (var line in entries.Value)
                    {
                        var dataPoint = factory.Reader(_config, line, _date, false);
                        dataPoint.Symbol = symbol;
                        yield return(dataPoint);
                    }
                }
            }
            else
            {
                ZipFile zipFile;
                using (var unzipped = Compression.Unzip(_zipPath, _zipentry, out zipFile))
                {
                    if (unzipped == null)
                    {
                        yield break;
                    }
                    string line;
                    while ((line = unzipped.ReadLine()) != null)
                    {
                        yield return(factory.Reader(_config, line, _date, false));
                    }
                }
                zipFile.Dispose();
            }
        }
Example #3
0
        /// <summary>
        /// Enumerate over the tick zip file and return a list of BaseData.
        /// </summary>
        /// <returns>IEnumerable of ticks</returns>
        public IEnumerable <BaseData> Parse()
        {
            if (!File.Exists(_zipPath))
            {
                Log.Error($"LeanDataReader.Parse(): File does not exist: {_zipPath}");
                yield break;
            }

            var factory = (BaseData)ObjectActivator.GetActivator(_config.Type).Invoke(new object[0]);

            if (_config.Type.ImplementsStreamReader())
            {
                using (var zip = new ZipFile(_zipPath))
                {
                    foreach (var zipEntry in zip.Where(x => _zipentry == null || string.Equals(x.FileName, _zipentry, StringComparison.OrdinalIgnoreCase)))
                    {
                        // we get the contract symbol from the zip entry if not already provided with the zip entry
                        var symbol = _config.Symbol;
                        if (_zipentry == null && (_config.SecurityType == SecurityType.Future || _config.SecurityType.IsOption()))
                        {
                            symbol = LeanData.ReadSymbolFromZipEntry(_config.Symbol, _config.Resolution, zipEntry.FileName);
                        }
                        using (var entryReader = new StreamReader(zipEntry.OpenReader()))
                        {
                            while (!entryReader.EndOfStream)
                            {
                                var dataPoint = factory.Reader(_config, entryReader, _date, false);
                                dataPoint.Symbol = symbol;
                                yield return(dataPoint);
                            }
                        }
                    }
                }
            }
            // for futures and options if no entry was provided we just read all
            else if (_zipentry == null && (_config.SecurityType == SecurityType.Future || _config.SecurityType.IsOption()))
            {
                foreach (var entries in Compression.Unzip(_zipPath))
                {
                    // we get the contract symbol from the zip entry
                    var symbol = LeanData.ReadSymbolFromZipEntry(_config.Symbol, _config.Resolution, entries.Key);
                    foreach (var line in entries.Value)
                    {
                        var dataPoint = factory.Reader(_config, line, _date, false);
                        dataPoint.Symbol = symbol;
                        yield return(dataPoint);
                    }
                }
            }
            else
            {
                ZipFile zipFile;
                using (var unzipped = Compression.Unzip(_zipPath, _zipentry, out zipFile))
                {
                    if (unzipped == null)
                    {
                        yield break;
                    }
                    string line;
                    while ((line = unzipped.ReadLine()) != null)
                    {
                        yield return(factory.Reader(_config, line, _date, false));
                    }
                }
                zipFile.Dispose();
            }
        }