Add extendedMarket parameter to History methods (#7191)

* Add extendedMarket parameter to every history api method overload

* Rename extendedMarketHours parameter

New name is extendedHours as in the History API to standarize parameters naming

* Update generic history overloads to use every matching subscription

* Update regression algorithms stats

* Centralize period-based history error for tick resolution

* Rename extended market hours parameter to extendedMarketHours

* Minor changes

* Minor changes

* Minor unit tests changes

* Minor unit tests changes

* Minor changes

* Minor unit tests changes

* Minor unit tests changes
This commit is contained in:
Jhonathan Abreu
2023-04-20 09:41:32 -04:00
committed by GitHub
parent fb383dc73c
commit 3888896ed4
13 changed files with 833 additions and 203 deletions
+38 -29
View File
@@ -845,12 +845,14 @@ namespace QuantConnect.Algorithm
/// <param name="periods">The number of bars to request</param>
/// <param name="resolution">The resolution to request</param>
/// <param name="fillForward">True to fill forward missing data, false otherwise</param>
/// <param name="extendedMarketHours">True to include extended market hours data, false otherwise</param>
/// <returns>A python dictionary with pandas DataFrame containing the requested historical data</returns>
[DocumentationAttribute(HistoricalData)]
public PyObject History(PyObject tickers, int periods, Resolution? resolution = null, bool? fillForward = null)
public PyObject History(PyObject tickers, int periods, Resolution? resolution = null, bool? fillForward = null,
bool? extendedMarketHours = null)
{
var symbols = tickers.ConvertToSymbolEnumerable();
return GetDataFrame(History(symbols, periods, resolution, fillForward));
return GetDataFrame(History(symbols, periods, resolution, fillForward, extendedMarketHours));
}
/// <summary>
@@ -861,12 +863,14 @@ namespace QuantConnect.Algorithm
/// <param name="span">The span over which to retrieve recent historical data</param>
/// <param name="resolution">The resolution to request</param>
/// <param name="fillForward">True to fill forward missing data, false otherwise</param>
/// <param name="extendedMarketHours">True to include extended market hours data, false otherwise</param>
/// <returns>A python dictionary with pandas DataFrame containing the requested historical data</returns>
[DocumentationAttribute(HistoricalData)]
public PyObject History(PyObject tickers, TimeSpan span, Resolution? resolution = null, bool? fillForward = null)
public PyObject History(PyObject tickers, TimeSpan span, Resolution? resolution = null, bool? fillForward = null,
bool? extendedMarketHours = null)
{
var symbols = tickers.ConvertToSymbolEnumerable();
return GetDataFrame(History(symbols, span, resolution, fillForward));
return GetDataFrame(History(symbols, span, resolution, fillForward, extendedMarketHours));
}
/// <summary>
@@ -877,7 +881,7 @@ namespace QuantConnect.Algorithm
/// <param name="end">The end time in the algorithm's time zone</param>
/// <param name="resolution">The resolution to request</param>
/// <param name="fillForward">True to fill forward missing data, false otherwise</param>
/// <param name="extendedMarket">True to include extended market hours data, false otherwise</param>
/// <param name="extendedMarketHours">True to include extended market hours data, false otherwise</param>
/// <param name="dataMappingMode">The contract mapping mode to use for the security history request</param>
/// <param name="dataNormalizationMode">The price scaling mode to use for the securities history</param>
/// <param name="contractDepthOffset">The continuous contract desired offset from the current front month.
@@ -885,11 +889,11 @@ namespace QuantConnect.Algorithm
/// <returns>A python dictionary with a pandas DataFrame containing the requested historical data</returns>
[DocumentationAttribute(HistoricalData)]
public PyObject History(PyObject tickers, DateTime start, DateTime end, Resolution? resolution = null, bool? fillForward = null,
bool? extendedMarket = null, DataMappingMode? dataMappingMode = null, DataNormalizationMode? dataNormalizationMode = null,
bool? extendedMarketHours = null, DataMappingMode? dataMappingMode = null, DataNormalizationMode? dataNormalizationMode = null,
int? contractDepthOffset = null)
{
var symbols = tickers.ConvertToSymbolEnumerable();
return GetDataFrame(History(symbols, start, end, resolution, fillForward, extendedMarket, dataMappingMode,
return GetDataFrame(History(symbols, start, end, resolution, fillForward, extendedMarketHours, dataMappingMode,
dataNormalizationMode, contractDepthOffset));
}
@@ -917,7 +921,7 @@ namespace QuantConnect.Algorithm
/// <param name="end">The end time in the algorithm's time zone</param>
/// <param name="resolution">The resolution to request</param>
/// <param name="fillForward">True to fill forward missing data, false otherwise</param>
/// <param name="extendedMarket">True to include extended market hours data, false otherwise</param>
/// <param name="extendedMarketHours">True to include extended market hours data, false otherwise</param>
/// <param name="dataMappingMode">The contract mapping mode to use for the security history request</param>
/// <param name="dataNormalizationMode">The price scaling mode to use for the securities history</param>
/// <param name="contractDepthOffset">The continuous contract desired offset from the current front month.
@@ -925,12 +929,12 @@ namespace QuantConnect.Algorithm
/// <returns>pandas.DataFrame containing the requested historical data</returns>
[DocumentationAttribute(HistoricalData)]
public PyObject History(PyObject type, PyObject tickers, DateTime start, DateTime end, Resolution? resolution = null,
bool? fillForward = null, bool? extendedMarket = null, DataMappingMode? dataMappingMode = null,
bool? fillForward = null, bool? extendedMarketHours = null, DataMappingMode? dataMappingMode = null,
DataNormalizationMode? dataNormalizationMode = null, int? contractDepthOffset = null)
{
var symbols = tickers.ConvertToSymbolEnumerable();
var requestedType = type.CreateType();
var requests = CreateDateRangeHistoryRequests(symbols, requestedType, start, end, resolution, fillForward, extendedMarket,
var requests = CreateDateRangeHistoryRequests(symbols, requestedType, start, end, resolution, fillForward, extendedMarketHours,
dataMappingMode, dataNormalizationMode, contractDepthOffset);
return GetDataFrame(History(requests.Where(x => x != null)), requestedType);
}
@@ -945,18 +949,17 @@ namespace QuantConnect.Algorithm
/// <param name="periods">The number of bars to request</param>
/// <param name="resolution">The resolution to request</param>
/// <param name="fillForward">True to fill forward missing data, false otherwise</param>
/// <param name="extendedMarketHours">True to include extended market hours data, false otherwise</param>
/// <returns>pandas.DataFrame containing the requested historical data</returns>
[DocumentationAttribute(HistoricalData)]
public PyObject History(PyObject type, PyObject tickers, int periods, Resolution? resolution = null, bool? fillForward = null)
public PyObject History(PyObject type, PyObject tickers, int periods, Resolution? resolution = null, bool? fillForward = null,
bool? extendedMarketHours = null)
{
var symbols = tickers.ConvertToSymbolEnumerable();
if (symbols.Any(symbol => GetResolution(symbol, resolution) == Resolution.Tick))
{
throw new ArgumentException("History functions that accept a 'periods' parameter can not be used with Resolution.Tick");
}
CheckPeriodBasedHistoryRequestResolution(symbols, resolution);
var requestedType = type.CreateType();
var requests = CreateBarCountHistoryRequests(symbols, requestedType, periods, resolution, fillForward);
var requests = CreateBarCountHistoryRequests(symbols, requestedType, periods, resolution, fillForward, extendedMarketHours);
return GetDataFrame(History(requests.Where(x => x != null)), requestedType);
}
@@ -970,11 +973,13 @@ namespace QuantConnect.Algorithm
/// <param name="span">The span over which to retrieve recent historical data</param>
/// <param name="resolution">The resolution to request</param>
/// <param name="fillForward">True to fill forward missing data, false otherwise</param>
/// <param name="extendedMarketHours">True to include extended market hours data, false otherwise</param>
/// <returns>pandas.DataFrame containing the requested historical data</returns>
[DocumentationAttribute(HistoricalData)]
public PyObject History(PyObject type, PyObject tickers, TimeSpan span, Resolution? resolution = null, bool? fillForward = null)
public PyObject History(PyObject type, PyObject tickers, TimeSpan span, Resolution? resolution = null, bool? fillForward = null,
bool? extendedMarketHours = null)
{
return History(type, tickers, Time - span, Time, resolution, fillForward);
return History(type, tickers, Time - span, Time, resolution, fillForward, extendedMarketHours);
}
/// <summary>
@@ -986,12 +991,14 @@ namespace QuantConnect.Algorithm
/// <param name="end">The end time in the algorithm's time zone</param>
/// <param name="resolution">The resolution to request</param>
/// <param name="fillForward">True to fill forward missing data, false otherwise</param>
/// <param name="extendedMarketHours">True to include extended market hours data, false otherwise</param>
/// <returns>pandas.DataFrame containing the requested historical data</returns>
[DocumentationAttribute(HistoricalData)]
public PyObject History(PyObject type, Symbol symbol, DateTime start, DateTime end, Resolution? resolution = null, bool? fillForward = null)
public PyObject History(PyObject type, Symbol symbol, DateTime start, DateTime end, Resolution? resolution = null, bool? fillForward = null,
bool? extendedMarketHours = null)
{
var requestedType = type.CreateType();
var requests = CreateDateRangeHistoryRequests(new [] { symbol }, requestedType, start, end, resolution, fillForward);
var requests = CreateDateRangeHistoryRequests(new [] { symbol }, requestedType, start, end, resolution, fillForward, extendedMarketHours);
if (requests.IsNullOrEmpty())
{
throw new ArgumentException($"No history data could be fetched. " +
@@ -1011,19 +1018,19 @@ namespace QuantConnect.Algorithm
/// <param name="periods">The number of bars to request</param>
/// <param name="resolution">The resolution to request</param>
/// <param name="fillForward">True to fill forward missing data, false otherwise</param>
/// <param name="extendedMarketHours">True to include extended market hours data, false otherwise</param>
/// <returns>pandas.DataFrame containing the requested historical data</returns>
[DocumentationAttribute(HistoricalData)]
public PyObject History(PyObject type, Symbol symbol, int periods, Resolution? resolution = null, bool? fillForward = null)
public PyObject History(PyObject type, Symbol symbol, int periods, Resolution? resolution = null, bool? fillForward = null,
bool? extendedMarketHours = null)
{
resolution = GetResolution(symbol, resolution);
if (resolution == Resolution.Tick)
{
throw new ArgumentException("History functions that accept a 'periods' parameter can not be used with Resolution.Tick");
}
CheckPeriodBasedHistoryRequestResolution(new[] { symbol }, resolution);
var marketHours = GetMarketHours(symbol);
var start = _historyRequestFactory.GetStartTimeAlgoTz(symbol, periods, resolution.Value, marketHours.ExchangeHours, marketHours.DataTimeZone);
return History(type, symbol, start, Time, resolution, fillForward);
var start = _historyRequestFactory.GetStartTimeAlgoTz(symbol, periods, resolution.Value, marketHours.ExchangeHours,
marketHours.DataTimeZone, extendedMarketHours);
return History(type, symbol, start, Time, resolution, fillForward, extendedMarketHours);
}
/// <summary>
@@ -1035,11 +1042,13 @@ namespace QuantConnect.Algorithm
/// <param name="span">The span over which to retrieve recent historical data</param>
/// <param name="resolution">The resolution to request</param>
/// <param name="fillForward">True to fill forward missing data, false otherwise</param>
/// <param name="extendedMarketHours">True to include extended market hours data, false otherwise</param>
/// <returns>pandas.DataFrame containing the requested historical data</returns>
[DocumentationAttribute(HistoricalData)]
public PyObject History(PyObject type, Symbol symbol, TimeSpan span, Resolution? resolution = null, bool? fillForward = null)
public PyObject History(PyObject type, Symbol symbol, TimeSpan span, Resolution? resolution = null, bool? fillForward = null,
bool? extendedMarketHours = null)
{
return History(type, symbol, Time - span, Time, resolution, fillForward);
return History(type, symbol, Time - span, Time, resolution, fillForward, extendedMarketHours);
}
/// <summary>