/* * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System.Linq; using Newtonsoft.Json; using System.Collections.Generic; namespace QuantConnect { /// /// Lean exchange definition /// public class Exchange { /// /// Unknown exchange value /// public static Exchange UNKNOWN { get; } = new(string.Empty, string.Empty, "UNKNOWN", string.Empty); /// /// The Members Exchange (MEMX) is an independently owned, technology-driven stock exchange /// public static Exchange MEMX { get; } = new("MEMX", "MM", "The Long-Term Stock Exchange", QuantConnect.Market.USA, SecurityType.Equity); /// /// Long-Term Stock Exchange /// public static Exchange LTSE { get; } = new("LTSE", "L", "The Long-Term Stock Exchange", QuantConnect.Market.USA, SecurityType.Equity); /// /// National Association of Securities Dealers Automated Quotation. /// public static Exchange NASDAQ { get; } = new("NASDAQ", "Q", "National Association of Securities Dealers Automated Quotation", QuantConnect.Market.USA, SecurityType.Equity); /// /// The NASDAQ options market /// public static Exchange NASDAQ_Options { get; } = new("XNDQ", "XNDQ", "NASDAQ options market", QuantConnect.Market.USA, SecurityType.Option, SecurityType.IndexOption); /// /// Bats Global Markets, Better Alternative Trading System /// public static Exchange BATS { get; } = new("BATS", "Z", "Bats Global Markets, Better Alternative Trading System", QuantConnect.Market.USA, SecurityType.Equity); /// /// New York Stock Archipelago Exchange /// public static Exchange ARCA { get; } = new("ARCA", "P", "New York Stock Archipelago Exchange", QuantConnect.Market.USA, SecurityType.Equity); /// /// New York Stock Archipelago Exchange /// public static Exchange ARCA_Options { get; } = new("ARCX", "ARCX", "NYSE Arca Options", QuantConnect.Market.USA, SecurityType.Option); /// /// New York Stock Exchange /// public static Exchange NYSE { get; } = new("NYSE", "N", "New York Stock Exchange", QuantConnect.Market.USA, SecurityType.Equity); /// /// Smart Exchange /// /// Brokerage will route to smart exchange public static Exchange SMART { get; } = new("SMART", "SMART", "SMART Exchange", QuantConnect.Market.USA, SecurityType.Equity); /// /// Over The Counter Exchange /// public static Exchange OTCX { get; } = new("OTCX", "OTCX", "Over the Counter Exchange", QuantConnect.Market.USA, SecurityType.Equity); /// /// The Investors Exchange /// public static Exchange IEX { get; } = new("IEX", "IEX", "Investors Exchange", QuantConnect.Market.USA, SecurityType.Equity); /// /// National Stock Exchange /// /// Is now known as the NYSE National public static Exchange NSX { get; } = new("NSE", "C", "National Stock Exchange", QuantConnect.Market.USA, SecurityType.Equity); /// /// The Financial Industry Regulatory Authority /// public static Exchange FINRA { get; } = new("FINRA", "D", "The Financial Industry Regulatory Authority", QuantConnect.Market.USA, SecurityType.Equity); /// /// Nasdaq International Securities Exchange /// public static Exchange ISE { get; } = new("ISE", "I", "Nasdaq International Securities Exchange", QuantConnect.Market.USA, SecurityType.Equity); /// /// Chicago Stock Exchange /// public static Exchange CSE { get; } = new("CSE", "M", "Chicago Stock Exchange", QuantConnect.Market.USA, SecurityType.Equity); /// /// The Chicago Board Options Exchange /// public static Exchange CBOE { get; } = new("CBOE", "W", "The Chicago Board Options Exchange", QuantConnect.Market.USA, SecurityType.Equity, SecurityType.Option, SecurityType.IndexOption); /// /// CBOE Options Exchange /// public static Exchange C2 { get; } = new("C2", "W", "CBOE Options Exchange", QuantConnect.Market.USA, SecurityType.Option); /// /// The American Options Exchange /// public static Exchange NASDAQ_BX { get; } = new("NASDAQ_BX", "B", "National Association of Securities Dealers Automated Quotation BX", QuantConnect.Market.USA, SecurityType.Equity); /// /// The Securities Industry Automation Corporation /// public static Exchange SIAC { get; } = new("SIAC", "SIAC", "The Securities Industry Automation Corporation", QuantConnect.Market.USA, SecurityType.Equity); /// /// CBOE EDGA U.S. equities Exchange /// public static Exchange EDGA { get; } = new("EDGA", "J", "CBOE EDGA U.S. equities Exchange", QuantConnect.Market.USA, SecurityType.Equity); /// /// CBOE EDGX U.S. equities Exchange /// public static Exchange EDGX { get; } = new("EDGX", "K", "CBOE EDGX U.S. equities Exchange", QuantConnect.Market.USA, SecurityType.Equity); /// /// CBOE EDGO U.S. option Exchange /// public static Exchange EDGO { get; } = new("EDGO", "EDGO", "CBOE EDGX OPTIONS EXCHANGE.", QuantConnect.Market.USA, SecurityType.Option, SecurityType.IndexOption); /// /// National Association of Securities Dealers Automated Quotation PSX /// public static Exchange NASDAQ_PSX { get; } = new("NASDAQ_PSX", "X", "National Association of Securities Dealers Automated Quotation PSX", QuantConnect.Market.USA, SecurityType.Equity); /// /// National Association of Securities Dealers Automated Quotation PSX /// public static Exchange BATS_Y { get; } = new("BATS_Y", "Y", "Bats Global Markets, Better Alternative Trading System", QuantConnect.Market.USA, SecurityType.Equity); /// /// The Boston Stock Exchange /// /// Now NASDAQ OMX BX public static Exchange BOSTON { get; } = new("BOSTON", "BB", "The Boston Stock Exchange", QuantConnect.Market.USA, SecurityType.Equity); /// /// The Boston Option Exchange /// public static Exchange BOX { get; } = new("BOX", "B", "The Boston Option Exchange", QuantConnect.Market.USA, SecurityType.Option, SecurityType.IndexOption); /// /// The American Stock Exchange /// /// Now NYSE MKT public static Exchange AMEX { get; } = new("AMEX", "A", "The American Stock Exchange", QuantConnect.Market.USA, SecurityType.Equity); /// /// Bombay Stock Exchange /// public static Exchange BSE { get; } = new("BSE", "BSE", "Bombay Stock Exchange", QuantConnect.Market.India, SecurityType.Equity); /// /// National Stock Exchange of India /// public static Exchange NSE { get; } = new("NSE", "NSE", "National Stock Exchange of India", QuantConnect.Market.India, SecurityType.Equity); /// /// The American Options Exchange /// /// Now NYSE Amex Options public static Exchange AMEX_Options { get; } = new("AMEX", "A", "The American Options Exchange", QuantConnect.Market.USA, SecurityType.Option); /// /// The Options Price Reporting Authority /// public static Exchange OPRA { get; } = new("OPRA", "O", "The Options Price Reporting Authority", QuantConnect.Market.USA, SecurityType.Option); /// /// Miami International Securities Options Exchange /// public static Exchange MIAX { get; } = new("MIAX", "M", "Miami International Securities Options Exchange", QuantConnect.Market.USA, SecurityType.Option); /// /// MIAX Pearl Option and Equity exchange. Offers a Price-Time allocation and Maker-Taker fee structure /// public static Exchange MIAX_PEARL { get; } = new("MIAX_PEARL", "MP", "MIAX PEARL", QuantConnect.Market.USA, SecurityType.Option, SecurityType.Equity); /// /// 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 /// public static Exchange MIAX_EMERALD { get; } = new("MIAX_EMERALD", "ME", "MIAX EMERALD", QuantConnect.Market.USA, SecurityType.Option); /// /// MIAX Sapphire: Electronic and floor trading for derivatives. /// public static Exchange MIAX_SAPPHIRE { get; } = new("MIAX_SAPPHIRE", "SPHR", "Miax Sapphire, LLC", QuantConnect.Market.USA, SecurityType.Option, SecurityType.IndexOption); /// /// International Securities Options Exchange GEMINI /// public static Exchange ISE_GEMINI { get; } = new("ISE_GEMINI", "H", "International Securities Options Exchange GEMINI", QuantConnect.Market.USA, SecurityType.Option); /// /// International Securities Options Exchange MERCURY /// public static Exchange ISE_MERCURY { get; } = new("ISE_MERCURY", "J", "International Securities Options Exchange MERCURY", QuantConnect.Market.USA, SecurityType.Option); /// /// The Chicago Mercantile Exchange (CME), is an organized exchange for the trading of futures and options. /// public static Exchange CME { get; } = new("CME", "CME", "Futures and Options Chicago Mercantile Exchange", QuantConnect.Market.CME, SecurityType.Future, SecurityType.FutureOption); /// /// The European Derivatives Exchange (EUREX) /// public static Exchange EUREX { get; } = new("EUREX", "EUREX", "European Derivatives Exchange", QuantConnect.Market.EUREX, SecurityType.Future, SecurityType.Index); /// /// /// The Chicago Board of Trade (CBOT) is a commodity exchange /// public static Exchange CBOT { get; } = new("CBOT", "CBOT", " Chicago Board of Trade Commodity Exchange", QuantConnect.Market.CBOT, SecurityType.Future, SecurityType.FutureOption); /// /// Cboe Futures Exchange /// public static Exchange CFE { get; } = new("CFE", "CFE", "CFE Futures Exchange", QuantConnect.Market.CFE, SecurityType.Future); /// /// COMEX Commodity Exchange /// public static Exchange COMEX { get; } = new("COMEX", "COMEX", "COMEX Futures Exchange", QuantConnect.Market.COMEX, SecurityType.Future); /// /// The Intercontinental Exchange /// public static Exchange ICE { get; } = new("ICE", "ICE", "The Intercontinental Exchange", QuantConnect.Market.ICE, SecurityType.Future); /// /// New York Mercantile Exchange /// public static Exchange NYMEX { get; } = new("NYMEX", "NYMEX", "New York Mercantile Exchange", QuantConnect.Market.NYMEX, SecurityType.Future, SecurityType.FutureOption); /// /// London International Financial Futures and Options Exchange /// public static Exchange NYSELIFFE { get; } = new("NYSELIFFE", "NYSELIFFE", "London International Financial Futures and Options Exchange", QuantConnect.Market.NYSELIFFE, SecurityType.Future, SecurityType.FutureOption); /// /// Credit Suisse First Boston (also known as CSFB and CS First Boston) is the investment banking affiliate of Credit Suisse headquartered in New York. /// public static Exchange CSFB { get; } = new("CSFB", "CSFB", "Credit Suisse First Boston", QuantConnect.Market.USA, SecurityType.Equity); /// /// 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. /// public static Exchange PHLX { get; } = new("PHLX", "X", "NASDAQ OMX PHLX", QuantConnect.Market.USA, SecurityType.Option, SecurityType.IndexOption); /// /// Exchange description /// [JsonIgnore] public string Description { get; } /// /// The exchange short code /// public string Code { get; init; } /// /// The exchange name /// public string Name { get; init; } /// /// The associated lean market /// public string Market { get; init; } /// /// Security types traded in this exchange /// [JsonProperty(ReferenceLoopHandling = ReferenceLoopHandling.Ignore)] public IReadOnlyList SecurityTypes { get; init; } = new List(); /// /// Creates a new empty exchange instance /// /// For json round trip serialization private Exchange() { } /// /// Creates a new exchange instance /// public Exchange(string name, string code, string description, string market, params SecurityType[] securityTypes) { Name = name; Market = market; Description = description; SecurityTypes = securityTypes?.ToList() ?? new List(); Code = string.IsNullOrEmpty(code) ? name : code; } /// /// Returns a string that represents the current object. /// public override string ToString() { return Name; } /// /// Returns the string representation of this exchange /// public static implicit operator string(Exchange exchange) { return ReferenceEquals(exchange, null) ? string.Empty : exchange.ToString(); } /// /// Indicates whether the current object is equal to another object /// public override bool Equals(object? obj) { if (ReferenceEquals(this, obj)) { return true; } var exchange = obj as Exchange; if (ReferenceEquals(exchange, null) || ReferenceEquals(exchange, UNKNOWN)) { // other is null or UNKNOWN (equivalents) // so we need to know how We compare with UNKNOWN return ReferenceEquals(this, UNKNOWN); } return Code == exchange.Code && Market == exchange.Market && SecurityTypes.All(exchange.SecurityTypes.Contains) && SecurityTypes.Count == exchange.SecurityTypes.Count; } /// /// Equals operator /// /// The left operand /// The right operand /// True if both symbols are equal, otherwise false public static bool operator ==(Exchange left, Exchange right) { if (ReferenceEquals(left, right)) { return true; } if (ReferenceEquals(left, null) || left.Equals(UNKNOWN)) { return ReferenceEquals(right, null) || right.Equals(UNKNOWN); } return left.Equals(right); } /// /// Not equals operator /// /// The left operand /// The right operand /// True if both symbols are not equal, otherwise false public static bool operator !=(Exchange left, Exchange right) { return !(left == right); } /// /// Serves as a hash function for a particular type. /// public override int GetHashCode() { unchecked { var hashCode = Code.GetHashCode(); hashCode = (hashCode * 397) ^ Market.GetHashCode(); for (var i = 0; i < SecurityTypes.Count; i++) { hashCode = (hashCode * 397) ^ SecurityTypes[i].GetHashCode(); } return hashCode; } } } }