Lean  $LEAN_TAG$
HistoryPacket.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 System.Collections.Generic;
19 
20 namespace QuantConnect.Packets
21 {
22  /// <summary>
23  /// Packet for history jobs
24  /// </summary>
25  public class HistoryPacket : Packet
26  {
27  /// <summary>
28  /// The queue where the data should be sent
29  /// </summary>
30  public string QueueName;
31 
32  /// <summary>
33  /// The individual requests to be processed
34  /// </summary>
35  public List<HistoryRequest> Requests = new List<HistoryRequest>();
36 
37  /// <summary>
38  /// Initializes a new instance of the <see cref="HistoryPacket"/> class
39  /// </summary>
40  public HistoryPacket()
41  : base(PacketType.History)
42  {
43  }
44  }
45 
46  /// <summary>
47  /// Specifies request parameters for a single historical request.
48  /// A HistoryPacket is made of multiple requests for data. These
49  /// are used to request data during live mode from a data server
50  /// </summary>
51  public class HistoryRequest
52  {
53  /// <summary>
54  /// The start time to request data in UTC
55  /// </summary>
56  public DateTime StartTimeUtc;
57 
58  /// <summary>
59  /// The end time to request data in UTC
60  /// </summary>
61  public DateTime EndTimeUtc;
62 
63  /// <summary>
64  /// The symbol to request data for
65  /// </summary>
66  public Symbol Symbol;
67 
68  /// <summary>
69  /// The requested resolution
70  /// </summary>
72 
73  /// <summary>
74  /// The type of data to retrieve
75  /// </summary>
77  }
78 
79  /// <summary>
80  /// Specifies various types of history results
81  /// </summary>
82  public enum HistoryResultType
83  {
84  /// <summary>
85  /// The requested file data
86  /// </summary>
87  File,
88 
89  /// <summary>
90  /// The request's status
91  /// </summary>
92  Status,
93 
94  /// <summary>
95  /// The request is completed
96  /// </summary>
97  Completed,
98 
99  /// <summary>
100  /// The request had an error
101  /// </summary>
102  Error
103  }
104 
105  /// <summary>
106  /// Provides a container for results from history requests. This contains
107  /// the file path relative to the /Data folder where the data can be written
108  /// </summary>
109  public abstract class HistoryResult
110  {
111  /// <summary>
112  /// Gets the type of history result
113  /// </summary>
114  public HistoryResultType Type { get; private set; }
115 
116  /// <summary>
117  /// Initializes a new instance of the <see cref="HistoryResult"/> class
118  /// </summary>
119  /// <param name="type">The type of history result</param>
121  {
122  Type = type;
123  }
124  }
125 
126  /// <summary>
127  /// Defines requested file data for a history request
128  /// </summary>
130  {
131  /// <summary>
132  /// The relative file path where the data should be written
133  /// </summary>
134  public string Filepath;
135 
136  /// <summary>
137  /// The file's contents, this is a zipped csv file
138  /// </summary>
139  public byte[] File;
140 
141  /// <summary>
142  /// Default constructor for serializers
143  /// </summary>
145  : base(HistoryResultType.File)
146  {
147  }
148 
149  /// <summary>
150  /// Initializes a new instance of the <see cref="HistoryResult"/> class
151  /// </summary>
152  /// <param name="filepath">The relative file path where the file should be written, rooted in /Data, so for example ./forex/fxcm/daily/eurusd.zip</param>
153  /// <param name="file">The zipped csv file content in bytes</param>
154  public FileHistoryResult(string filepath, byte[] file)
155  : this()
156  {
157  Filepath = filepath;
158  File = file;
159  }
160  }
161 
162  /// <summary>
163  /// Specifies the completed message from a history result
164  /// </summary>
166  {
167  /// <summary>
168  /// Initializes a new instance of <see cref="CompletedHistoryResult"/> class
169  /// </summary>
172  {
173  }
174  }
175 
176  /// <summary>
177  /// Specfies an error message in a history result
178  /// </summary>
180  {
181  /// <summary>
182  /// Gets the error that was encountered
183  /// </summary>
184  public string Message;
185 
186  /// <summary>
187  /// Default constructor for serializers
188  /// </summary>
190  : base(HistoryResultType.Error)
191  {
192  }
193 
194  /// <summary>
195  /// Initializes a new instance of the <see cref="ErrorHistoryResult"/> class
196  /// </summary>
197  /// <param name="message">The error message</param>
198  public ErrorHistoryResult(string message)
199  : this()
200  {
201  Message = message;
202  }
203  }
204 
205  /// <summary>
206  /// Specifies the progress of a request
207  /// </summary>
209  {
210  /// <summary>
211  /// Gets the progress of the request
212  /// </summary>
213  public int Progress;
214 
215  /// <summary>
216  /// Default constructor for serializers
217  /// </summary>
219  : base(HistoryResultType.Status)
220  {
221  }
222 
223  /// <summary>
224  /// Initializes a new instance of the <see cref="StatusHistoryResult"/> class
225  /// </summary>
226  /// <param name="progress">The progress, from 0 to 100</param>
227  public StatusHistoryResult(int progress)
228  : this()
229  {
230  Progress = progress;
231  }
232  }
233 }