Lean  $LEAN_TAG$
SecurityIdentifierContext.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 
17 using System;
18 using System.Linq;
19 
21 {
22  /// <summary>
23  /// Auxiliary class for handling map files and SID.
24  /// </summary>
25  internal class SecurityIdentifierContext
26  {
27  /// <summary>
28  /// Initializes a new instance of the <see cref="SecurityIdentifierContext"/> class.
29  /// </summary>
30  /// <param name="mapFile">The map file.</param>
31  /// <param name="market">The market.</param>
32  public SecurityIdentifierContext(MapFile mapFile, string market)
33  {
34  MapFile = mapFile;
35  SID = SecurityIdentifier.GenerateEquity(MapFile.FirstDate, MapFile.FirstTicker, market);
36  MapFileRows = MapFile.Select(mfr => new Tuple<DateTime, string>(mfr.Date, mfr.MappedSymbol)).ToArray();
37  Tickers = MapFile.Select(mfr => mfr.MappedSymbol.ToLowerInvariant()).Distinct().ToArray();
38  LastTicker = MapFile.Last().MappedSymbol.ToLowerInvariant();
39  }
40 
41  /// <summary>
42  /// Gets the sid.
43  /// </summary>
44  /// <value>
45  /// The sid.
46  /// </value>
47  public SecurityIdentifier SID { get; }
48 
49  /// <summary>
50  /// Gets the map file.
51  /// </summary>
52  /// <value>
53  /// The map file.
54  /// </value>
55  public MapFile MapFile { get; }
56 
57  /// <summary>
58  /// Gets the map file rows.
59  /// </summary>
60  /// <value>
61  /// The map file rows.
62  /// </value>
63  public Tuple<DateTime, string>[] MapFileRows { get; }
64 
65  /// <summary>
66  /// Gets the tickers.
67  /// </summary>
68  /// <value>
69  /// The tickers.
70  /// </value>
71  public string[] Tickers { get; }
72 
73  /// <summary>
74  /// Gets the last ticker.
75  /// </summary>
76  /// <value>
77  /// The last ticker.
78  /// </value>
79  public string LastTicker { get; }
80  }
81 }