17 using System.Collections.Generic;
35 private readonly DateTime _date;
36 private readonly
string _zipPath;
37 private readonly
string _zipentry;
70 string zipEntry =
null;
72 var isFutureOrOption = filepath.Contains(
'#', StringComparison.InvariantCulture);
76 zipEntry = filepath.Split(
'#')[1];
77 filepath = filepath.Split(
'#')[0];
80 var fileInfo =
new FileInfo(filepath);
81 if (!
LeanData.
TryParsePath(fileInfo.FullName, out symbol, out date, out resolution, out var tickType, out var dataType))
83 throw new ArgumentException($
"File {filepath} cannot be parsed.");
92 var dataTimeZone = marketHoursDataBase.
GetDataTimeZone(symbol.ID.Market, symbol, symbol.SecurityType);
93 var exchangeTimeZone = marketHoursDataBase.GetExchangeHours(symbol.ID.Market, symbol, symbol.SecurityType).TimeZone;
96 dataTimeZone, exchangeTimeZone, tickType: tickType,
97 fillForward:
false, extendedHours:
true, isInternalFeed:
true);
100 _zipPath = fileInfo.FullName;
101 _zipentry = zipEntry;
109 public IEnumerable<BaseData>
Parse()
111 if (!File.Exists(_zipPath))
113 Log.
Error($
"LeanDataReader.Parse(): File does not exist: {_zipPath}");
119 if (_config.Type.ImplementsStreamReader())
121 using (var zip =
new ZipFile(_zipPath))
123 foreach (var zipEntry
in zip.Where(x => _zipentry ==
null ||
string.Equals(x.FileName, _zipentry, StringComparison.OrdinalIgnoreCase)))
126 var symbol = _config.Symbol;
127 if(_zipentry ==
null && (_config.SecurityType ==
SecurityType.Future || _config.SecurityType.IsOption()))
131 using (var entryReader =
new StreamReader(zipEntry.OpenReader()))
133 while (!entryReader.EndOfStream)
135 var dataPoint = factory.Reader(_config, entryReader, _date,
false);
136 dataPoint.
Symbol = symbol;
137 yield
return dataPoint;
144 else if (_zipentry ==
null && (_config.SecurityType ==
SecurityType.Future || _config.SecurityType.IsOption()))
150 foreach (var line
in entries.Value)
152 var dataPoint = factory.Reader(_config, line, _date,
false);
153 dataPoint.
Symbol = symbol;
154 yield
return dataPoint;
163 if (unzipped ==
null)
166 while ((line = unzipped.ReadLine()) !=
null)
168 yield
return factory.Reader(_config, line, _date,
false);
181 return _config.DataTimeZone;
190 return _config.ExchangeTimeZone;