Lean
$LEAN_TAG$
DataFeedPacket.cs
1
/*
2
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8
*
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
14
*
15
*/
16
17
using
System.Collections.Generic;
18
using
QuantConnect
.
Data
;
19
using
QuantConnect
.
Interfaces
;
20
using
QuantConnect
.
Util
;
21
22
namespace
QuantConnect.Lean.Engine.DataFeeds
23
{
24
/// <summary>
25
/// Defines a container type to hold data produced by a data feed subscription
26
/// </summary>
27
public
class
DataFeedPacket
28
{
29
private
static
readonly
IReadOnlyRef<bool>
_false =
Ref
.CreateReadOnly(() =>
false
);
30
private
readonly
IReadOnlyRef<bool>
_isRemoved;
31
32
/// <summary>
33
/// The security
34
/// </summary>
35
public
ISecurityPrice
Security
36
{
37
get
;
private
set
;
38
}
39
40
/// <summary>
41
/// The subscription configuration that produced this data
42
/// </summary>
43
public
SubscriptionDataConfig
Configuration
44
{
45
get
;
private
set
;
46
}
47
48
/// <summary>
49
/// Gets the number of data points held within this packet
50
/// </summary>
51
public
int
Count
=>
Data
.Count;
52
53
/// <summary>
54
/// The data for the security
55
/// </summary>
56
public
List<BaseData>
Data
{
get
; }
57
58
/// <summary>
59
/// Gets whether or not this packet should be filtered out due to the subscription being removed
60
/// </summary>
61
public
bool
IsSubscriptionRemoved
=> _isRemoved.Value;
62
63
/// <summary>
64
/// Initializes a new instance of the <see cref="DataFeedPacket"/> class
65
/// </summary>
66
/// <param name="security">The security whose data is held in this packet</param>
67
/// <param name="configuration">The subscription configuration that produced this data</param>
68
/// <param name="isSubscriptionRemoved">Reference to whether or not the subscription has since been removed, defaults to false</param>
69
public
DataFeedPacket
(
ISecurityPrice
security,
SubscriptionDataConfig
configuration,
IReadOnlyRef<bool>
isSubscriptionRemoved =
null
)
70
: this(security,
71
configuration,
72
new List<
BaseData
>(4),
// performance: by default the list has 0 capacity, so lets initialize it with at least 4 (which is the default)
73
isSubscriptionRemoved)
74
{
75
}
76
77
/// <summary>
78
/// Initializes a new instance of the <see cref="DataFeedPacket"/> class
79
/// </summary>
80
/// <param name="security">The security whose data is held in this packet</param>
81
/// <param name="configuration">The subscription configuration that produced this data</param>
82
/// <param name="data">The data to add to this packet. The list reference is reused
83
/// internally and NOT copied.</param>
84
/// <param name="isSubscriptionRemoved">Reference to whether or not the subscription has since been removed, defaults to false</param>
85
public
DataFeedPacket
(
ISecurityPrice
security,
SubscriptionDataConfig
configuration, List<BaseData> data,
IReadOnlyRef<bool>
isSubscriptionRemoved =
null
)
86
{
87
Security
= security;
88
Configuration
= configuration;
89
Data
= data;
90
_isRemoved = isSubscriptionRemoved ?? _false;
91
}
92
93
/// <summary>
94
/// Adds the specified data to this packet
95
/// </summary>
96
/// <param name="data">The data to be added to this packet</param>
97
public
void
Add
(
BaseData
data)
98
{
99
Data
.Add(data);
100
}
101
}
102
}
Engine
DataFeeds
DataFeedPacket.cs
Generated by
1.8.17