Skip to content

Commit f202871

Browse files
committed
Add ContractMultiplier setter to Cfd via CfdSymbolProperties
1 parent cefa634 commit f202871

3 files changed

Lines changed: 76 additions & 7 deletions

File tree

Common/Securities/Cfd/Cfd.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public Cfd(SecurityExchangeHours exchangeHours,
6262
Securities.MarginInterestRateModel.Null
6363
)
6464
{
65+
_symbolProperties = new CfdSymbolProperties(symbolProperties);
66+
SymbolProperties = _symbolProperties;
6567
Holdings = new CfdHolding(this, currencyConverter);
6668
}
6769

@@ -102,15 +104,20 @@ public Cfd(Symbol symbol,
102104
Securities.MarginInterestRateModel.Null
103105
)
104106
{
107+
_symbolProperties = new CfdSymbolProperties(symbolProperties);
108+
SymbolProperties = _symbolProperties;
105109
Holdings = new CfdHolding(this, currencyConverter);
106110
}
107111

112+
private readonly CfdSymbolProperties _symbolProperties;
113+
108114
/// <summary>
109-
/// Gets the contract multiplier for this CFD security
115+
/// Gets or sets the contract multiplier for this CFD security
110116
/// </summary>
111117
public decimal ContractMultiplier
112118
{
113-
get { return SymbolProperties.ContractMultiplier; }
119+
get { return _symbolProperties.ContractMultiplier; }
120+
set { _symbolProperties.SetContractMultiplier(value); }
114121
}
115122

116123
/// <summary>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
namespace QuantConnect.Securities.Cfd
17+
{
18+
/// <summary>
19+
/// Represents common properties for a specific CFD contract
20+
/// </summary>
21+
public class CfdSymbolProperties : SymbolProperties
22+
{
23+
/// <summary>
24+
/// The contract multiplier for the security.
25+
/// </summary>
26+
/// <remarks>
27+
/// If manually set by a consumer, this value will be used instead of the
28+
/// <see cref="SymbolProperties.ContractMultiplier"/> and also allows to make
29+
/// sure it is not overridden when the symbol properties database gets updated.
30+
/// </remarks>
31+
private decimal? _contractMultiplier;
32+
33+
/// <summary>
34+
/// The contract multiplier for the security
35+
/// </summary>
36+
public override decimal ContractMultiplier => _contractMultiplier ?? base.ContractMultiplier;
37+
38+
/// <summary>
39+
/// Creates an instance of the <see cref="CfdSymbolProperties"/> class from <see cref="SymbolProperties"/>
40+
/// </summary>
41+
public CfdSymbolProperties(SymbolProperties properties)
42+
: base(properties)
43+
{
44+
}
45+
46+
internal void SetContractMultiplier(decimal multiplier)
47+
{
48+
_contractMultiplier = multiplier;
49+
}
50+
}
51+
}

Tests/Common/Securities/Cfd/CfdTests.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* limitations under the License.
1414
*/
1515

16-
using System;
1716
using NUnit.Framework;
1817
using QuantConnect.Data;
1918
using QuantConnect.Data.Market;
@@ -27,12 +26,24 @@ public class CfdTests
2726
[Test]
2827
public void ConstructorExtractsQuoteCurrency()
2928
{
30-
var symbol = Symbol.Create("DE30EUR", SecurityType.Cfd, Market.Oanda);
31-
var config = new SubscriptionDataConfig(typeof(TradeBar), symbol, Resolution.Minute, TimeZones.Utc, TimeZones.NewYork, true, true, true);
32-
var symbolProperties = new SymbolProperties("Dax German index", "EUR", 1, 1, 1, string.Empty);
33-
var cfd = new QuantConnect.Securities.Cfd.Cfd(SecurityExchangeHours.AlwaysOpen(config.DataTimeZone), new Cash("EUR", 0, 0), config, symbolProperties, ErrorCurrencyConverter.Instance, RegisteredSecurityDataTypesProvider.Null);
29+
var cfd = CreateCfd(contractMultiplier: 1m);
3430
Assert.AreEqual("EUR", cfd.QuoteCurrency.Symbol);
3531
}
3632

33+
[Test]
34+
public void ContractMultiplierCanBeSetByUser()
35+
{
36+
var cfd = CreateCfd(contractMultiplier: 1m);
37+
cfd.ContractMultiplier = 5m;
38+
Assert.AreEqual(5m, cfd.ContractMultiplier);
39+
}
40+
41+
private static QuantConnect.Securities.Cfd.Cfd CreateCfd(decimal contractMultiplier)
42+
{
43+
var symbol = Symbol.Create("DE30EUR", SecurityType.Cfd, Market.Oanda);
44+
var config = new SubscriptionDataConfig(typeof(TradeBar), symbol, Resolution.Minute, TimeZones.Utc, TimeZones.NewYork, true, true, true);
45+
var symbolProperties = new SymbolProperties("Dax German index", "EUR", contractMultiplier, 1, 1, string.Empty);
46+
return new QuantConnect.Securities.Cfd.Cfd(SecurityExchangeHours.AlwaysOpen(config.DataTimeZone), new Cash("EUR", 0, 0), config, symbolProperties, ErrorCurrencyConverter.Instance, RegisteredSecurityDataTypesProvider.Null);
47+
}
3748
}
3849
}

0 commit comments

Comments
 (0)