/*
* 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 System.Collections.Generic;
using System.Linq;
namespace QuantConnect.Securities.CurrencyConversion
{
///
/// Provides an implementation of with a fixed conversion rate
///
public class ConstantCurrencyConversion : ICurrencyConversion
{
private decimal _conversionRate;
///
/// Event fired when the conversion rate is updated
///
public event EventHandler ConversionRateUpdated;
///
/// The currency this conversion converts from
///
public string SourceCurrency { get; }
///
/// The currency this conversion converts to
///
public string DestinationCurrency { get; }
///
/// The current conversion rate
///
public decimal ConversionRate
{
get
{
return _conversionRate;
}
set
{
if (_conversionRate != value)
{
// only update if there was actually one
_conversionRate = value;
ConversionRateUpdated?.Invoke(this, value);
}
}
}
///
/// The securities which the conversion rate is based on
///
public IEnumerable ConversionRateSecurities => Enumerable.Empty();
///
/// Initializes a new instance of the class.
///
/// The currency this conversion converts from
/// The currency this conversion converts to
/// The conversion rate between the currencies
public ConstantCurrencyConversion(string sourceCurrency, string destinationCurrency, decimal conversionRate = 1m)
{
SourceCurrency = sourceCurrency;
DestinationCurrency = destinationCurrency;
ConversionRate = conversionRate;
}
///
/// Marks the conversion rate as potentially outdated, needing an update based on the latest data
///
/// This conversion is not based on securities, so we don't really need an update
public void Update()
{
}
///
/// Creates a new identity conversion, where the conversion rate is set to 1 and the source and destination currencies might the same
///
/// The currency this conversion converts from
/// The currency this conversion converts to. If null, the destination and source currencies are the same
/// The identity currency conversion
public static ConstantCurrencyConversion Identity(string sourceCurrency, string destinationCurrency = null)
{
return new ConstantCurrencyConversion(sourceCurrency, destinationCurrency ?? sourceCurrency);
}
///
/// Returns an instance of that represents a null conversion
///
public static ConstantCurrencyConversion Null(string sourceCurrency, string destinationCurrency)
{
return new ConstantCurrencyConversion(sourceCurrency, destinationCurrency, 0m);
}
}
}