18 using System.Collections.Generic;
28 private const int MaxMarketIdentifier = 1000;
30 private static Dictionary<string, int> Markets =
new Dictionary<string, int>();
31 private static Dictionary<int, string> ReverseMarkets =
new Dictionary<int, string>();
32 private static readonly IEnumerable<Tuple<string, int>> HardcodedMarkets =
new List<Tuple<string, int>>
34 Tuple.Create(
"empty", 0),
36 Tuple.Create(
FXCM, 2),
37 Tuple.Create(
Oanda, 3),
42 Tuple.Create(
NYMEX, 7),
43 Tuple.Create(
CBOT, 8),
45 Tuple.Create(
CBOE, 10),
46 Tuple.Create(
India, 11),
48 Tuple.Create(
GDAX, 12),
59 Tuple.Create(
COMEX, 22),
60 Tuple.Create(
CME, 23),
61 Tuple.Create(
SGX, 24),
62 Tuple.Create(
HKFE, 25),
65 Tuple.Create(
CFE, 33),
66 Tuple.Create(
FTX, 34),
67 Tuple.Create(
FTXUS, 35),
69 Tuple.Create(
Bybit, 37)
75 foreach (var market
in HardcodedMarkets)
77 Markets[market.Item1] = market.Item2;
78 ReverseMarkets[market.Item2] = market.Item1;
85 public const string USA =
"usa";
90 public const string Oanda =
"oanda";
95 public const string FXCM =
"fxcm";
112 public const string Globex =
"cmeglobex";
117 public const string NYMEX =
"nymex";
122 public const string CBOT =
"cbot";
127 public const string ICE =
"ice";
132 public const string CBOE =
"cboe";
137 public const string CFE =
"cfe";
142 public const string India =
"india";
147 public const string COMEX =
"comex";
152 public const string CME =
"cme";
157 public const string SGX =
"sgx";
162 public const string HKFE =
"hkfe";
172 public const string GDAX =
"gdax";
222 public const string FTX =
"ftx";
227 public const string FTXUS =
"ftxus";
237 public const string Bybit =
"bybit";
244 public static void Add(
string market,
int identifier)
246 if (identifier >= MaxMarketIdentifier)
248 throw new ArgumentOutOfRangeException(nameof(identifier),
Messages.
Market.InvalidMarketIdentifier(MaxMarketIdentifier));
251 market = market.ToLowerInvariant();
253 int marketIdentifier;
254 if (Markets.TryGetValue(market, out marketIdentifier) && identifier != marketIdentifier)
256 throw new ArgumentException(
Messages.
Market.TriedToAddExistingMarketWithDifferentIdentifier(market));
259 string existingMarket;
260 if (ReverseMarkets.TryGetValue(identifier, out existingMarket))
262 throw new ArgumentException(
Messages.
Market.TriedToAddExistingMarketIdentifier(market, existingMarket));
267 var newMarketDictionary = Markets.ToDictionary(entry => entry.Key,
268 entry => entry.Value);
269 newMarketDictionary[market] = identifier;
271 var newReverseMarketDictionary = ReverseMarkets.ToDictionary(entry => entry.Key,
272 entry => entry.Value);
273 newReverseMarketDictionary[identifier] = market;
275 Markets = newMarketDictionary;
276 ReverseMarkets = newReverseMarketDictionary;
286 return !Markets.TryGetValue(market, out var code) ? null : code;
296 return !ReverseMarkets.TryGetValue(code, out var market) ? null : market;
304 return Markets.Keys.ToList();