Lean  $LEAN_TAG$
Exchange.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.Linq;
17 using Newtonsoft.Json;
18 using System.Collections.Generic;
19 
20 namespace QuantConnect
21 {
22  /// <summary>
23  /// Lean exchange definition
24  /// </summary>
25  public class Exchange
26  {
27  /// <summary>
28  /// Unknown exchange value
29  /// </summary>
30  public static Exchange UNKNOWN { get; } = new (string.Empty, string.Empty, "UNKNOWN", string.Empty);
31 
32  /// <summary>
33  /// The Members Exchange (MEMX) is an independently owned, technology-driven stock exchange
34  /// </summary>
35  public static Exchange MEMX { get; }
36  = new("MEMX", "MM", "The Long-Term Stock Exchange", QuantConnect.Market.USA, SecurityType.Equity);
37 
38  /// <summary>
39  /// Long-Term Stock Exchange
40  /// </summary>
41  public static Exchange LTSE { get; }
42  = new("LTSE", "L", "The Long-Term Stock Exchange", QuantConnect.Market.USA, SecurityType.Equity);
43 
44  /// <summary>
45  /// National Association of Securities Dealers Automated Quotation.
46  /// </summary>
47  public static Exchange NASDAQ { get; }
48  = new("NASDAQ", "Q", "National Association of Securities Dealers Automated Quotation", QuantConnect.Market.USA, SecurityType.Equity);
49 
50  /// <summary>
51  /// Bats Global Markets, Better Alternative Trading System
52  /// </summary>
53  public static Exchange BATS { get; }
54  = new("BATS", "Z", "Bats Global Markets, Better Alternative Trading System", QuantConnect.Market.USA, SecurityType.Equity);
55 
56  /// <summary>
57  /// New York Stock Archipelago Exchange
58  /// </summary>
59  public static Exchange ARCA { get; }
60  = new("ARCA", "P", "New York Stock Archipelago Exchange", QuantConnect.Market.USA, SecurityType.Equity);
61 
62  /// <summary>
63  /// New York Stock Exchange
64  /// </summary>
65  public static Exchange NYSE { get; }
66  = new("NYSE", "N", "New York Stock Exchange", QuantConnect.Market.USA, SecurityType.Equity);
67 
68  /// <summary>
69  /// Smart Exchange
70  /// </summary>
71  /// <remarks>Brokerage will route to smart exchange</remarks>
72  public static Exchange SMART { get; }
73  = new("SMART", "SMART", "SMART Exchange", QuantConnect.Market.USA, SecurityType.Equity);
74 
75  /// <summary>
76  /// Over The Counter Exchange
77  /// </summary>
78  public static Exchange OTCX { get; }
79  = new("OTCX", "OTCX", "Over the Counter Exchange", QuantConnect.Market.USA, SecurityType.Equity);
80 
81  /// <summary>
82  /// The Investors Exchange
83  /// </summary>
84  public static Exchange IEX { get; }
85  = new("IEX", "IEX", "Investors Exchange", QuantConnect.Market.USA, SecurityType.Equity);
86 
87  /// <summary>
88  /// National Stock Exchange
89  /// </summary>
90  /// <remarks>Is now known as the NYSE National</remarks>
91  public static Exchange NSX { get; }
92  = new("NSE", "C", "National Stock Exchange", QuantConnect.Market.USA, SecurityType.Equity);
93 
94  /// <summary>
95  /// The Financial Industry Regulatory Authority
96  /// </summary>
97  public static Exchange FINRA { get; }
98  = new("FINRA", "D", "The Financial Industry Regulatory Authority", QuantConnect.Market.USA, SecurityType.Equity);
99 
100  /// <summary>
101  /// Nasdaq International Securities Exchange
102  /// </summary>
103  public static Exchange ISE { get; }
104  = new("ISE", "I", "Nasdaq International Securities Exchange", QuantConnect.Market.USA, SecurityType.Equity);
105 
106  /// <summary>
107  /// Chicago Stock Exchange
108  /// </summary>
109  public static Exchange CSE { get; }
110  = new("CSE", "M", "Chicago Stock Exchange", QuantConnect.Market.USA, SecurityType.Equity);
111 
112  /// <summary>
113  /// The Chicago Board Options Exchange
114  /// </summary>
115  public static Exchange CBOE { get; }
116  = new("CBOE", "W", "The Chicago Board Options Exchange", QuantConnect.Market.USA, SecurityType.Equity);
117 
118  /// <summary>
119  /// The American Options Exchange
120  /// </summary>
121  public static Exchange NASDAQ_BX { get; }
122  = new("NASDAQ_BX", "B", "National Association of Securities Dealers Automated Quotation BX", QuantConnect.Market.USA, SecurityType.Equity);
123 
124  /// <summary>
125  /// The Securities Industry Automation Corporation
126  /// </summary>
127  public static Exchange SIAC { get; }
128  = new("SIAC", "SIAC", "The Securities Industry Automation Corporation", QuantConnect.Market.USA, SecurityType.Equity);
129 
130  /// <summary>
131  /// CBOE EDGA U.S. equities Exchange
132  /// </summary>
133  public static Exchange EDGA { get; }
134  = new("EDGA", "J", "CBOE EDGA U.S. equities Exchange", QuantConnect.Market.USA, SecurityType.Equity);
135 
136  /// <summary>
137  /// CBOE EDGX U.S. equities Exchange
138  /// </summary>
139  public static Exchange EDGX { get; }
140  = new("EDGX", "K", "CBOE EDGX U.S. equities Exchange", QuantConnect.Market.USA, SecurityType.Equity);
141 
142  /// <summary>
143  /// National Association of Securities Dealers Automated Quotation PSX
144  /// </summary>
145  public static Exchange NASDAQ_PSX { get; }
146  = new("NASDAQ_PSX", "X", "National Association of Securities Dealers Automated Quotation PSX", QuantConnect.Market.USA, SecurityType.Equity);
147 
148  /// <summary>
149  /// National Association of Securities Dealers Automated Quotation PSX
150  /// </summary>
151  public static Exchange BATS_Y { get; }
152  = new("BATS_Y", "Y", "Bats Global Markets, Better Alternative Trading System", QuantConnect.Market.USA, SecurityType.Equity);
153 
154  /// <summary>
155  /// The Boston Stock Exchange
156  /// </summary>
157  /// <remarks>Now NASDAQ OMX BX</remarks>
158  public static Exchange BOSTON { get; }
159  = new("BOSTON", "BB", "The Boston Stock Exchange", QuantConnect.Market.USA, SecurityType.Equity);
160 
161  /// <summary>
162  /// The American Stock Exchange
163  /// </summary>
164  /// <remarks>Now NYSE MKT</remarks>
165  public static Exchange AMEX { get; }
166  = new("AMEX", "A", "The American Stock Exchange", QuantConnect.Market.USA, SecurityType.Equity);
167 
168  /// <summary>
169  /// Bombay Stock Exchange
170  /// </summary>
171  public static Exchange BSE { get; }
172  = new("BSE", "BSE", "Bombay Stock Exchange", QuantConnect.Market.India, SecurityType.Equity);
173 
174  /// <summary>
175  /// National Stock Exchange of India
176  /// </summary>
177  public static Exchange NSE { get; }
178  = new("NSE", "NSE", "National Stock Exchange of India", QuantConnect.Market.India, SecurityType.Equity);
179 
180  /// <summary>
181  /// The American Options Exchange
182  /// </summary>
183  /// <remarks>Now NYSE Amex Options</remarks>
184  public static Exchange AMEX_Options { get; }
185  = new("AMEX", "A", "The American Options Exchange", QuantConnect.Market.USA, SecurityType.Option);
186 
187  /// <summary>
188  /// The Options Price Reporting Authority
189  /// </summary>
190  public static Exchange OPRA { get; }
191  = new("OPRA", "O", "The Options Price Reporting Authority", QuantConnect.Market.USA, SecurityType.Option);
192 
193  /// <summary>
194  /// CBOE Options Exchange
195  /// </summary>
196  public static Exchange C2 { get; }
197  = new("C2", "W", "CBOE Options Exchange", QuantConnect.Market.USA, SecurityType.Option);
198 
199  /// <summary>
200  /// Miami International Securities Options Exchange
201  /// </summary>
202  public static Exchange MIAX { get; }
203  = new("MIAX", "M", "Miami International Securities Options Exchange", QuantConnect.Market.USA, SecurityType.Option);
204 
205  /// <summary>
206  /// MIAX Pearl Option and Equity exchange. Offers a Price-Time allocation and Maker-Taker fee structure
207  /// </summary>
208  public static Exchange MIAX_PEARL { get; }
209  = new("MIAX_PEARL", "MP", "MIAX PEARL", QuantConnect.Market.USA, SecurityType.Option, SecurityType.Equity);
210 
211  /// <summary>
212  /// Serves as a counterpart to MIAX Options and MIAX Pearl by providing Pro-Rata allocation like MIAX Options and a Maker-Taker fee structure like MIAX Pearl
213  /// </summary>
214  public static Exchange MIAX_EMERALD { get; }
215  = new("MIAX_EMERALD", "ME", "MIAX EMERALD", QuantConnect.Market.USA, SecurityType.Option);
216 
217  /// <summary>
218  /// International Securities Options Exchange GEMINI
219  /// </summary>
220  public static Exchange ISE_GEMINI { get; }
221  = new("ISE_GEMINI", "H", "International Securities Options Exchange GEMINI", QuantConnect.Market.USA, SecurityType.Option);
222 
223  /// <summary>
224  /// International Securities Options Exchange MERCURY
225  /// </summary>
226  public static Exchange ISE_MERCURY { get; }
227  = new("ISE_MERCURY", "J", "International Securities Options Exchange MERCURY", QuantConnect.Market.USA, SecurityType.Option);
228 
229  /// <summary>
230  /// The Chicago Mercantile Exchange (CME), is an organized exchange for the trading of futures and options.
231  /// </summary>
232  public static Exchange CME { get; }
233  = new("CME", "CME", "Futures and Options Chicago Mercantile Exchange", QuantConnect.Market.CME, SecurityType.Future, SecurityType.FutureOption);
234 
235  /// <summary>
236  /// The Chicago Board of Trade (CBOT) is a commodity exchange
237  /// </summary>
238  public static Exchange CBOT { get; }
239  = new("CBOT", "CBOT", " Chicago Board of Trade Commodity Exchange", QuantConnect.Market.CBOT, SecurityType.Future, SecurityType.FutureOption);
240 
241  /// <summary>
242  /// Cboe Futures Exchange
243  /// </summary>
244  public static Exchange CFE { get; }
245  = new("CFE", "CFE", "CFE Futures Exchange", QuantConnect.Market.CFE, SecurityType.Future);
246 
247  /// <summary>
248  /// COMEX Commodity Exchange
249  /// </summary>
250  public static Exchange COMEX { get; }
251  = new("COMEX", "COMEX", "COMEX Futures Exchange", QuantConnect.Market.COMEX, SecurityType.Future);
252 
253  /// <summary>
254  /// The Intercontinental Exchange
255  /// </summary>
256  public static Exchange ICE { get; }
257  = new("ICE", "ICE", "The Intercontinental Exchange", QuantConnect.Market.ICE, SecurityType.Future);
258 
259  /// <summary>
260  /// New York Mercantile Exchange
261  /// </summary>
262  public static Exchange NYMEX { get; }
263  = new("NYMEX", "NYMEX", "New York Mercantile Exchange", QuantConnect.Market.NYMEX, SecurityType.Future, SecurityType.FutureOption);
264 
265  /// <summary>
266  /// London International Financial Futures and Options Exchange
267  /// </summary>
268  public static Exchange NYSELIFFE { get; }
269  = new("NYSELIFFE", "NYSELIFFE", "London International Financial Futures and Options Exchange", QuantConnect.Market.NYSELIFFE, SecurityType.Future, SecurityType.FutureOption);
270 
271  /// <summary>
272  /// Exchange description
273  /// </summary>
274  [JsonIgnore]
275  public string Description { get; }
276 
277  /// <summary>
278  /// The exchange short code
279  /// </summary>
280  public string Code { get; init; }
281 
282  /// <summary>
283  /// The exchange name
284  /// </summary>
285  public string Name { get; init; }
286 
287  /// <summary>
288  /// The associated lean market <see cref="Market"/>
289  /// </summary>
290  public string Market { get; init; }
291 
292  /// <summary>
293  /// Security types traded in this exchange
294  /// </summary>
295  [JsonProperty(ReferenceLoopHandling = ReferenceLoopHandling.Ignore)]
296  public IReadOnlyList<SecurityType> SecurityTypes { get; init; } = new List<SecurityType>();
297 
298  /// <summary>
299  /// Creates a new empty exchange instance
300  /// </summary>
301  /// <remarks>For json round trip serialization</remarks>
302  private Exchange()
303  {
304  }
305 
306  /// <summary>
307  /// Creates a new exchange instance
308  /// </summary>
309  private Exchange(string name, string code, string description, string market, params SecurityType[] securityTypes)
310  {
311  Name = name;
312  Market = market;
313  Description = description;
314  SecurityTypes = securityTypes?.ToList() ?? new List<SecurityType>();
315  Code = string.IsNullOrEmpty(code) ? name : code;
316  }
317 
318  /// <summary>
319  /// Returns a string that represents the current object.
320  /// </summary>
321  public override string ToString()
322  {
323  return Name;
324  }
325 
326  /// <summary>
327  /// Returns the string representation of this exchange
328  /// </summary>
329  public static implicit operator string(Exchange exchange)
330  {
331  return ReferenceEquals(exchange, null) ? string.Empty : exchange.ToString();
332  }
333 
334  /// <summary>
335  /// Indicates whether the current object is equal to another object
336  /// </summary>
337  public override bool Equals(object? obj)
338  {
339  if (ReferenceEquals(this, obj))
340  {
341  return true;
342  }
343  var exchange = obj as Exchange;
344  if (ReferenceEquals(exchange, null) || ReferenceEquals(exchange, UNKNOWN))
345  {
346  // other is null or UNKNOWN (equivalents)
347  // so we need to know how We compare with UNKNOWN
348  return ReferenceEquals(this, UNKNOWN);
349  }
350 
351  return Code == exchange.Code
352  && Market == exchange.Market
353  && SecurityTypes.All(exchange.SecurityTypes.Contains)
354  && SecurityTypes.Count == exchange.SecurityTypes.Count;
355  }
356 
357  /// <summary>
358  /// Equals operator
359  /// </summary>
360  /// <param name="left">The left operand</param>
361  /// <param name="right">The right operand</param>
362  /// <returns>True if both symbols are equal, otherwise false</returns>
363  public static bool operator ==(Exchange left, Exchange right)
364  {
365  if (ReferenceEquals(left, right))
366  {
367  return true;
368  }
369  if (ReferenceEquals(left, null) || left.Equals(UNKNOWN))
370  {
371  return ReferenceEquals(right, null) || right.Equals(UNKNOWN);
372  }
373  return left.Equals(right);
374  }
375 
376  /// <summary>
377  /// Not equals operator
378  /// </summary>
379  /// <param name="left">The left operand</param>
380  /// <param name="right">The right operand</param>
381  /// <returns>True if both symbols are not equal, otherwise false</returns>
382  public static bool operator !=(Exchange left, Exchange right)
383  {
384  return !(left == right);
385  }
386 
387  /// <summary>
388  /// Serves as a hash function for a particular type.
389  /// </summary>
390  public override int GetHashCode()
391  {
392  unchecked
393  {
394  var hashCode = Code.GetHashCode();
395  hashCode = (hashCode * 397) ^ Market.GetHashCode();
396  for (var i = 0; i < SecurityTypes.Count; i++)
397  {
398  hashCode = (hashCode * 397) ^ SecurityTypes[i].GetHashCode();
399  }
400  return hashCode;
401  }
402  }
403  }
404 }