Lean  $LEAN_TAG$
Global.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;
17 using Newtonsoft.Json;
19 using Newtonsoft.Json.Converters;
20 using System.Runtime.Serialization;
21 using System.Runtime.CompilerServices;
22 
23 namespace QuantConnect
24 {
25  /// <summary>
26  /// Shortcut date format strings
27  /// </summary>
28  public static class DateFormat
29  {
30  /// Year-Month-Date 6 Character Date Representation
31  public const string SixCharacter = "yyMMdd";
32  /// YYYY-MM-DD Eight Character Date Representation
33  public const string EightCharacter = "yyyyMMdd";
34  /// Daily and hourly time format
35  public const string TwelveCharacter = "yyyyMMdd HH:mm";
36  /// JSON Format Date Representation
37  public static string JsonFormat { get; } = "yyyy-MM-ddTHH:mm:ss";
38  /// MySQL Format Date Representation
39  public const string DB = "yyyy-MM-dd HH:mm:ss";
40  /// QuantConnect UX Date Representation
41  public const string UI = "yyyy-MM-dd HH:mm:ss";
42  /// en-US Short Date and Time Pattern
43  public const string USShort = "M/d/yy h:mm tt";
44  /// en-US Short Date Pattern
45  public const string USShortDateOnly = "M/d/yy";
46  /// en-US format
47  public const string US = "M/d/yyyy h:mm:ss tt";
48  /// en-US Date format
49  public const string USDateOnly = "M/d/yyyy";
50  /// Date format of QC forex data
51  public const string Forex = "yyyyMMdd HH:mm:ss.ffff";
52  /// Date format of FIX Protocol UTC Timestamp without milliseconds
53  public const string FIX = "yyyyMMdd-HH:mm:ss";
54  /// Date format of FIX Protocol UTC Timestamp with milliseconds
55  public const string FIXWithMillisecond = "yyyyMMdd-HH:mm:ss.fff";
56  /// YYYYMM Year and Month Character Date Representation (used for futures)
57  public const string YearMonth = "yyyyMM";
58  }
59 
60  /// <summary>
61  /// Singular holding of assets from backend live nodes:
62  /// </summary>
63  [JsonObject]
64  public class Holding
65  {
66  /// Symbol of the Holding:
67  [JsonProperty(PropertyName = "symbol")]
68  public Symbol Symbol { get; set; } = Symbol.Empty;
69 
70  /// Type of the security
71  [JsonProperty(PropertyName = "type")]
73 
74  /// The currency symbol of the holding, such as $
75  [JsonProperty(PropertyName = "currencySymbol")]
76  public string CurrencySymbol { get; set; }
77 
78  /// Average Price of our Holding in the currency the symbol is traded in
79  [JsonProperty(PropertyName = "averagePrice", DefaultValueHandling = DefaultValueHandling.Ignore)]
80  public decimal AveragePrice { get; set; }
81 
82  /// Quantity of Symbol We Hold.
83  [JsonProperty(PropertyName = "quantity", DefaultValueHandling = DefaultValueHandling.Ignore)]
84  public decimal Quantity { get; set; }
85 
86  /// Current Market Price of the Asset in the currency the symbol is traded in
87  [JsonProperty(PropertyName = "marketPrice", DefaultValueHandling = DefaultValueHandling.Ignore)]
88  public decimal MarketPrice { get; set; }
89 
90  /// Current market conversion rate into the account currency
91  [JsonProperty(PropertyName = "conversionRate", DefaultValueHandling = DefaultValueHandling.Ignore)]
92  public decimal? ConversionRate { get; set; }
93 
94  /// Current market value of the holding
95  [JsonProperty(PropertyName = "marketValue", DefaultValueHandling = DefaultValueHandling.Ignore)]
96  public decimal MarketValue { get; set; }
97 
98  /// Current unrealized P/L of the holding
99  [JsonProperty(PropertyName = "unrealizedPnl", DefaultValueHandling = DefaultValueHandling.Ignore)]
100  public decimal UnrealizedPnL { get; set; }
101 
102  /// Current unrealized P/L % of the holding
103  [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
104  public decimal UnrealizedPnLPercent { get; set; }
105 
106  /// Create a new default holding:
107  public Holding()
108  {
109  CurrencySymbol = "$";
110  }
111 
112  /// <summary>
113  /// Create a simple JSON holdings from a Security holding class.
114  /// </summary>
115  /// <param name="security">The security instance</param>
116  public Holding(Security security)
117  : this()
118  {
119  var holding = security.Holdings;
120 
121  Symbol = holding.Symbol;
122  Quantity = holding.Quantity;
123  MarketValue = holding.HoldingsValue;
126 
127  var rounding = security.SymbolProperties.MinimumPriceVariation.GetDecimalPlaces();
128 
129  AveragePrice = Math.Round(holding.AveragePrice, rounding);
130  MarketPrice = Math.Round(holding.Price, rounding);
131  UnrealizedPnL = Math.Round(holding.UnrealizedProfit, 2);
132  UnrealizedPnLPercent = Math.Round(holding.UnrealizedProfitPercent * 100, 2);
133  }
134 
135  /// <summary>
136  /// Clones this instance
137  /// </summary>
138  /// <returns>A new Holding object with the same values as this one</returns>
139  public Holding Clone()
140  {
141  return new Holding
142  {
144  Symbol = Symbol,
145  Quantity = Quantity,
152  };
153  }
154 
155  /// <summary>
156  /// Writes out the properties of this instance to string
157  /// </summary>
158  public override string ToString()
159  {
160  return Messages.Holding.ToString(this);
161  }
162  }
163 
164  /// <summary>
165  /// Represents the types of environments supported by brokerages for trading
166  /// </summary>
167  [JsonConverter(typeof(StringEnumConverter))]
169  {
170  /// <summary>
171  /// Live trading (0)
172  /// </summary>
173  [EnumMember(Value = "live")]
174  Live,
175 
176  /// <summary>
177  /// Paper trading (1)
178  /// </summary>
179  [EnumMember(Value = "paper")]
180  Paper
181  }
182 
183  /// <summary>
184  /// Multilanguage support enum: which language is this project for the interop bridge converter.
185  /// </summary>
186  [JsonConverter(typeof(StringEnumConverter))]
187  public enum Language
188  {
189  /// <summary>
190  /// C# Language Project (0)
191  /// </summary>
192  [EnumMember(Value = "C#")]
193  CSharp,
194 
195  /// <summary>
196  /// FSharp Project (1)
197  /// </summary>
198  [EnumMember(Value = "F#")]
199  FSharp,
200 
201  /// <summary>
202  /// Visual Basic Project (2)
203  /// </summary>
204  [EnumMember(Value = "VB")]
205  VisualBasic,
206 
207  /// <summary>
208  /// Java Language Project (3)
209  /// </summary>
210  [EnumMember(Value = "Ja")]
211  Java,
212 
213  /// <summary>
214  /// Python Language Project (4)
215  /// </summary>
216  [EnumMember(Value = "Py")]
217  Python
218  }
219 
220  /// <summary>
221  /// Live server types available through the web IDE. / QC deployment.
222  /// </summary>
223  public enum ServerType
224  {
225  /// <summary>
226  /// Additional server (0)
227  /// </summary>
228  Server512,
229 
230  /// <summary>
231  /// Upgraded server (1)
232  /// </summary>
233  Server1024,
234 
235  /// <summary>
236  /// Server with 2048 MB Ram (2)
237  /// </summary>
238  Server2048
239  }
240 
241  /// <summary>
242  /// Type of tradable security / underlying asset
243  /// </summary>
244  public enum SecurityType
245  {
246  /// <summary>
247  /// Base class for all security types (0)
248  /// </summary>
249  Base,
250 
251  /// <summary>
252  /// US Equity Security (1)
253  /// </summary>
254  Equity,
255 
256  /// <summary>
257  /// Option Security Type (2)
258  /// </summary>
259  Option,
260 
261  /// <summary>
262  /// Commodity Security Type (3)
263  /// </summary>
264  Commodity,
265 
266  /// <summary>
267  /// FOREX Security (4)
268  /// </summary>
269  Forex,
270 
271  /// <summary>
272  /// Future Security Type (5)
273  /// </summary>
274  Future,
275 
276  /// <summary>
277  /// Contract For a Difference Security Type (6)
278  /// </summary>
279  Cfd,
280 
281  /// <summary>
282  /// Cryptocurrency Security Type (7)
283  /// </summary>
284  Crypto,
285 
286  /// <summary>
287  /// Futures Options Security Type (8)
288  /// </summary>
289  /// <remarks>
290  /// Futures options function similar to equity options, but with a few key differences.
291  /// Firstly, the contract unit of trade is 1x, rather than 100x. This means that each
292  /// option represents the right to buy or sell 1 future contract at expiry/exercise.
293  /// The contract multiplier for Futures Options plays a big part in determining the premium
294  /// of the option, which can also differ from the underlying future's multiplier.
295  /// </remarks>
296  FutureOption,
297 
298  /// <summary>
299  /// Index Security Type (9)
300  /// </summary>
301  Index,
302 
303  /// <summary>
304  /// Index Option Security Type (10)
305  /// </summary>
306  /// <remarks>
307  /// For index options traded on American markets, they tend to be European-style options and are Cash-settled.
308  /// </remarks>
309  IndexOption,
310 
311  /// <summary>
312  /// Crypto Future Type (11)
313  /// </summary>
314  CryptoFuture,
315  }
316 
317  /// <summary>
318  /// Account type: margin or cash
319  /// </summary>
320  public enum AccountType
321  {
322  /// <summary>
323  /// Margin account type (0)
324  /// </summary>
325  Margin,
326 
327  /// <summary>
328  /// Cash account type (1)
329  /// </summary>
330  Cash
331  }
332 
333  /// <summary>
334  /// Market data style: is the market data a summary (OHLC style) bar, or is it a time-price value.
335  /// </summary>
336  public enum MarketDataType
337  {
338  /// Base market data type (0)
339  Base,
340  /// TradeBar market data type (OHLC summary bar) (1)
341  TradeBar,
342  /// Tick market data type (price-time pair) (2)
343  Tick,
344  /// Data associated with an instrument (3)
345  Auxiliary,
346  /// QuoteBar market data type (4) [Bid(OHLC), Ask(OHLC) and Mid(OHLC) summary bar]
347  QuoteBar,
348  /// Option chain data (5)
349  OptionChain,
350  /// Futures chain data (6)
352  }
353 
354  /// <summary>
355  /// Datafeed enum options for selecting the source of the datafeed.
356  /// </summary>
357  public enum DataFeedEndpoint
358  {
359  /// Backtesting Datafeed Endpoint (0)
360  Backtesting,
361  /// Loading files off the local system (1)
362  FileSystem,
363  /// Getting datafeed from a QC-Live-Cloud (2)
364  LiveTrading,
365  /// Database (3)
366  Database
367  }
368 
369  /// <summary>
370  /// Cloud storage permission options.
371  /// </summary>
372  public enum StoragePermissions
373  {
374  /// Public Storage Permissions (0)
375  Public,
376 
377  /// Authenticated Read Storage Permissions (1)
379  }
380 
381  /// <summary>
382  /// Types of tick data
383  /// </summary>
384  /// <remarks>QuantConnect currently only has trade, quote, open interest tick data.</remarks>
385  public enum TickType
386  {
387  /// Trade type tick object (0)
388  Trade ,
389  /// Quote type tick object (1)
390  Quote,
391  /// Open Interest type tick object (for options, futures) (2)
393  }
394 
395  /// <summary>
396  /// Specifies the type of <see cref="QuantConnect.Data.Market.Delisting"/> data
397  /// </summary>
398  public enum DelistingType
399  {
400  /// <summary>
401  /// Specifies a warning of an imminent delisting (0)
402  /// </summary>
403  Warning = 0,
404 
405  /// <summary>
406  /// Specifies the symbol has been delisted (1)
407  /// </summary>
408  Delisted = 1
409  }
410 
411  /// <summary>
412  /// Specifies the type of <see cref="QuantConnect.Data.Market.Split"/> data
413  /// </summary>
414  public enum SplitType
415  {
416  /// <summary>
417  /// Specifies a warning of an imminent split event (0)
418  /// </summary>
419  Warning = 0,
420 
421  /// <summary>
422  /// Specifies the symbol has been split (1)
423  /// </summary>
424  SplitOccurred = 1
425  }
426 
427  /// <summary>
428  /// Resolution of data requested.
429  /// </summary>
430  /// <remarks>Always sort the enum from the smallest to largest resolution</remarks>
431  public enum Resolution
432  {
433  /// Tick Resolution (0)
434  Tick,
435  /// Second Resolution (1)
436  Second,
437  /// Minute Resolution (2)
438  Minute,
439  /// Hour Resolution (3)
440  Hour,
441  /// Daily Resolution (4)
442  Daily
443  }
444 
445  /// <summary>
446  /// Specifies what side a position is on, long/short
447  /// </summary>
448  public enum PositionSide
449  {
450  /// <summary>
451  /// A short position, quantity less than zero (-1)
452  /// </summary>
453  Short = -1,
454 
455  /// <summary>
456  /// No position, quantity equals zero (0)
457  /// </summary>
458  None = 0,
459 
460  /// <summary>
461  /// A long position, quantity greater than zero (1)
462  /// </summary>
463  Long = 1
464  }
465 
466  /// <summary>
467  /// Specifies the different types of options
468  /// </summary>
469  public enum OptionRight
470  {
471  /// <summary>
472  /// A call option, the right to buy at the strike price (0)
473  /// </summary>
474  Call,
475 
476  /// <summary>
477  /// A put option, the right to sell at the strike price (1)
478  /// </summary>
479  Put
480  }
481 
482  /// <summary>
483  /// Specifies the style of an option
484  /// </summary>
485  public enum OptionStyle
486  {
487  /// <summary>
488  /// American style options are able to be exercised at any time on or before the expiration date (0)
489  /// </summary>
490  American,
491 
492  /// <summary>
493  /// European style options are able to be exercised on the expiration date only (1)
494  /// </summary>
495  European
496  }
497 
498  /// <summary>
499  /// Specifies the type of settlement in derivative deals
500  /// </summary>
501  public enum SettlementType
502  {
503  /// <summary>
504  /// Physical delivery of the underlying security (0)
505  /// </summary>
507 
508  /// <summary>
509  /// Cash is paid/received on settlement (1)
510  /// </summary>
511  Cash
512  }
513 
514  /// <summary>
515  /// Wrapper for algorithm status enum to include the charting subscription.
516  /// </summary>
517  public class AlgorithmControl
518  {
519  /// <summary>
520  /// Default initializer for algorithm control class.
521  /// </summary>
523  {
524  // default to true, API can override
525  Initialized = false;
526  HasSubscribers = true;
527  Status = AlgorithmStatus.Running;
529  }
530 
531  /// <summary>
532  /// Register this control packet as not defaults.
533  /// </summary>
534  public bool Initialized { get; set; }
535 
536  /// <summary>
537  /// Current run status of the algorithm id.
538  /// </summary>
539  public AlgorithmStatus Status { get; set; }
540 
541  /// <summary>
542  /// Currently requested chart.
543  /// </summary>
544  public string ChartSubscription { get; set; }
545 
546  /// <summary>
547  /// True if there's subscribers on the channel
548  /// </summary>
549  public bool HasSubscribers { get; set; }
550  }
551 
552  /// <summary>
553  /// States of a live deployment.
554  /// </summary>
555  public enum AlgorithmStatus
556  {
557  /// Error compiling algorithm at start (0)
558  DeployError,
559  /// Waiting for a server (1)
560  InQueue,
561  /// Running algorithm (2)
562  Running,
563  /// Stopped algorithm or exited with runtime errors (3)
564  Stopped,
565  /// Liquidated algorithm (4)
566  Liquidated,
567  /// Algorithm has been deleted (5)
568  Deleted,
569  /// Algorithm completed running (6)
570  Completed,
571  /// Runtime Error Stoped Algorithm (7)
572  RuntimeError,
573  /// Error in the algorithm id (not used) (8)
574  Invalid,
575  /// The algorithm is logging into the brokerage (9)
576  LoggingIn,
577  /// The algorithm is initializing (10)
578  Initializing,
579  /// History status update (11)
580  History
581  }
582 
583  /// <summary>
584  /// Specifies where a subscription's data comes from
585  /// </summary>
587  {
588  /// <summary>
589  /// The subscription's data comes from disk (0)
590  /// </summary>
591  LocalFile,
592 
593  /// <summary>
594  /// The subscription's data is downloaded from a remote source (1)
595  /// </summary>
596  RemoteFile,
597 
598  /// <summary>
599  /// The subscription's data comes from a rest call that is polled and returns a single line/data point of information (2)
600  /// </summary>
601  Rest,
602 
603  /// <summary>
604  /// The subscription's data is streamed (3)
605  /// </summary>
606  Streaming,
607 
608  /// <summary>
609  /// The subscription's data comes from the object store (4)
610  /// </summary>
612  }
613 
614  /// <summary>
615  /// Used by the <see cref="Data.LeanDataWriter"/> to determine which merge write policy should be applied
616  /// </summary>
617  public enum WritePolicy
618  {
619  /// <summary>
620  /// Will overwrite any existing file or zip entry with the new content (0)
621  /// </summary>
622  Overwrite = 0,
623 
624  /// <summary>
625  /// Will inject and merge new content with the existings file content (1)
626  /// </summary>
627  Merge,
628 
629  /// <summary>
630  /// Will append new data to the end of the file or zip entry (2)
631  /// </summary>
632  Append
633  }
634 
635  /// <summary>
636  /// enum Period - Enum of all the analysis periods, AS integers. Reference "Period" Array to access the values
637  /// </summary>
638  public enum Period
639  {
640  /// Period Short Codes - 10
641  TenSeconds = 10,
642  /// Period Short Codes - 30 Second
643  ThirtySeconds = 30,
644  /// Period Short Codes - 60 Second
645  OneMinute = 60,
646  /// Period Short Codes - 120 Second
647  TwoMinutes = 120,
648  /// Period Short Codes - 180 Second
649  ThreeMinutes = 180,
650  /// Period Short Codes - 300 Second
651  FiveMinutes = 300,
652  /// Period Short Codes - 600 Second
653  TenMinutes = 600,
654  /// Period Short Codes - 900 Second
655  FifteenMinutes = 900,
656  /// Period Short Codes - 1200 Second
657  TwentyMinutes = 1200,
658  /// Period Short Codes - 1800 Second
659  ThirtyMinutes = 1800,
660  /// Period Short Codes - 3600 Second
661  OneHour = 3600,
662  /// Period Short Codes - 7200 Second
663  TwoHours = 7200,
664  /// Period Short Codes - 14400 Second
665  FourHours = 14400,
666  /// Period Short Codes - 21600 Second
667  SixHours = 21600
668  }
669 
670  /// <summary>
671  /// Specifies how data is normalized before being sent into an algorithm
672  /// </summary>
674  {
675  /// <summary>
676  /// No modifications to the asset price at all. For Equities, dividends are paid in cash and splits are applied directly to your portfolio quantity. (0)
677  /// </summary>
678  Raw,
679  /// <summary>
680  /// Splits and dividends are backward-adjusted into the price of the asset. The price today is identical to the current market price. (1)
681  /// </summary>
682  Adjusted,
683  /// <summary>
684  /// Equity splits are applied to the price adjustment but dividends are paid in cash to your portfolio. This normalization mode allows you to manage dividend payments (e.g. reinvestment) while still giving a smooth time series of prices for indicators. (2)
685  /// </summary>
687  /// <summary>
688  /// Equity splits are applied to the price adjustment and the value of all future dividend payments is added to the initial asset price. (3)
689  /// </summary>
690  TotalReturn,
691  /// <summary>
692  /// Eliminates price jumps between two consecutive contracts, adding a factor based on the difference of their prices. The first contract has the true price. Factor 0. (4)
693  /// </summary>
694  /// <remarks>First contract is the true one, factor 0</remarks>
696  /// <summary>
697  /// Eliminates price jumps between two consecutive contracts, adding a factor based on the difference of their prices. The last contract has the true price. Factor 0. (5)
698  /// </summary>
699  /// <remarks>Last contract is the true one, factor 0</remarks>
701  /// <summary>
702  /// Eliminates price jumps between two consecutive contracts, multiplying the prices by their ratio. The last contract has the true price. Factor 1. (6)
703  /// </summary>
704  /// <remarks>Last contract is the true one, factor 1</remarks>
706  /// <summary>
707  /// Splits and dividends are adjusted into the prices in a given date. Only for history requests. (7)
708  /// </summary>
709  ScaledRaw,
710  }
711 
712  /// <summary>
713  /// Continuous contracts mapping modes
714  /// </summary>
715  public enum DataMappingMode
716  {
717  /// <summary>
718  /// The contract maps on the previous day of expiration of the front month (0)
719  /// </summary>
721  /// <summary>
722  /// The contract maps on the first date of the delivery month of the front month. If the contract expires prior to this date,
723  /// then it rolls on the contract's last trading date instead (1)
724  /// </summary>
725  /// <remarks>For example, the Crude Oil WTI (CL) 'DEC 2021 CLZ1' contract expires on November, 19 2021, so the mapping date will be its expiration date.</remarks>
726  /// <remarks>Another example is the Corn 'DEC 2021 ZCZ1' contract, which expires on December, 14 2021, so the mapping date will be December 1, 2021.</remarks>
728  /// <summary>
729  /// The contract maps when the following back month contract has a higher open interest that the current front month (2)
730  /// </summary>
731  OpenInterest,
732  /// <summary>
733  /// The contract maps when any of the back month contracts of the next year have a higher volume that the current front month (3)
734  /// </summary>
736  }
737 
738  /// <summary>
739  /// The different types of <see cref="CashBook.Updated"/> events
740  /// </summary>
741  public enum CashBookUpdateType
742  {
743  /// <summary>
744  /// A new <see cref="Cash.Symbol"/> was added (0)
745  /// </summary>
746  Added,
747  /// <summary>
748  /// One or more <see cref="Cash"/> instances were removed (1)
749  /// </summary>
750  Removed,
751  /// <summary>
752  /// An existing <see cref="Cash.Symbol"/> was updated (2)
753  /// </summary>
754  Updated
755  }
756 
757  /// <summary>
758  /// Defines Lean exchanges codes and names
759  /// </summary>
760  public static class Exchanges
761  {
762  /// <summary>
763  /// Gets the exchange as single character representation.
764  /// </summary>
765  [MethodImpl(MethodImplOptions.AggressiveInlining)]
766  public static string GetPrimaryExchangeCodeGetPrimaryExchange(this string exchange,
767  SecurityType securityType = SecurityType.Equity,
768  string market = Market.USA)
769  {
770  return exchange.GetPrimaryExchange(securityType, market).Code;
771  }
772 
773  /// <summary>
774  /// Gets the exchange as PrimaryExchange object.
775  /// </summary>
776  /// <remarks>Useful for performance</remarks>
777  [MethodImpl(MethodImplOptions.AggressiveInlining)]
778  public static Exchange GetPrimaryExchange(this string exchange,
779  SecurityType securityType = SecurityType.Equity,
780  string market = Market.USA)
781  {
782  var primaryExchange = Exchange.UNKNOWN;
783  if (string.IsNullOrEmpty(exchange))
784  {
785  return primaryExchange;
786  }
787 
788  if (securityType == SecurityType.Equity)
789  {
790  switch (exchange.LazyToUpper())
791  {
792  case "T":
793  case "Q":
794  case "NASDAQ":
795  case "NASDAQ_OMX":
796  return Exchange.NASDAQ;
797  case "Z":
798  case "BATS":
799  case "BATS Z":
800  case "BATS_Z":
801  return Exchange.BATS;
802  case "P":
803  case "ARCA":
804  return Exchange.ARCA;
805  case "N":
806  case "NYSE":
807  return Exchange.NYSE;
808  case "C":
809  case "NSX":
810  case "NSE":
811  if (market == Market.USA)
812  {
813  return Exchange.NSX;
814  }
815  else if (market == Market.India)
816  {
817  return Exchange.NSE;
818  }
819  return Exchange.UNKNOWN;
820  case "D":
821  case "FINRA":
822  return Exchange.FINRA;
823  case "I":
824  case "ISE":
825  return Exchange.ISE;
826  case "M":
827  case "CSE":
828  return Exchange.CSE;
829  case "W":
830  case "CBOE":
831  return Exchange.CBOE;
832  case "A":
833  case "AMEX":
834  return Exchange.AMEX;
835  case "SIAC":
836  return Exchange.SIAC;
837  case "J":
838  case "EDGA":
839  return Exchange.EDGA;
840  case "K":
841  case "EDGX":
842  return Exchange.EDGX;
843  case "B":
844  case "NASDAQ BX":
845  case "NASDAQ_BX":
846  return Exchange.NASDAQ_BX;
847  case "X":
848  case "NASDAQ PSX":
849  case "NASDAQ_PSX":
850  return Exchange.NASDAQ_PSX;
851  case "Y":
852  case "BATS Y":
853  case "BATS_Y":
854  case "BYX":
855  return Exchange.BATS_Y;
856  case "BB":
857  case "BOSTON":
858  return Exchange.BOSTON;
859  case "BSE":
860  return Exchange.BSE;
861  case "IEX":
862  return Exchange.IEX;
863  case "SMART":
864  return Exchange.SMART;
865  case "OTCX":
866  return Exchange.OTCX;
867  case "MP":
868  case "MIAX PEARL":
869  case "MIAX_PEARL":
870  return Exchange.MIAX_PEARL;
871  case "L":
872  case "LTSE":
873  return Exchange.LTSE;
874  case "MM":
875  case "MEMX":
876  return Exchange.MEMX;
877  case "CSFB":
878  return Exchange.CSFB;
879  }
880  }
881  else if (securityType == SecurityType.Option)
882  {
883  switch (exchange.LazyToUpper())
884  {
885  case "A":
886  case "AMEX":
887  return Exchange.AMEX_Options;
888  case "M":
889  case "MIAX":
890  return Exchange.MIAX;
891  case "ME":
892  case "MIAX EMERALD":
893  case "MIAX_EMERALD":
894  return Exchange.MIAX_EMERALD;
895  case "MP":
896  case "MIAX PEARL":
897  case "MIAX_PEARL":
898  return Exchange.MIAX_PEARL;
899  case "I":
900  case "ISE":
901  return Exchange.ISE;
902  case "H":
903  case "ISE GEMINI":
904  case "ISE_GEMINI":
905  return Exchange.ISE_GEMINI;
906  case "J":
907  case "ISE MERCURY":
908  case "ISE_MERCURY":
909  return Exchange.ISE_MERCURY;
910  case "O":
911  case "OPRA":
912  return Exchange.OPRA;
913  case "W":
914  case "C2":
915  return Exchange.C2;
916  case "XNDQ":
917  return Exchange.NASDAQ_Options;
918  case "ARCX":
919  return Exchange.ARCA_Options;
920  case "EDGO":
921  return Exchange.EDGO;
922  case "BOX":
923  case "B":
924  return Exchange.BOX;
925  case "PHLX":
926  return Exchange.PHLX;
927  case "SPHR":
928  case "MIAX SAPPHIRE":
929  case "MIAX_SAPPHIRE":
930  return Exchange.MIAX_SAPPHIRE;
931  default:
932  return Exchange.UNKNOWN;
933  }
934  }
935  else if (securityType == SecurityType.Future || securityType == SecurityType.FutureOption)
936  {
937  switch (exchange.LazyToUpper())
938  {
939  case "CME":
940  return Exchange.CME;
941  case "CBOT":
942  return Exchange.CBOT;
943  case "NYMEX":
944  return Exchange.NYMEX;
945  case "ICE":
946  return Exchange.ICE;
947  case "CFE":
948  return Exchange.CFE;
949  case "COMEX":
950  return Exchange.COMEX;
951  case "NYSELIFFE":
952  return Exchange.NYSELIFFE;
953  case "EUREX":
954  return Exchange.EUREX;
955  default:
956  return Exchange.UNKNOWN;
957  }
958  }
959  return Exchange.UNKNOWN;
960  }
961  }
962 
963  /// <summary>
964  /// Defines the different channel status values
965  /// </summary>
966  public static class ChannelStatus
967  {
968  /// <summary>
969  /// The channel is empty
970  /// </summary>
971  public const string Vacated = "channel_vacated";
972 
973  /// <summary>
974  /// The channel has subscribers
975  /// </summary>
976  public const string Occupied = "channel_occupied";
977  }
978 
979  /// <summary>
980  /// Represents the types deployment targets for algorithms
981  /// </summary>
982  [JsonConverter(typeof(StringEnumConverter))]
983  public enum DeploymentTarget
984  {
985  /// <summary>
986  /// Cloud Platform (0)
987  /// </summary>
989 
990  /// <summary>
991  /// Local Platform (1)
992  /// </summary>
994 
995  /// <summary>
996  /// Private Cloud Platform (2)
997  /// </summary>
999  }
1000 
1001  /// <summary>
1002  /// Represents the deployment modes of an algorithm
1003  /// </summary>
1004  [JsonConverter(typeof(StringEnumConverter))]
1005  public enum AlgorithmMode
1006  {
1007  /// <summary>
1008  /// Live (0)
1009  /// </summary>
1010  Live,
1011 
1012  /// <summary>
1013  /// Optimization (1)
1014  /// </summary>
1015  Optimization,
1016 
1017  /// <summary>
1018  /// Backtesting (2)
1019  /// </summary>
1020  Backtesting,
1021 
1022  /// <summary>
1023  /// Research (3)
1024  /// </summary>
1025  Research
1026  }
1027 }