/* * 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; namespace QuantConnect.Securities { /// /// Represents common properties for a specific security, uniquely identified by market, symbol and security type /// public class SymbolProperties { /// /// DTO used to hold the properties of the symbol /// /// /// A DTO is used to handle updates to the symbol properties. Since some properties are decimals, /// which is not thread-safe, we get around it by creating a new instance of the DTO and assigning to this property /// private SymbolPropertiesHolder _properties; /// /// The description of the security /// public string Description => _properties.Description; /// /// The quote currency of the security /// public string QuoteCurrency => _properties.QuoteCurrency; /// /// The contract multiplier for the security /// public virtual decimal ContractMultiplier { get => _properties.ContractMultiplier; internal set => _properties.ContractMultiplier = value; } /// /// The minimum price variation (tick size) for the security /// public virtual decimal MinimumPriceVariation => _properties.MinimumPriceVariation; /// /// The lot size (lot size of the order) for the security /// public decimal LotSize => _properties.LotSize; /// /// The market ticker /// public string MarketTicker => _properties.MarketTicker; /// /// The minimum order size allowed /// For crypto/forex pairs it's expected to be expressed in base or quote currency /// i.e For BTC/USD the minimum order size allowed with Coinbase is 0.0001 BTC /// while on Binance the minimum order size allowed is 10 USD /// public decimal? MinimumOrderSize => _properties.MinimumOrderSize; /// /// Allows normalizing live asset prices to US Dollars for Lean consumption. In some exchanges, /// for some securities, data is expressed in cents like for example for corn futures ('ZC'). /// /// Default value is 1 but for some futures in cents it's 100 public decimal PriceMagnifier => _properties.PriceMagnifier; /// /// Scale factor for option's strike price. For some options, such as NQX, the strike price /// is based on a fraction of the underlying, thus this paramater scales the strike price so /// that it can be used in comparation with the underlying such as /// in /// public decimal StrikeMultiplier => _properties.StrikeMultiplier; /// /// Creates an instance of the class /// protected SymbolProperties(SymbolProperties properties) { _properties = properties._properties; } /// /// Creates an instance of the class /// public SymbolProperties(string description, string quoteCurrency, decimal contractMultiplier, decimal minimumPriceVariation, decimal lotSize, string marketTicker, decimal? minimumOrderSize = null, decimal priceMagnifier = 1, decimal strikeMultiplier = 1) { _properties = new SymbolPropertiesHolder(description, quoteCurrency, contractMultiplier, minimumPriceVariation, lotSize, marketTicker, minimumOrderSize, priceMagnifier, strikeMultiplier); } /// /// The string representation of these symbol properties /// public override string ToString() { return Messages.SymbolProperties.ToString(this); } /// /// Gets a default instance of the class for the specified /// /// The quote currency of the symbol /// A default instance of the class public static SymbolProperties GetDefault(string quoteCurrency) { return new SymbolProperties(string.Empty, quoteCurrency.LazyToUpper(), 1, 0.01m, 1, string.Empty); } /// /// Updates the symbol properties with the values from the specified /// /// The symbol properties to take values from internal virtual void Update(SymbolProperties other) { _properties = other._properties; } /// /// DTO used to hold the properties of the symbol /// private class SymbolPropertiesHolder { public string Description { get; } public string QuoteCurrency { get; } public decimal ContractMultiplier { get; set; } public decimal MinimumPriceVariation { get; } public decimal LotSize { get; } public string MarketTicker { get; } public decimal? MinimumOrderSize { get; } public decimal PriceMagnifier { get; } public decimal StrikeMultiplier { get; } /// /// Creates an instance of the class /// public SymbolPropertiesHolder(string description, string quoteCurrency, decimal contractMultiplier, decimal minimumPriceVariation, decimal lotSize, string marketTicker, decimal? minimumOrderSize, decimal priceMagnifier, decimal strikeMultiplier) { Description = description; QuoteCurrency = quoteCurrency; ContractMultiplier = contractMultiplier; MinimumPriceVariation = minimumPriceVariation; LotSize = lotSize; if (LotSize <= 0) { throw new ArgumentException(Messages.SymbolProperties.InvalidLotSize); } MarketTicker = marketTicker; MinimumOrderSize = minimumOrderSize; PriceMagnifier = priceMagnifier; if (PriceMagnifier <= 0) { throw new ArgumentException(Messages.SymbolProperties.InvalidPriceMagnifier); } StrikeMultiplier = strikeMultiplier; if (strikeMultiplier <= 0) { throw new ArgumentException(Messages.SymbolProperties.InvalidStrikeMultiplier); } } } } }