Files
quantconnect--lean/Common/Data/BaseDataRequest.cs
T
Colton Sellers 43a540cbb1 OpenInterest Bug Fixes (#5207)
* Filter values that are before subscription start time; also adjust starttime for OpenInterest

* Use data EndTime for comparison

* Allow Auxiliary data through

* Fix OpenInterest DataReader Logic

* Add regression

* Address review

* Ignore open interest for time slice

- TimeSliceFactory will directly ignore open interest for determining if
  the slice has data or not. Open interest will still be available
  through the Tick collection. Reverting some of the previous commits
  changes since they are no longer required.
- HistoryRequests and SubscriptionRequest will use AlwaysOpen exchange
  for open interest requests. Adding unit test reproducing issue
- Adding `BaseDataRequest` to avoid duplication logic.

* Make OpenInterest an internal feed and ignored by default in history

- Adding unit tests

* Revert SubscriptionFilterEnumerator Start time addition

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-02-18 19:04:29 -03:00

82 lines
3.1 KiB
C#

/*
* 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;
namespace QuantConnect.Data
{
/// <summary>
/// Abstract sharing logic for data requests
/// </summary>
public abstract class BaseDataRequest
{
private readonly Lazy<DateTime> _localStartTime;
private readonly Lazy<DateTime> _localEndTime;
/// <summary>
/// Gets the beginning of the requested time interval in UTC
/// </summary>
public DateTime StartTimeUtc { get; protected set; }
/// <summary>
/// Gets the end of the requested time interval in UTC
/// </summary>
public DateTime EndTimeUtc { get; protected set; }
/// <summary>
/// Gets the <see cref="StartTimeUtc"/> in the security's exchange time zone
/// </summary>
public DateTime StartTimeLocal => _localStartTime.Value;
/// <summary>
/// Gets the <see cref="EndTimeUtc"/> in the security's exchange time zone
/// </summary>
public DateTime EndTimeLocal => _localEndTime.Value;
/// <summary>
/// Gets the exchange hours used for processing fill forward requests
/// </summary>
public SecurityExchangeHours ExchangeHours { get; }
/// <summary>
/// Initializes the base data request
/// </summary>
/// <param name="startTimeUtc">The start time for this request,</param>
/// <param name="endTimeUtc">The start time for this request</param>
/// <param name="exchangeHours">The exchange hours for this request</param>
/// <param name="tickType">The tick type of this request</param>
protected BaseDataRequest(DateTime startTimeUtc,
DateTime endTimeUtc,
SecurityExchangeHours exchangeHours,
TickType tickType)
{
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<DateTime>(() => StartTimeUtc.ConvertFromUtc(ExchangeHours.TimeZone));
_localEndTime = new Lazy<DateTime>(() => EndTimeUtc.ConvertFromUtc(ExchangeHours.TimeZone));
}
}
}