Lean  $LEAN_TAG$
OrderRequest.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 
18 namespace QuantConnect.Orders
19 {
20  /// <summary>
21  /// Represents a request to submit, update, or cancel an order
22  /// </summary>
23  public abstract class OrderRequest
24  {
25  /// <summary>
26  /// Gets the type of this order request
27  /// </summary>
28  public abstract OrderRequestType OrderRequestType
29  {
30  get;
31  }
32 
33  /// <summary>
34  /// Gets the status of this request
35  /// </summary>
37  {
38  get; private set;
39  }
40 
41  /// <summary>
42  /// Gets the UTC time the request was created
43  /// </summary>
44  public DateTime Time
45  {
46  get; private set;
47  }
48 
49  /// <summary>
50  /// Gets the order id the request acts on
51  /// </summary>
52  public int OrderId
53  {
54  get; protected set;
55  }
56 
57  /// <summary>
58  /// Gets a tag for this request
59  /// </summary>
60  public string Tag
61  {
62  get; private set;
63  }
64 
65  /// <summary>
66  /// Gets the response for this request. If this request was never processed then this
67  /// will equal <see cref="OrderResponse.Unprocessed"/>. This value is never equal to null.
68  /// </summary>
69  public OrderResponse Response
70  {
71  get; private set;
72  }
73 
74  /// <summary>
75  /// Initializes a new instance of the <see cref="OrderRequest"/> class
76  /// </summary>
77  /// <param name="time">The time this request was created</param>
78  /// <param name="orderId">The order id this request acts on, specify zero for <see cref="SubmitOrderRequest"/></param>
79  /// <param name="tag">A custom tag for the request</param>
80  protected OrderRequest(DateTime time, int orderId, string tag)
81  {
82  Time = time;
83  OrderId = orderId;
84  Tag = tag;
86  Status = OrderRequestStatus.Unprocessed;
87  }
88 
89  /// <summary>
90  /// Sets the <see cref="Response"/> for this request
91  /// </summary>
92  /// <param name="response">The response to this request</param>
93  /// <param name="status">The current status of this request</param>
95  {
96  if (response == null)
97  {
98  throw new ArgumentNullException(nameof(response), "Response can not be null");
99  }
100 
101  // if the response is an error, ignore the input status
102  Status = response.IsError ? OrderRequestStatus.Error : status;
103  Response = response;
104  }
105 
106  /// <summary>
107  /// Returns a string that represents the current object.
108  /// </summary>
109  /// <returns>
110  /// A string that represents the current object.
111  /// </returns>
112  /// <filterpriority>2</filterpriority>
113  public override string ToString()
114  {
115  return Messages.OrderRequest.ToString(this);
116  }
117  }
118 }