Lean  $LEAN_TAG$
Cfd.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 using System;
17 using QuantConnect.Data;
21 
23 {
24  /// <summary>
25  /// CFD Security Object Implementation for CFD Assets
26  /// </summary>
27  /// <seealso cref="Security"/>
28  public class Cfd : Security
29  {
30  /// <summary>
31  /// Constructor for the CFD security
32  /// </summary>
33  /// <param name="exchangeHours">Defines the hours this exchange is open</param>
34  /// <param name="quoteCurrency">The cash object that represent the quote currency</param>
35  /// <param name="config">The subscription configuration for this security</param>
36  /// <param name="symbolProperties">The symbol properties for this security</param>
37  /// <param name="currencyConverter">Currency converter used to convert <see cref="CashAmount"/>
38  /// instances into units of the account currency</param>
39  /// <param name="registeredTypes">Provides all data types registered in the algorithm</param>
40  public Cfd(SecurityExchangeHours exchangeHours,
41  Cash quoteCurrency,
43  SymbolProperties symbolProperties,
44  ICurrencyConverter currencyConverter,
46  : base(config,
47  quoteCurrency,
48  symbolProperties,
49  new CfdExchange(exchangeHours),
50  new CfdCache(),
52  new ImmediateFillModel(),
53  new ConstantFeeModel(0),
54  NullSlippageModel.Instance,
56  Securities.VolatilityModel.Null,
57  new SecurityMarginModel(50m),
58  new CfdDataFilter(),
60  currencyConverter,
61  registeredTypes,
62  Securities.MarginInterestRateModel.Null
63  )
64  {
65  Holdings = new CfdHolding(this, currencyConverter);
66  }
67 
68  /// <summary>
69  /// Constructor for the CFD security
70  /// </summary>
71  /// <param name="symbol">The security's symbol</param>
72  /// <param name="exchangeHours">Defines the hours this exchange is open</param>
73  /// <param name="quoteCurrency">The cash object that represent the quote currency</param>
74  /// <param name="symbolProperties">The symbol properties for this security</param>
75  /// <param name="currencyConverter">Currency converter used to convert <see cref="CashAmount"/>
76  /// instances into units of the account currency</param>
77  /// <param name="registeredTypes">Provides all data types registered in the algorithm</param>
78  /// <param name="securityCache">Cache for storing Security data</param>
79  public Cfd(Symbol symbol,
80  SecurityExchangeHours exchangeHours,
81  Cash quoteCurrency,
82  SymbolProperties symbolProperties,
83  ICurrencyConverter currencyConverter,
85  SecurityCache securityCache)
86  : base(symbol,
87  quoteCurrency,
88  symbolProperties,
89  new CfdExchange(exchangeHours),
90  securityCache,
92  new ImmediateFillModel(),
93  new ConstantFeeModel(0),
94  NullSlippageModel.Instance,
96  Securities.VolatilityModel.Null,
97  new SecurityMarginModel(50m),
98  new CfdDataFilter(),
100  currencyConverter,
101  registeredTypes,
102  Securities.MarginInterestRateModel.Null
103  )
104  {
105  Holdings = new CfdHolding(this, currencyConverter);
106  }
107 
108  /// <summary>
109  /// Gets the contract multiplier for this CFD security
110  /// </summary>
111  public decimal ContractMultiplier
112  {
113  get { return SymbolProperties.ContractMultiplier; }
114  }
115 
116  /// <summary>
117  /// Gets the minimum price variation for this CFD security
118  /// </summary>
119  public decimal MinimumPriceVariation
120  {
122  }
123 
124  /// <summary>
125  /// Decomposes the specified currency pair into a base and quote currency provided as out parameters
126  /// </summary>
127  /// <param name="symbol">The input symbol to be decomposed</param>
128  /// <param name="symbolProperties">The symbol properties for this security</param>
129  /// <param name="baseCurrency">The output base currency</param>
130  /// <param name="quoteCurrency">The output quote currency</param>
131  public static void DecomposeCurrencyPair(Symbol symbol, SymbolProperties symbolProperties, out string baseCurrency, out string quoteCurrency)
132  {
133  quoteCurrency = symbolProperties.QuoteCurrency;
134  if (symbol.Value.EndsWith(quoteCurrency))
135  {
136  baseCurrency = symbol.Value.RemoveFromEnd(quoteCurrency);
137  }
138  else
139  {
140  throw new InvalidOperationException($"Symbol doesn't end with {quoteCurrency}");
141  }
142  }
143  }
144 }