/// <summary> /// Gets a cryptocurrency by its name and its network. /// If it is not supported by the platform, it will return null /// </summary> /// <param name="crypto"></param> /// <param name="network"></param> /// <returns></returns> public static Crypto GetBySymbolAndNetwork(CryptoCurrencies crypto, CryptoNetworks network = CryptoNetworks.Standard) { switch (crypto) { case CryptoCurrencies.BTC: return(new Crypto(crypto, network, Crypto.BTC.Precision)); case CryptoCurrencies.ETH: return(new Crypto(crypto, network, Crypto.ETH.Precision)); case CryptoCurrencies.LTC: return(new Crypto(crypto, network, Crypto.LTC.Precision)); case CryptoCurrencies.USDT: return(new Crypto(crypto, network, Crypto.USDT.Precision)); case CryptoCurrencies.XMR: return(new Crypto(crypto, network, Crypto.XMR.Precision)); case CryptoCurrencies.XRP: return(new Crypto(crypto, network, Crypto.XRP.Precision)); case CryptoCurrencies.PGD: return(new Crypto(crypto, network, Crypto.PGD.Precision)); } return(null); }
//decimal _div = 100; //public override ushort Precision { get => 2; set { } } public CryptoUSDT(CryptoNetworks network) : base(CryptoCurrencies.USDT, network, 2, 1) { if (network != CryptoNetworks.ERC20 && network != CryptoNetworks.Standard && network != CryptoNetworks.TRC20) { throw new Exception($"{network} is not supported for USDT"); } this.network = network; }
public Crypto(CryptoCurrencies crypto, CryptoNetworks network, ushort precision, decimal howManyForOneUSD = decimal.MinValue) : base(howManyForOneUSD) { base.CurrencyId = (Currencies)crypto; this.CryptoCurrencyId = crypto; this.Network = network; this.Precision = precision; }
/// <summary> /// Gets a cryptocurrency by its name. /// </summary> /// <param name="cryptoAndNetwork">The name of the crypto, any of <see cref="CryptoCurrencies"/>. /// Or the name of the crypto and the name of the network separated by an <seealso cref="CRYPTO_NETWORK_SEPARATOR"/>, example: USDT_ERC20 </param> /// <returns>If the network is specified but it is not found, null is returned</returns> public static Crypto GetBySymbolAndNetwork(string cryptoAndNetwork) { if (string.IsNullOrEmpty(cryptoAndNetwork)) { return(null); } var values = cryptoAndNetwork.Split(new char[] { CRYPTO_NETWORK_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries); if (values.Length == 0) { return(null); // should not happen } string crypto = values[0]; if (Enum.TryParse <CryptoCurrencies>(crypto, true, out CryptoCurrencies ccrypto) == false || !Enum.IsDefined(typeof(CryptoCurrencies), ccrypto)) { return(null); } CryptoNetworks cnetwork = CryptoNetworks.Standard; string network = null; if (values.Length > 1) { network = values[1]; } if (network != null && Enum.TryParse <CryptoNetworks>(network, true, out CryptoNetworks newnet)) { cnetwork = newnet; } else if (network != null) { return(null); } return(GetBySymbolAndNetwork(ccrypto, cnetwork)); }