Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,12 @@ protected virtual string GetUniverseFileName(Symbol canonicalSymbol)
protected virtual bool TryGenerateAndWriteUnderlyingLine(Symbol underlyingSymbol, MarketHoursDatabase.Entry marketHoursEntry,
StreamWriter writer, out IDerivativeUniverseFileEntry entry, out List<Slice> history)
{
GetHistoryTimeRange(PriceHistoryResolutions[0], marketHoursEntry, out var historyEndUtc, out var historyStartUtc);
var historyType = typeof(TradeBar);
GetHistoryTimeRange(PriceHistoryResolutions[0], historyType, marketHoursEntry, out var startUtc, out var endUtc);
var underlyingHistoryRequest = new HistoryRequest(
historyStartUtc,
historyEndUtc,
typeof(TradeBar),
startUtc,
endUtc,
historyType,
underlyingSymbol,
PriceHistoryResolutions[0],
marketHoursEntry.ExchangeHours,
Expand All @@ -291,7 +292,7 @@ protected virtual bool TryGenerateAndWriteUnderlyingLine(Symbol underlyingSymbol
includeExtendedMarketHours: false,
isCustomData: false,
DataNormalizationMode.ScaledRaw,
LeanData.GetCommonTickTypeForCommonDataTypes(typeof(TradeBar), _securityType));
LeanData.GetCommonTickTypeForCommonDataTypes(historyType, _securityType));

entry = CreateUniverseEntry(underlyingSymbol);
history = GetHistory(new[] { underlyingHistoryRequest }, marketHoursEntry.ExchangeHours.TimeZone, marketHoursEntry);
Expand Down Expand Up @@ -319,13 +320,13 @@ private List<Slice> GetHistory(HistoryRequest[] historyRequests,

foreach (var resolution in PriceHistoryResolutions)
{
GetHistoryTimeRange(resolution, marketHoursEntry, out var historyEndUtc, out var historyStartUtc);

var resolutionHistoryRequests = historyRequests.Select(x =>
{
var request = new HistoryRequest(x, x.Symbol, historyStartUtc, historyEndUtc);
request.Resolution = resolution;
return request;
var resolutionHistoryRequests = historyRequests.Select(request =>
{
GetHistoryTimeRange(resolution, request.DataType, marketHoursEntry, out var startUtc, out var endUtc);
var newRequest = new HistoryRequest(request, request.Symbol, startUtc, endUtc);
newRequest.Resolution = resolution;
return newRequest;
}).ToArray();

history = _historyProvider.GetHistory(resolutionHistoryRequests, sliceTimeZone).ToList();
Expand All @@ -338,15 +339,17 @@ private List<Slice> GetHistory(HistoryRequest[] historyRequests,
return history;
}

private void GetHistoryTimeRange(Resolution resolution, MarketHoursDatabase.Entry marketHoursEntry,
out DateTime historyEndUtc, out DateTime historyStartUtc)
private void GetHistoryTimeRange(Resolution resolution, Type dataType, MarketHoursDatabase.Entry marketHoursEntry,
out DateTime startUtc, out DateTime endUtc)
{
historyEndUtc = resolution != Resolution.Daily ? _processingDate : _processingDate.AddDays(1);
historyStartUtc = Time.GetStartTimeForTradeBars(marketHoursEntry.ExchangeHours, historyEndUtc, resolution.ToTimeSpan(),
var end = resolution != Resolution.Daily || dataType == typeof(OpenInterest)
? _processingDate
: _processingDate.AddDays(1);
var start = Time.GetStartTimeForTradeBars(marketHoursEntry.ExchangeHours, end, resolution.ToTimeSpan(),
_historyBarCount, false, marketHoursEntry.DataTimeZone);

historyEndUtc = historyEndUtc.ConvertToUtc(marketHoursEntry.ExchangeHours.TimeZone);
historyStartUtc = historyStartUtc.ConvertToUtc(marketHoursEntry.ExchangeHours.TimeZone);
endUtc = end.ConvertToUtc(marketHoursEntry.ExchangeHours.TimeZone);
startUtc = start.ConvertToUtc(marketHoursEntry.ExchangeHours.TimeZone);
}

/// <summary>
Expand All @@ -363,8 +366,7 @@ protected virtual IEnumerable<IDerivativeUniverseFileEntry> GenerateDerivativeEn
Log.Debug($"Generating universe entry for {symbol.Value}");
}

GetHistoryTimeRange(PriceHistoryResolutions[0], marketHoursEntry, out var historyEndUtc, out var historyStartUtc);
var historyRequests = GetDerivativeHistoryRequests(symbol, historyStartUtc, historyEndUtc, marketHoursEntry);
var historyRequests = GetDerivativeHistoryRequests(symbol, marketHoursEntry);

IDerivativeUniverseFileEntry entry;
if (historyRequests == null || historyRequests.Length == 0)
Expand All @@ -384,23 +386,25 @@ protected virtual IEnumerable<IDerivativeUniverseFileEntry> GenerateDerivativeEn
/// <summary>
/// Creates the requests to get the data to be used to generate the universe entry for the given derivative symbol
/// </summary>
protected virtual HistoryRequest[] GetDerivativeHistoryRequests(Symbol symbol, DateTime startUtc, DateTime endUtc,
MarketHoursDatabase.Entry marketHoursEntry)
protected virtual HistoryRequest[] GetDerivativeHistoryRequests(Symbol symbol, MarketHoursDatabase.Entry marketHoursEntry)
{
var dataTypes = new[] { typeof(TradeBar), typeof(QuoteBar), typeof(OpenInterest) };
return dataTypes.Select(dataType => new HistoryRequest(
startUtc,
endUtc,
dataType,
symbol,
PriceHistoryResolutions[0],
marketHoursEntry.ExchangeHours,
marketHoursEntry.DataTimeZone,
null,
includeExtendedMarketHours: false,
isCustomData: false,
DataNormalizationMode.ScaledRaw,
LeanData.GetCommonTickTypeForCommonDataTypes(dataType, _securityType))).ToArray();
return new[] { typeof(TradeBar), typeof(QuoteBar), typeof(OpenInterest) }.Select(dataType =>
{
GetHistoryTimeRange(PriceHistoryResolutions[0], dataType, marketHoursEntry, out var startUtc, out var endUtc);
return new HistoryRequest(
startUtc,
endUtc,
dataType,
symbol,
PriceHistoryResolutions[0],
marketHoursEntry.ExchangeHours,
marketHoursEntry.DataTimeZone,
null,
includeExtendedMarketHours: false,
isCustomData: false,
DataNormalizationMode.ScaledRaw,
LeanData.GetCommonTickTypeForCommonDataTypes(dataType, _securityType));
}).ToArray();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ protected override Dictionary<Symbol, List<Symbol>> FilterSymbols(Dictionary<Sym
/// <summary>
/// Adds a request for the mirror option symbol to the base list of requests.
/// </summary>
protected override HistoryRequest[] GetDerivativeHistoryRequests(Symbol symbol, DateTime start, DateTime end, MarketHoursDatabase.Entry marketHoursEntry)
protected override HistoryRequest[] GetDerivativeHistoryRequests(Symbol symbol, MarketHoursDatabase.Entry marketHoursEntry)
{
var requests = base.GetDerivativeHistoryRequests(symbol, start, end, marketHoursEntry);
var requests = base.GetDerivativeHistoryRequests(symbol, marketHoursEntry);

var mirrorOptionSymbol = OptionsUniverseGeneratorUtils.GetMirrorOptionSymbol(symbol);
var mirrorOptionHistoryRequests = base.GetDerivativeHistoryRequests(mirrorOptionSymbol, start, end, marketHoursEntry);
var mirrorOptionHistoryRequests = base.GetDerivativeHistoryRequests(mirrorOptionSymbol, marketHoursEntry);

return requests.Concat(mirrorOptionHistoryRequests).ToArray();
}
Expand Down
Loading