Lean  $LEAN_TAG$
IndexSymbol.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 using System;
17 using System.Collections.Generic;
18 
20 {
21  /// <summary>
22  /// Helper methods for Index Symbols
23  /// </summary>
24  public static class IndexSymbol
25  {
26  private static readonly Dictionary<string, string> _indexExchange = new(StringComparer.InvariantCultureIgnoreCase)
27  {
28  { "SPX", Market.CBOE },
29  { "NDX", "NASDAQ" },
30  { "VIX", Market.CBOE },
31  { "SPXW", Market.CBOE },
32  { "NQX", "NASDAQ" },
33  { "VIXW", Market.CBOE },
34  { "RUT", "RUSSELL" }
35  };
36 
37  private static readonly Dictionary<string, string> _indexMarket = new(StringComparer.InvariantCultureIgnoreCase)
38  {
39  { "HSI", Market.HKFE },
40  { "N225", Market.OSE },
41  { "SX5E", Market.EUREX }
42  };
43 
44  /// <summary>
45  /// Gets the actual exchange the index lives on
46  /// </summary>
47  /// <remarks>Useful for live trading</remarks>
48  /// <returns>The exchange of the index</returns>
49  public static string GetIndexExchange(Symbol symbol)
50  {
51  return _indexExchange.TryGetValue(symbol.Value, out var market)
52  ? market
53  : symbol.ID.Market;
54  }
55 
56  /// <summary>
57  /// Gets the lean market for this index ticker
58  /// </summary>
59  /// <returns>The market of the index</returns>
60  public static bool TryGetIndexMarket(string ticker, out string market)
61  {
62  return _indexMarket.TryGetValue(ticker, out market);
63  }
64  }
65 }