Lean  $LEAN_TAG$
Delisting.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 
17 using System;
18 using Newtonsoft.Json;
19 using QuantConnect.Orders;
20 
22 {
23  /// <summary>
24  /// Delisting event of a security
25  /// </summary>
26  public class Delisting : BaseData
27  {
28  /// <summary>
29  /// Gets the type of delisting, warning or delisted
30  /// A <see cref="DelistingType.Warning"/> is sent
31  /// </summary>
32  [JsonProperty]
33  public DelistingType Type { get; private set; }
34 
35  /// <summary>
36  /// Gets the <see cref="OrderTicket"/> that was submitted to liquidate this position
37  /// </summary>
38  public OrderTicket Ticket { get; private set; }
39 
40  /// <summary>
41  /// Initializes a new instance of the <see cref="Delisting"/> class
42  /// </summary>
43  public Delisting()
44  {
45  DataType = MarketDataType.Auxiliary;
46  Type = DelistingType.Delisted;
47  }
48 
49  /// <summary>
50  /// Initializes a new instance of the <see cref="Delisting"/> class
51  /// </summary>
52  /// <param name="symbol">The delisted symbol</param>
53  /// <param name="date">The date the symbol was delisted</param>
54  /// <param name="price">The final price before delisting</param>
55  /// <param name="type">The type of delisting event</param>
56  public Delisting(Symbol symbol, DateTime date, decimal price, DelistingType type)
57  : this()
58  {
59  Symbol = symbol;
60  Time = date;
61  Value = price;
62  Type = type;
63  }
64 
65  /// <summary>
66  /// Sets the <see cref="OrderTicket"/> used to liquidate this position
67  /// </summary>
68  /// <param name="ticket">The ticket that represents the order to liquidate this position</param>
69  public void SetOrderTicket(OrderTicket ticket)
70  {
71  Ticket = ticket;
72  }
73 
74  /// <summary>
75  /// Reader converts each line of the data source into BaseData objects. Each data type creates its own factory method, and returns a new instance of the object
76  /// each time it is called.
77  /// </summary>
78  /// <param name="config">Subscription data config setup object</param>
79  /// <param name="line">Line of the source document</param>
80  /// <param name="date">Date of the requested data</param>
81  /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
82  /// <returns>Instance of the T:BaseData object generated by this line of the CSV</returns>
83  public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
84  {
85  throw new NotImplementedException("This method is not supposed to be called on the Delisting type.");
86  }
87 
88  /// <summary>
89  /// Return the URL string source of the file. This will be converted to a stream
90  /// </summary>
91  /// <param name="config">Configuration object</param>
92  /// <param name="date">Date of this source file</param>
93  /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
94  /// <returns>String URL of source file.</returns>
95  public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
96  {
97  return null;
98  }
99 
100  /// <summary>
101  /// Return a new instance clone of this object, used in fill forward
102  /// </summary>
103  /// <remarks>
104  /// This base implementation uses reflection to copy all public fields and properties
105  /// </remarks>
106  /// <returns>A clone of the current object</returns>
107  public override BaseData Clone()
108  {
109  return new Delisting(Symbol, Time, Price, Type);
110  }
111 
112  /// <summary>
113  /// Formats a string with the symbol and value.
114  /// </summary>
115  /// <returns>string - a string formatted as SPY: 167.753</returns>
116  public override string ToString()
117  {
118  var type = Type == DelistingType.Warning ? "Delisting Warning" : "Delisted";
119  return $"{type}: {Symbol} {EndTime}";
120  }
121  }
122 }