/* * 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 QuantConnect.Interfaces; using QuantConnect.Securities; namespace QuantConnect.Commands { /// /// Represents a command to add a security to the algorithm /// public class AddSecurityCommand : BaseCommand { /// /// The security type of the security /// public SecurityType SecurityType { get; set; } /// /// The security's ticker symbol /// public string Symbol { get; set; } /// /// The requested resolution, defaults to Resolution.Minute /// public Resolution Resolution { get; set; } /// /// The security's market, defaults to except for Forex, defaults to /// public string Market { get; set; } /// /// The fill forward behavior, true to fill forward, false otherwise - defaults to true /// public bool FillDataForward { get; set; } /// /// The leverage for the security, defaults to 2 for equity, 50 for forex, and 1 for everything else /// public decimal Leverage { get; set; } /// /// The extended market hours flag, true to allow pre/post market data, false for only in market data /// public bool ExtendedMarketHours { get; set; } /// /// Default construct that applies default values /// public AddSecurityCommand() { Resolution = Resolution.Minute; Market = null; FillDataForward = true; Leverage = Security.NullLeverage; ExtendedMarketHours = false; } /// /// Runs this command against the specified algorithm instance /// /// The algorithm to run this command against public override CommandResultPacket Run(IAlgorithm algorithm) { var security = algorithm.AddSecurity(SecurityType, Symbol, Resolution, Market, FillDataForward, Leverage, ExtendedMarketHours); return new Result(this, true, security.Symbol); } /// /// Result packet type for the command /// public class Result : CommandResultPacket { /// /// The symbol result from the add security command /// public Symbol Symbol { get; set; } /// /// Initializes a new instance of the class /// public Result(AddSecurityCommand command, bool success, Symbol symbol) : base(command, success) { Symbol = symbol; } } } }