Lean
$LEAN_TAG$
MappingEventProvider.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;
18
using
QuantConnect
.
Data
;
19
using
QuantConnect
.
Interfaces
;
20
using
QuantConnect
.
Data
.
Market
;
21
using
System.Collections.Generic;
22
using
QuantConnect
.
Data
.
Auxiliary
;
23
24
namespace
QuantConnect.Lean.Engine.DataFeeds.Enumerators
25
{
26
/// <summary>
27
/// Event provider who will emit <see cref="SymbolChangedEvent"/> events
28
/// </summary>
29
public
class
MappingEventProvider
:
ITradableDateEventProvider
30
{
31
private
IMapFileProvider
_mapFileProvider;
32
33
/// <summary>
34
/// The associated configuration
35
/// </summary>
36
protected
SubscriptionDataConfig
Config
{
get
;
private
set
; }
37
38
/// <summary>
39
/// The current instance being used
40
/// </summary>
41
protected
MapFile
MapFile
{
get
;
private
set
; }
42
43
/// <summary>
44
/// Initializes this instance
45
/// </summary>
46
/// <param name="config">The <see cref="SubscriptionDataConfig"/></param>
47
/// <param name="factorFileProvider">The factor file provider to use</param>
48
/// <param name="mapFileProvider">The <see cref="Data.Auxiliary.MapFile"/> provider to use</param>
49
/// <param name="startTime">Start date for the data request</param>
50
public
virtual
void
Initialize
(
51
SubscriptionDataConfig
config,
52
IFactorFileProvider
factorFileProvider,
53
IMapFileProvider
mapFileProvider,
54
DateTime startTime)
55
{
56
_mapFileProvider = mapFileProvider;
57
Config
= config;
58
InitializeMapFile
();
59
60
if
(
MapFile
.
HasData
(startTime.Date))
61
{
62
// initialize mapped symbol using request start date
63
Config
.
MappedSymbol
=
MapFile
.
GetMappedSymbol
(startTime.Date,
Config
.
MappedSymbol
,
Config
.
DataMappingMode
);
64
}
65
}
66
67
/// <summary>
68
/// Check for new mappings
69
/// </summary>
70
/// <param name="eventArgs">The new tradable day event arguments</param>
71
/// <returns>New mapping event if any</returns>
72
public
virtual
IEnumerable<BaseData>
GetEvents
(
NewTradableDateEventArgs
eventArgs)
73
{
74
if
(
Config
.
Symbol
== eventArgs.
Symbol
75
&&
MapFile
.
HasData
(eventArgs.
Date
))
76
{
77
var old =
Config
.
MappedSymbol
;
78
var newSymbol =
MapFile
.
GetMappedSymbol
(eventArgs.
Date
,
Config
.
MappedSymbol
,
Config
.
DataMappingMode
);
79
Config
.
MappedSymbol
= newSymbol;
80
81
// check to see if the symbol was remapped
82
if
(old !=
Config
.
MappedSymbol
)
83
{
84
var changed =
new
SymbolChangedEvent
(
85
Config
.
Symbol
,
86
eventArgs.
Date
,
87
old,
88
Config
.
MappedSymbol
);
89
yield
return
changed;
90
}
91
}
92
}
93
94
/// <summary>
95
/// Initializes the map file to use
96
/// </summary>
97
protected
void
InitializeMapFile
()
98
{
99
MapFile
= _mapFileProvider.ResolveMapFile(
Config
);
100
}
101
}
102
}
Engine
DataFeeds
Enumerators
MappingEventProvider.cs
Generated by
1.8.17