/*
* 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.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using QuantConnect.Util;
namespace QuantConnect.Lean.Engine.DataFeeds
{
///
/// Defines a container type to hold data produced by a data feed subscription
///
public class DataFeedPacket
{
private static readonly IReadOnlyRef _false = Ref.CreateReadOnly(() => false);
private readonly IReadOnlyRef _isRemoved;
///
/// The security
///
public ISecurityPrice Security
{
get; private set;
}
///
/// The subscription configuration that produced this data
///
public SubscriptionDataConfig Configuration
{
get; private set;
}
///
/// Gets the number of data points held within this packet
///
public int Count => Data.Count;
///
/// The data for the security
///
public List Data { get; }
///
/// Gets whether or not this packet should be filtered out due to the subscription being removed
///
public bool IsSubscriptionRemoved => _isRemoved.Value;
///
/// Initializes a new instance of the class
///
/// The security whose data is held in this packet
/// The subscription configuration that produced this data
/// Reference to whether or not the subscription has since been removed, defaults to false
public DataFeedPacket(ISecurityPrice security, SubscriptionDataConfig configuration, IReadOnlyRef isSubscriptionRemoved = null)
: this(security,
configuration,
new List(4), // performance: by default the list has 0 capacity, so lets initialize it with at least 4 (which is the default)
isSubscriptionRemoved)
{
}
///
/// Initializes a new instance of the class
///
/// The security whose data is held in this packet
/// The subscription configuration that produced this data
/// The data to add to this packet. The list reference is reused
/// internally and NOT copied.
/// Reference to whether or not the subscription has since been removed, defaults to false
public DataFeedPacket(ISecurityPrice security, SubscriptionDataConfig configuration, List data, IReadOnlyRef isSubscriptionRemoved = null)
{
Security = security;
Configuration = configuration;
Data = data;
_isRemoved = isSubscriptionRemoved ?? _false;
}
///
/// Adds the specified data to this packet
///
/// The data to be added to this packet
public void Add(BaseData data)
{
Data.Add(data);
}
}
}