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