21 using System.Collections.Generic;
45 var prefilteredSecond = second.PrefilterUsing(first);
50 isUniverseSubscription:
true,
51 universe: prefilteredSecond,
53 configuration: configurationPerSymbol ?
new SubscriptionDataConfig(prefilteredSecond.Configuration, symbol: security.Symbol) : prefilteredSecond.Configuration,
54 startTimeUtc: currentTimeUtc - prefilteredSecond.Configuration.
Resolution.ToTimeSpan(),
55 endTimeUtc: currentTimeUtc.AddSeconds(-1)
76 clone.Data = clone.Data.Where(d => first.
ContainsMember(d.Symbol)).ToList();
144 throw new NotImplementedException($
"The specified security type is not implemented yet: {securityType}");
147 return new Symbol(sid, ticker);
157 var universeDataBySymbol =
new Dictionary<Symbol, DerivativeUniverseData>();
160 universeDataBySymbol.Clear();
162 foreach (var downloaderParameters
in universeDownloaderParameters)
164 Log.
Debug($
"{nameof(UniverseExtensions)}.{nameof(RunUniverseDownloader)}:Generating universe for {downloaderParameters.Symbol} on {processingDate:yyyy/MM/dd}");
166 var historyData = dataDownloader.
Get(downloaderParameters);
168 if (historyData ==
null)
170 Log.
Debug($
"{nameof(UniverseExtensions)}.{nameof(RunUniverseDownloader)}: No data available for the following parameters: {universeDownloadParameters}");
174 foreach (var baseData
in historyData)
179 if (!universeDataBySymbol.TryAdd(tradeBar.Symbol,
new(tradeBar)))
181 universeDataBySymbol[tradeBar.Symbol].UpdateByTradeBar(tradeBar);
185 if (!universeDataBySymbol.TryAdd(openInterest.Symbol,
new(openInterest)))
187 universeDataBySymbol[openInterest.Symbol].UpdateByOpenInterest(openInterest);
191 if (!universeDataBySymbol.TryAdd(quoteBar.Symbol,
new(quoteBar)))
193 universeDataBySymbol[quoteBar.Symbol].UpdateByQuoteBar(quoteBar);
197 throw new InvalidOperationException($
"{nameof(UniverseExtensions)}.{nameof(RunUniverseDownloader)}: Unexpected data type encountered.");
202 if (universeDataBySymbol.Count == 0)
207 using var writer =
new StreamWriter(universeDownloadParameters.
GetUniverseFileName(processingDate));
209 writer.WriteLine($
"#{OptionUniverse.CsvHeader}");
212 foreach (var universeData
in universeDataBySymbol
213 .OrderBy(x => x.Key.Underlying !=
null)
214 .ThenBy(d => d.Key.SecurityType.IsOption() ? d.Key.ID.OptionRight : 0)
215 .ThenBy(d => d.Key.SecurityType.IsOption() ? d.Key.ID.StrikePrice : 0)
216 .ThenBy(d => d.Key.ID.Date)
217 .ThenBy(d => d.Key.ID))
219 writer.WriteLine(universeData.Value.ToCsv());
222 Log.
Trace($
"{nameof(UniverseExtensions)}.{nameof(RunUniverseDownloader)}:Generated for {universeDownloadParameters.Symbol} on {processingDate:yyyy/MM/dd} with {universeDataBySymbol.Count} entries");