/* * 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.Data; using QuantConnect.Orders.Fees; using QuantConnect.Orders.Fills; using QuantConnect.Orders.Slippage; namespace QuantConnect.Securities.Cfd { /// /// CFD Security Object Implementation for CFD Assets /// /// public class Cfd : Security { /// /// Constructor for the CFD security /// /// Defines the hours this exchange is open /// The cash object that represent the quote currency /// The subscription configuration for this security /// The symbol properties for this security /// Currency converter used to convert /// instances into units of the account currency /// Provides all data types registered in the algorithm public Cfd(SecurityExchangeHours exchangeHours, Cash quoteCurrency, SubscriptionDataConfig config, SymbolProperties symbolProperties, ICurrencyConverter currencyConverter, IRegisteredSecurityDataTypesProvider registeredTypes) : base(config, quoteCurrency, symbolProperties, new CfdExchange(exchangeHours), new CfdCache(), new SecurityPortfolioModel(), new ImmediateFillModel(), new ConstantFeeModel(0), NullSlippageModel.Instance, new ImmediateSettlementModel(), Securities.VolatilityModel.Null, new SecurityMarginModel(50m), new CfdDataFilter(), new SecurityPriceVariationModel(), currencyConverter, registeredTypes, Securities.MarginInterestRateModel.Null ) { Holdings = new CfdHolding(this, currencyConverter); } /// /// Constructor for the CFD security /// /// The security's symbol /// Defines the hours this exchange is open /// The cash object that represent the quote currency /// The symbol properties for this security /// Currency converter used to convert /// instances into units of the account currency /// Provides all data types registered in the algorithm /// Cache for storing Security data public Cfd(Symbol symbol, SecurityExchangeHours exchangeHours, Cash quoteCurrency, SymbolProperties symbolProperties, ICurrencyConverter currencyConverter, IRegisteredSecurityDataTypesProvider registeredTypes, SecurityCache securityCache) : base(symbol, quoteCurrency, symbolProperties, new CfdExchange(exchangeHours), securityCache, new SecurityPortfolioModel(), new ImmediateFillModel(), new ConstantFeeModel(0), NullSlippageModel.Instance, new ImmediateSettlementModel(), Securities.VolatilityModel.Null, new SecurityMarginModel(50m), new CfdDataFilter(), new SecurityPriceVariationModel(), currencyConverter, registeredTypes, Securities.MarginInterestRateModel.Null ) { Holdings = new CfdHolding(this, currencyConverter); } /// /// Gets the contract multiplier for this CFD security /// public decimal ContractMultiplier { get { return SymbolProperties.ContractMultiplier; } } /// /// Gets the minimum price variation for this CFD security /// public decimal MinimumPriceVariation { get { return SymbolProperties.MinimumPriceVariation; } } /// /// Decomposes the specified currency pair into a base and quote currency provided as out parameters /// /// The input symbol to be decomposed /// The symbol properties for this security /// The output base currency /// The output quote currency public static void DecomposeCurrencyPair(Symbol symbol, SymbolProperties symbolProperties, out string baseCurrency, out string quoteCurrency) { quoteCurrency = symbolProperties.QuoteCurrency; if (symbol.Value.EndsWith(quoteCurrency)) { baseCurrency = symbol.Value.RemoveFromEnd(quoteCurrency); } else { throw new InvalidOperationException($"Symbol doesn't end with {quoteCurrency}"); } } } }