using System;
using System.Linq;
namespace CryptoExchange.Net.Objects
{
///
/// Exchange configuration for asset aliases
///
public class AssetAliasConfiguration
{
///
/// Defined aliases
///
public AssetAlias[] Aliases { get; set; } = [];
///
/// Auto convert asset names when using the Shared interfaces. Defaults to true
///
public bool AutoConvertEnabled { get; set; } = true;
///
/// Map the common name to an exchange name for an asset. If there is no alias the input name is returned
///
public string CommonToExchangeName(string commonName) =>
!AutoConvertEnabled ? commonName : Aliases.FirstOrDefault(x => x.CommonAssetName.Equals(commonName, StringComparison.InvariantCulture))?.ExchangeAssetName ?? commonName;
///
/// Map the exchange name to a common name for an asset. If there is no alias the input name is returned
///
public string ExchangeToCommonName(string exchangeName)
{
if (!AutoConvertEnabled)
return exchangeName;
var alias = Aliases.FirstOrDefault(x => x.ExchangeAssetName.Equals(exchangeName, StringComparison.InvariantCulture));
if (alias == null || alias.Type == AliasType.OnlyToExchange)
return exchangeName;
return alias.CommonAssetName;
}
}
}