/* * 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. */ using System; using QuantConnect.Orders; using QuantConnect.Interfaces; namespace QuantConnect.Commands { /// /// Represents a command to submit an order to the algorithm /// public class OrderCommand : BaseCommand { /// /// Gets or sets the symbol to be ordered /// public Symbol Symbol { get; set; } /// /// Gets or sets the order type to be submted /// public OrderType OrderType { get; set; } /// /// Gets or sets the number of units to be ordered (directional) /// public decimal Quantity { get; set; } /// /// Gets or sets the limit price. Only applies to and /// public decimal LimitPrice { get; set; } /// /// Gets or sets the stop price. Only applies to and /// public decimal StopPrice { get; set; } /// /// Gets or sets an arbitrary tag to be attached to the order /// public string Tag { get; set; } /// /// Runs this command against the specified algorithm instance /// /// The algorithm to run this command against public override CommandResultPacket Run(IAlgorithm algorithm) { var request = new SubmitOrderRequest(OrderType, Symbol.SecurityType, Symbol, Quantity, StopPrice, LimitPrice, DateTime.UtcNow, Tag); var ticket = algorithm.Transactions.ProcessRequest(request); var response = ticket.GetMostRecentOrderResponse(); var message = $"{OrderType} for {Quantity} units of {Symbol}: {response}"; if (response.IsSuccess) { algorithm.Debug(message); } else { algorithm.Error(message); } return new CommandResultPacket(this, response.IsSuccess); } /// /// Returns a string that represents the current object. /// /// /// A string that represents the current object. /// /// 2 public override string ToString() { // delegate to the order request return new SubmitOrderRequest(OrderType, Symbol.SecurityType, Symbol, Quantity, StopPrice, LimitPrice, DateTime.UtcNow, Tag).ToString(); } } }