mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-11-04 12:28:06 +00:00
Added AliasType to specify only one way conversion for AssetAliases
This commit is contained in:
parent
3960cab7a7
commit
c1b2b62dbc
@ -9,6 +9,10 @@ namespace CryptoExchange.Net.Objects
|
||||
/// </summary>
|
||||
public class AssetAlias
|
||||
{
|
||||
/// <summary>
|
||||
/// Alias type
|
||||
/// </summary>
|
||||
public AliasType Type { get; set; }
|
||||
/// <summary>
|
||||
/// The name of the asset on the exchange
|
||||
/// </summary>
|
||||
@ -21,10 +25,26 @@ namespace CryptoExchange.Net.Objects
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public AssetAlias(string exchangeName, string commonName)
|
||||
public AssetAlias(string exchangeName, string commonName, AliasType type = AliasType.BothWays)
|
||||
{
|
||||
ExchangeAssetName = exchangeName;
|
||||
CommonAssetName = commonName;
|
||||
Type = type;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Alias type
|
||||
/// </summary>
|
||||
public enum AliasType
|
||||
{
|
||||
/// <summary>
|
||||
/// Translate both from and to exchange
|
||||
/// </summary>
|
||||
BothWays,
|
||||
/// <summary>
|
||||
/// Only translate when converting to exchange
|
||||
/// </summary>
|
||||
OnlyToExchange
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,12 +23,22 @@ namespace CryptoExchange.Net.Objects
|
||||
/// <summary>
|
||||
/// Map the common name to an exchange name for an asset. If there is no alias the input name is returned
|
||||
/// </summary>
|
||||
public string CommonToExchangeName(string commonName) => !AutoConvertEnabled ? commonName : Aliases.SingleOrDefault(x => x.CommonAssetName == commonName)?.ExchangeAssetName ?? commonName;
|
||||
public string CommonToExchangeName(string commonName) => !AutoConvertEnabled ? commonName : Aliases.FirstOrDefault(x => x.CommonAssetName == commonName)?.ExchangeAssetName ?? commonName;
|
||||
|
||||
/// <summary>
|
||||
/// Map the exchange name to a common name for an asset. If there is no alias the input name is returned
|
||||
/// </summary>
|
||||
public string ExchangeToCommonName(string exchangeName) => !AutoConvertEnabled ? exchangeName : Aliases.SingleOrDefault(x => x.ExchangeAssetName == exchangeName)?.CommonAssetName ?? exchangeName;
|
||||
public string ExchangeToCommonName(string exchangeName)
|
||||
{
|
||||
if (!AutoConvertEnabled)
|
||||
return exchangeName;
|
||||
|
||||
var alias = Aliases.FirstOrDefault(x => x.ExchangeAssetName == exchangeName);
|
||||
if (alias == null || alias.Type == AliasType.OnlyToExchange)
|
||||
return exchangeName;
|
||||
|
||||
return alias.CommonAssetName;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user