/*
* 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 string ticker symbol
///
public string Ticker { get; set; }
///
/// Gets or sets the security type of the ticker.
///
public SecurityType SecurityType { get; set; }
///
/// Gets or sets the market the ticker resides in
///
public string Market { 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)
{
Symbol = GetSymbol(Ticker, SecurityType, Market, Symbol);
var request = new SubmitOrderRequest(OrderType, Symbol.SecurityType, Symbol, Quantity, StopPrice, LimitPrice, DateTime.UtcNow, Tag);
var ticket = algorithm.SubmitOrderRequest(request);
var response = ticket.GetMostRecentOrderResponse();
var message = Messages.OrderCommand.CommandInfo(OrderType, Symbol, Quantity, response);
if (response.IsError)
{
algorithm.Error(message);
}
else
{
algorithm.Debug(message);
}
return new CommandResultPacket(this, success: !response.IsError);
}
///
/// Returns a string that represents the current object.
///
///
/// A string that represents the current object.
///
/// 2
public override string ToString()
{
Symbol = GetSymbol(Ticker, SecurityType, Market, Symbol);
// delegate to the order request
return new SubmitOrderRequest(OrderType, Symbol.SecurityType, Symbol, Quantity, StopPrice, LimitPrice, DateTime.UtcNow, Tag).ToString();
}
}
}