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