public static Money GetCurrentExchangeRate(string exchangeCodeId, string currencyCode) { //Usually we takie it right from the API //However it differs for ERC20 Token Because we don't have its value in the API #region Token value if (exchangeCodeId == "ERC20Token") { if (AppSettings.Site.CurrencyIsTokenCryptocurrency) { return(new Money(1)); } else { return(AppSettings.Ethereum.ERC20TokenRate); } } //We have token cryptocurrency as our main website currency and we want to fetch other official cryptocurrency value //We need to get token value to BTC/USD/whatever and then lookup the value in the API if (currencyCode == AppSettings.Site.CurrencyCode && AppSettings.Site.CurrencyIsTokenCryptocurrency) { if (AppSettings.Payments.TokenCryptocurrencyValueType == TokenCryptocurrencyValue.Static) { if (AppSettings.Ethereum.ERC20TokenRate.IsZero) { return(Money.Zero); } //We have static value in USD (1 TOKEN = X USD) Money OneCryptoInUSD = CoinmarketcapHelper.GetCurrentExchangeRateFromAPI(exchangeCodeId, "USD"); return(new Money(OneCryptoInUSD.ToDecimal() / AppSettings.Ethereum.ERC20TokenRate.ToDecimal())); } else if (AppSettings.Payments.TokenCryptocurrencyValueType == TokenCryptocurrencyValue.DynamicFromInternalExchange) { //We take value from Internal Exchange decimal OneStockValue = InternalExchangeTransaction.GetLastStockValue(); if ((AppSettings.InternalExchange.InternalExchangeStockType == BalanceType.MainBalance || AppSettings.InternalExchange.InternalExchangeStockType == BalanceType.CashBalance) && AppSettings.InternalExchange.InternalExchangePurchaseVia == BalanceType.BTC) { if (OneStockValue == 0) { return(Money.Zero); } //Stock = our token currency //Purchase via BTC Money OneCryptoInBTC = CoinmarketcapHelper.GetCurrentExchangeRateFromAPI(exchangeCodeId, "BTC"); return(new Money(OneCryptoInBTC.ToDecimal() / OneStockValue)); } } return(new Money(1)); } #endregion return(GetCurrentExchangeRateFromAPI(exchangeCodeId, currencyCode)); }
private void UpdateStatisticsData() { Regex rgx = new Regex("[0-9]+([.,][0-9]+)?"); var test = rgx.Match(Last24LowValue.Text).NextMatch(); //LAST STOCK VALUE tmpLastStockValue = InternalExchangeTransaction.GetLastStockValue(FirstIncome); if (FirstIncome) { tmpCurrentStockValue = InternalExchangeTransaction.GetLastStockValue(!FirstIncome); } else { tmpCurrentStockValue = rgx.IsMatch(LastStockValue.Text) ? Decimal.Parse(rgx.Match(LastStockValue.Text).Value) : 0.0m; } //LAST ASK VALUE tmpLastAskValue = InternalExchangeTransaction.GetLastAskValue(FirstIncome); if (FirstIncome) { tmpCurrentLastAskValue = InternalExchangeTransaction.GetLastAskValue(!FirstIncome); } else { tmpCurrentLastAskValue = rgx.IsMatch(LastAskValue.Text) ? Decimal.Parse(rgx.Match(LastAskValue.Text).Value) : 0.0m; } //LAST BID VALUE tmpLastBidValue = InternalExchangeTransaction.GetLastBidValue(FirstIncome); if (FirstIncome) { tmpCurrentLastBidValue = InternalExchangeTransaction.GetLastBidValue(!FirstIncome); } else { tmpCurrentLastBidValue = rgx.IsMatch(LastBidValue.Text) ? Decimal.Parse(rgx.Match(LastBidValue.Text).Value) : 0.0m; } //LAST 24H HIGH tmpLast24HighValue = InternalExchangeTransaction.GetLast24hHigh(FirstIncome); if (FirstIncome) { tmpCurrentLast24HighValue = InternalExchangeTransaction.GetLast24hHigh(!FirstIncome); } else { tmpCurrentLast24HighValue = rgx.IsMatch(Last24HighValue.Text) ? Decimal.Parse(rgx.Match(Last24HighValue.Text).NextMatch().Value) : 0.0m; } //LAST 24H LOW tmpLast24LowValue = InternalExchangeTransaction.GetLast24hLow(FirstIncome); if (FirstIncome) { tmpCurrentLast24LowValue = InternalExchangeTransaction.GetLast24hLow(!FirstIncome); } else { tmpCurrentLast24LowValue = rgx.IsMatch(Last24LowValue.Text) ? Decimal.Parse(rgx.Match(Last24LowValue.Text).NextMatch().Value) : 0.0m; } //LAST 24H VOLUME tmpLast24Volume = InternalExchangeTransaction.GetLast24hVolume(FirstIncome); if (FirstIncome) { tmpCurrentLast24Volume = InternalExchangeTransaction.GetLast24hVolume(!FirstIncome); } else { tmpCurrentLast24Volume = rgx.IsMatch(Last24Volume.Text) ? Decimal.Parse(rgx.Match(Last24Volume.Text).NextMatch().Value) : 0.0m; } FirstIncome = false; }