Lean  $LEAN_TAG$
MarketTodayPacket.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;
18 
19 namespace QuantConnect.Packets
20 {
21 
22  /// <summary>
23  /// Market today information class
24  /// </summary>
25  public class MarketToday
26  {
27  /// <summary>
28  /// Date this packet was generated.
29  /// </summary>
30  [JsonProperty(PropertyName = "date")]
31  public DateTime Date { get; set; }
32 
33  /// <summary>
34  /// Given the dates and times above, what is the current market status - open or closed.
35  /// </summary>
36  [JsonProperty(PropertyName = "status")]
37  public string Status { get; set; } = string.Empty;
38 
39  /// <summary>
40  /// Premarket hours for today
41  /// </summary>
42  [JsonProperty(PropertyName = "premarket")]
43  public MarketHours PreMarket { get; set; }
44 
45  /// <summary>
46  /// Normal trading market hours for today
47  /// </summary>
48  [JsonProperty(PropertyName = "open")]
49  public MarketHours Open { get; set; }
50 
51  /// <summary>
52  /// Post market hours for today
53  /// </summary>
54  [JsonProperty(PropertyName = "postmarket")]
55  public MarketHours PostMarket { get; set; }
56 
57  /// <summary>
58  /// Default constructor (required for JSON serialization)
59  /// </summary>
60  public MarketToday()
61  { }
62  }
63 
64  /// <summary>
65  /// Market open hours model for pre, normal and post market hour definitions.
66  /// </summary>
67  public class MarketHours
68  {
69  /// <summary>
70  /// Start time for this market hour category
71  /// </summary>
72  [JsonProperty(PropertyName = "start")]
73  public DateTime Start { get; set; }
74 
75  /// <summary>
76  /// End time for this market hour category
77  /// </summary>
78  [JsonProperty(PropertyName = "end")]
79  public DateTime End { get; set; }
80 
81  /// <summary>
82  /// Market hours initializer given an hours since midnight measure for the market hours today
83  /// </summary>
84  /// <param name="referenceDate">Reference date used for as base date from the specified hour offsets</param>
85  /// <param name="defaultStart">Time in hours since midnight to start this open period.</param>
86  /// <param name="defaultEnd">Time in hours since midnight to end this open period.</param>
87  public MarketHours(DateTime referenceDate, double defaultStart, double defaultEnd)
88  {
89  Start = referenceDate.Date.AddHours(defaultStart);
90  End = referenceDate.Date.AddHours(defaultEnd);
91  if (defaultEnd == 24)
92  {
93  // when we mark it as the end of the day other code that relies on .TimeOfDay has issues
94  End = End.AddTicks(-1);
95  }
96  }
97  }
98 }