/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using NodaTime;
using QuantConnect.Securities;
using System.Collections.Generic;
using QuantConnect.Util;
namespace QuantConnect.Data
{
///
/// Represents a request for historical data
///
public class HistoryRequest : BaseDataRequest
{
private Resolution? _fillForwardResolution;
private bool _includeExtendedMarketHours;
///
/// Gets the symbol to request data for
///
public Symbol Symbol { get; set; }
///
/// Gets the requested data resolution
///
public Resolution Resolution { get; set; }
///
/// Gets the requested fill forward resolution, set to null for no fill forward behavior.
/// Will always return null when Resolution is set to Tick.
///
public Resolution? FillForwardResolution
{
get
{
return Resolution == Resolution.Tick ? null : _fillForwardResolution;
}
set
{
_fillForwardResolution = value;
}
}
///
/// Gets whether or not to include extended market hours data, set to false for only normal market hours
///
public bool IncludeExtendedMarketHours
{
get
{
return _includeExtendedMarketHours;
}
set
{
_includeExtendedMarketHours = value && LeanData.SupportsExtendedMarketHours(DataType);
}
}
///
/// Gets the time zone of the time stamps on the raw input data
///
public DateTimeZone DataTimeZone { get; set; }
///
/// TickType of the history request
///
public TickType TickType { get; set; }
///
/// Gets the normalization mode used for this subscription
///
public DataNormalizationMode DataNormalizationMode { get; set; }
///
/// Gets the data mapping mode used for this subscription
///
public DataMappingMode DataMappingMode { get; set; }
///
/// The continuous contract desired offset from the current front month.
/// For example, 0 (default) will use the front month, 1 will use the back month contract
///
public uint ContractDepthOffset { get; set; }
///
/// Gets the tradable days specified by this request, in the security's data time zone
///
public override IEnumerable TradableDaysInDataTimeZone => Time.EachTradeableDayInTimeZone(ExchangeHours,
StartTimeLocal,
EndTimeLocal,
DataTimeZone,
IncludeExtendedMarketHours);
///
/// Initializes a new instance of the class from the specified parameters
///
/// The start time for this request,
/// The end time for this request
/// The data type of the output data
/// The symbol to request data for
/// The requested data resolution
/// The exchange hours used in fill forward processing
/// The time zone of the data
/// The requested fill forward resolution for this request
/// True to include data from pre/post market hours
/// True for custom user data, false for normal QC data
/// Specifies normalization mode used for this subscription
/// The tick type used to created the for the retrieval of history data
/// The contract mapping mode to use for the security
/// The continuous contract desired offset from the current front month.
/// For example, 0 will use the front month, 1 will use the back month contract
public HistoryRequest(DateTime startTimeUtc,
DateTime endTimeUtc,
Type dataType,
Symbol symbol,
Resolution resolution,
SecurityExchangeHours exchangeHours,
DateTimeZone dataTimeZone,
Resolution? fillForwardResolution,
bool includeExtendedMarketHours,
bool isCustomData,
DataNormalizationMode dataNormalizationMode,
TickType tickType,
DataMappingMode dataMappingMode = DataMappingMode.OpenInterest,
uint contractDepthOffset = 0)
: base(startTimeUtc, endTimeUtc, exchangeHours, tickType, isCustomData, dataType)
{
Symbol = symbol;
DataTimeZone = dataTimeZone;
Resolution = resolution;
FillForwardResolution = fillForwardResolution;
IncludeExtendedMarketHours = includeExtendedMarketHours;
DataNormalizationMode = dataNormalizationMode;
TickType = tickType;
DataMappingMode = dataMappingMode;
ContractDepthOffset = contractDepthOffset;
}
///
/// Initializes a new instance of the class from the specified config and exchange hours
///
/// The subscription data config used to initialize this request
/// The exchange hours used for fill forward processing
/// The start time for this request,
/// The end time for this request
public HistoryRequest(SubscriptionDataConfig config, SecurityExchangeHours hours, DateTime startTimeUtc, DateTime endTimeUtc)
: this(startTimeUtc, endTimeUtc, config.Type, config.Symbol, config.Resolution,
hours, config.DataTimeZone, config.FillDataForward ? config.Resolution : (Resolution?)null,
config.ExtendedMarketHours, config.IsCustomData, config.DataNormalizationMode, config.TickType, config.DataMappingMode, config.ContractDepthOffset)
{
}
///
/// Initializes a new instance of the class with new Symbol, StartTimeUtc, EndTimeUtc
///
/// Represents a request for historical data
/// The start time for this request
/// The end time for this request
public HistoryRequest(HistoryRequest request, Symbol newSymbol, DateTime newStartTimeUtc, DateTime newEndTimeUtc)
: this (newStartTimeUtc, newEndTimeUtc, request.DataType, newSymbol, request.Resolution, request.ExchangeHours, request.DataTimeZone, request.FillForwardResolution,
request.IncludeExtendedMarketHours, request.IsCustomData, request.DataNormalizationMode, request.TickType, request.DataMappingMode, request.ContractDepthOffset)
{ }
}
}