mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-11-05 04:48:34 +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>
|
/// </summary>
|
||||||
public class AssetAlias
|
public class AssetAlias
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Alias type
|
||||||
|
/// </summary>
|
||||||
|
public AliasType Type { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The name of the asset on the exchange
|
/// The name of the asset on the exchange
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -21,10 +25,26 @@ namespace CryptoExchange.Net.Objects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// ctor
|
/// ctor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AssetAlias(string exchangeName, string commonName)
|
public AssetAlias(string exchangeName, string commonName, AliasType type = AliasType.BothWays)
|
||||||
{
|
{
|
||||||
ExchangeAssetName = exchangeName;
|
ExchangeAssetName = exchangeName;
|
||||||
CommonAssetName = commonName;
|
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>
|
/// <summary>
|
||||||
/// Map the common name to an exchange name for an asset. If there is no alias the input name is returned
|
/// Map the common name to an exchange name for an asset. If there is no alias the input name is returned
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Map the exchange name to a common name for an asset. If there is no alias the input name is returned
|
/// Map the exchange name to a common name for an asset. If there is no alias the input name is returned
|
||||||
/// </summary>
|
/// </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