/* * 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; using System.Linq; using System.Collections.Generic; namespace QuantConnect { /// /// Markets Collection: Soon to be expanded to a collection of items specifying the market hour, timezones and country codes. /// public static class Market { // the upper bound (non-inclusive) for market identifiers private const int MaxMarketIdentifier = 1000; private static Dictionary Markets = new Dictionary(); private static Dictionary ReverseMarkets = new Dictionary(); private static readonly IEnumerable> HardcodedMarkets = new List> { Tuple.Create("empty", 0), Tuple.Create(USA, 1), Tuple.Create(FXCM, 2), Tuple.Create(Oanda, 3), Tuple.Create(Dukascopy, 4), Tuple.Create(Bitfinex, 5), Tuple.Create(Globex, 6), Tuple.Create(NYMEX, 7), Tuple.Create(CBOT, 8), Tuple.Create(ICE, 9), Tuple.Create(CBOE, 10), Tuple.Create(India, 11), Tuple.Create(GDAX, 12), Tuple.Create(Kraken, 13), Tuple.Create(Bittrex, 14), Tuple.Create(Bithumb, 15), Tuple.Create(Binance, 16), Tuple.Create(Poloniex, 17), Tuple.Create(Coinone, 18), Tuple.Create(HitBTC, 19), Tuple.Create(OkCoin, 20), Tuple.Create(Bitstamp, 21), Tuple.Create(COMEX, 22), Tuple.Create(CME, 23), Tuple.Create(SGX, 24), Tuple.Create(HKFE, 25), Tuple.Create(NYSELIFFE, 26), Tuple.Create(CFE, 33), Tuple.Create(FTX, 34), Tuple.Create(FTXUS, 35), Tuple.Create(BinanceUS, 36), Tuple.Create(Bybit, 37), Tuple.Create(Coinbase, 38), Tuple.Create(InteractiveBrokers, 39), Tuple.Create(EUREX, 40), Tuple.Create(OSE, 41) }; static Market() { // initialize our maps foreach (var market in HardcodedMarkets) { Markets[market.Item1] = market.Item2; ReverseMarkets[market.Item2] = market.Item1; } } /// /// USA Market /// public const string USA = "usa"; /// /// Oanda Market /// public const string Oanda = "oanda"; /// /// FXCM Market Hours /// public const string FXCM = "fxcm"; /// /// Dukascopy Market /// public const string Dukascopy = "dukascopy"; /// /// Bitfinex market /// public const string Bitfinex = "bitfinex"; // Futures exchanges /// /// CME Globex /// public const string Globex = "cmeglobex"; /// /// NYMEX /// public const string NYMEX = "nymex"; /// /// CBOT /// public const string CBOT = "cbot"; /// /// ICE /// public const string ICE = "ice"; /// /// CBOE /// public const string CBOE = "cboe"; /// /// CFE /// public const string CFE = "cfe"; /// /// NSE - National Stock Exchange /// public const string India = "india"; /// /// Comex /// public const string COMEX = "comex"; /// /// CME /// public const string CME = "cme"; /// /// EUREX /// public const string EUREX = "eurex"; /// /// Singapore Exchange /// public const string SGX = "sgx"; /// /// Hong Kong Exchange /// public const string HKFE = "hkfe"; /// /// Osaka Stock Exchange /// public const string OSE = "ose"; /// /// London International Financial Futures and Options Exchange /// public const string NYSELIFFE = "nyseliffe"; /// /// GDAX /// [Obsolete("The GDAX constant is deprecated. Please use Coinbase instead.")] public const string GDAX = Coinbase; /// /// Kraken /// public const string Kraken = "kraken"; /// /// Bitstamp /// public const string Bitstamp = "bitstamp"; /// /// OkCoin /// public const string OkCoin = "okcoin"; /// /// Bithumb /// public const string Bithumb = "bithumb"; /// /// Binance /// public const string Binance = "binance"; /// /// Poloniex /// public const string Poloniex = "poloniex"; /// /// Coinone /// public const string Coinone = "coinone"; /// /// HitBTC /// public const string HitBTC = "hitbtc"; /// /// Bittrex /// public const string Bittrex = "bittrex"; /// /// FTX /// public const string FTX = "ftx"; /// /// FTX.US /// public const string FTXUS = "ftxus"; /// /// Binance.US /// public const string BinanceUS = "binanceus"; /// /// Bybit /// public const string Bybit = "bybit"; /// /// Coinbase /// public const string Coinbase = "coinbase"; /// /// InteractiveBrokers market /// public const string InteractiveBrokers = "interactivebrokers"; /// /// Adds the specified market to the map of available markets with the specified identifier. /// /// The market string to add /// The identifier for the market, this value must be positive and less than 1000 public static void Add(string market, int identifier) { if (identifier >= MaxMarketIdentifier) { throw new ArgumentOutOfRangeException(nameof(identifier), Messages.Market.InvalidMarketIdentifier(MaxMarketIdentifier)); } market = market.ToLowerInvariant(); int marketIdentifier; if (Markets.TryGetValue(market, out marketIdentifier) && identifier != marketIdentifier) { throw new ArgumentException(Messages.Market.TriedToAddExistingMarketWithDifferentIdentifier(market)); } string existingMarket; if (ReverseMarkets.TryGetValue(identifier, out existingMarket)) { throw new ArgumentException(Messages.Market.TriedToAddExistingMarketIdentifier(market, existingMarket)); } // update our maps. // We make a copy and update the copy, later swap the references so it's thread safe with no lock var newMarketDictionary = Markets.ToDictionary(entry => entry.Key, entry => entry.Value); newMarketDictionary[market] = identifier; var newReverseMarketDictionary = ReverseMarkets.ToDictionary(entry => entry.Key, entry => entry.Value); newReverseMarketDictionary[identifier] = market; Markets = newMarketDictionary; ReverseMarkets = newReverseMarketDictionary; } /// /// Gets the market code for the specified market. Returns null if the market is not found /// /// The market to check for (case sensitive) /// The internal code used for the market. Corresponds to the value used when calling public static int? Encode(string market) { return !Markets.TryGetValue(market, out var code) ? null : code; } /// /// Gets the market string for the specified market code. /// /// The market code to be decoded /// The string representation of the market, or null if not found public static string Decode(int code) { return !ReverseMarkets.TryGetValue(code, out var market) ? null : market; } /// /// Returns a list of the supported markets /// public static List SupportedMarkets() { return Markets.Keys.ToList(); } } }