/* * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace QuantConnect.Orders { /// /// Represents a response to an . See property for /// a specific request's response value /// public class OrderResponse { /// /// Gets the order id /// public int OrderId { get; private set; } /// /// Gets the error message if the does not equal , otherwise /// gets /// public string ErrorMessage { get; private set; } /// /// Gets the error code for this response. /// public OrderResponseErrorCode ErrorCode { get; private set; } /// /// Gets true if this response represents a successful request, false otherwise /// If this is an unprocessed response, IsSuccess will return false. /// public bool IsSuccess { get { return IsProcessed && !IsError; } } /// /// Gets true if this response represents an error, false otherwise /// public bool IsError { get { return IsProcessed && ErrorCode != OrderResponseErrorCode.None; } } /// /// Gets true if this response has been processed, false otherwise /// public bool IsProcessed { get { return this != Unprocessed; } } /// /// Initializes a new instance of the class /// /// The order id /// The error code of the response, specify for no error /// The error message, applies only if the does not equal private OrderResponse(int orderId, OrderResponseErrorCode errorCode, string errorMessage) { OrderId = orderId; ErrorCode = errorCode; if (errorCode != OrderResponseErrorCode.None) { ErrorMessage = errorMessage ?? Messages.OrderResponse.DefaultErrorMessage; } } /// /// Returns a string that represents the current object. /// /// /// A string that represents the current object. /// /// 2 public override string ToString() { return Messages.OrderResponse.ToString(this); } #region Statics - implicit(int), Unprocessed constant, response factory methods /// /// Gets an for a request that has not yet been processed /// public static readonly OrderResponse Unprocessed = new OrderResponse(int.MinValue, OrderResponseErrorCode.None, Messages.OrderResponse.UnprocessedOrderResponseErrorMessage); /// /// Helper method to create a successful response from a request /// public static OrderResponse Success(OrderRequest request) { return new OrderResponse(request.OrderId, OrderResponseErrorCode.None, null); } /// /// Helper method to create an error response from a request /// public static OrderResponse Error(OrderRequest request, OrderResponseErrorCode errorCode, string errorMessage) { return new OrderResponse(request.OrderId, errorCode, errorMessage); } /// /// Helper method to create an error response due to an invalid order status /// public static OrderResponse InvalidStatus(OrderRequest request, Order order) { return Error(request, OrderResponseErrorCode.InvalidOrderStatus, Messages.OrderResponse.InvalidStatus(request, order)); } /// /// Helper method to create an error response due to the "New" order status /// public static OrderResponse InvalidNewStatus(OrderRequest request, Order order) { return Error(request, OrderResponseErrorCode.InvalidNewOrderStatus, Messages.OrderResponse.InvalidNewStatus(request, order)); } /// /// Helper method to create an error response due to a bad order id /// public static OrderResponse UnableToFindOrder(OrderRequest request) { return Error(request, OrderResponseErrorCode.UnableToFindOrder, Messages.OrderResponse.UnableToFindOrder(request)); } /// /// Helper method to create an error response due to a zero order quantity /// public static OrderResponse ZeroQuantity(OrderRequest request) { return Error(request, OrderResponseErrorCode.OrderQuantityZero, Messages.OrderResponse.ZeroQuantity(request)); } /// /// Helper method to create an error response due to a missing security /// public static OrderResponse MissingSecurity(SubmitOrderRequest request) { return Error(request, OrderResponseErrorCode.MissingSecurity, Messages.OrderResponse.MissingSecurity(request)); } /// /// Helper method to create an error response due to algorithm still in warmup mode /// public static OrderResponse WarmingUp(OrderRequest request) { return Error(request, OrderResponseErrorCode.AlgorithmWarmingUp, Messages.OrderResponse.WarmingUp(request)); } #endregion } }