/*
* 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 QuantConnect.Securities;
using System.Collections.Generic;
namespace QuantConnect.Data
{
///
/// Abstract sharing logic for data requests
///
public abstract class BaseDataRequest
{
private readonly Lazy _localStartTime;
private readonly Lazy _localEndTime;
///
/// Gets the beginning of the requested time interval in UTC
///
public DateTime StartTimeUtc { get; protected set; }
///
/// Gets the end of the requested time interval in UTC
///
public DateTime EndTimeUtc { get; protected set; }
///
/// Gets the in the security's exchange time zone
///
public DateTime StartTimeLocal => _localStartTime.Value;
///
/// Gets the in the security's exchange time zone
///
public DateTime EndTimeLocal => _localEndTime.Value;
///
/// Gets the exchange hours used for processing fill forward requests
///
public SecurityExchangeHours ExchangeHours { get; }
///
/// Gets the tradable days specified by this request, in the security's data time zone
///
public abstract IEnumerable TradableDaysInDataTimeZone { get; }
///
/// Gets true if this is a custom data request, false for normal QC data
///
public bool IsCustomData { get; }
///
/// The data type of this request
///
public Type DataType { get; set; }
///
/// Initializes the base data request
///
/// The start time for this request,
/// The start time for this request
/// The exchange hours for this request
/// The tick type of this request
/// True if this subscription is for custom data
/// The data type of the output data
protected BaseDataRequest(DateTime startTimeUtc,
DateTime endTimeUtc,
SecurityExchangeHours exchangeHours,
TickType tickType,
bool isCustomData,
Type dataType)
{
DataType = dataType;
IsCustomData = isCustomData;
StartTimeUtc = startTimeUtc;
EndTimeUtc = endTimeUtc;
ExchangeHours = exchangeHours;
// open interest data comes in once a day before market open,
// make the subscription start from midnight and use always open exchange
if (tickType == TickType.OpenInterest)
{
ExchangeHours = SecurityExchangeHours.AlwaysOpen(ExchangeHours.TimeZone);
}
_localStartTime = new Lazy(() => StartTimeUtc.ConvertFromUtc(ExchangeHours.TimeZone));
_localEndTime = new Lazy(() => EndTimeUtc.ConvertFromUtc(ExchangeHours.TimeZone));
IsCustomData = isCustomData;
}
}
}