예제 #1
0
        public Price(decimal amount, string currency)
        {
            if (currency != "BTC" && !BitcoinPriceData.GetAllCodes().Any(s => s.ToUpper() == currency.ToUpper()))
            {
                throw new Exception("Unsupported currency");
            }


            PegCurrency = currency.ToUpper();
            Value       = amount;

            if (PegCurrency == "BTC")
            {
                BTC = amount;
                USD = BitcoinPriceData.ToFiat(amount, "USD");
            }
            else if (PegCurrency == "USD")
            {
                BTC = BitcoinPriceData.ToBTC(amount, "USD");
                USD = amount;
            }
            else
            {
                BTC = BitcoinPriceData.ToBTC(amount, PegCurrency);
                USD = BitcoinPriceData.ToFiat(BTC, "USD");
            }
        }
예제 #2
0
        public decimal ToCurrency(string currency)
        {
            if (currency != "BTC" && !BitcoinPriceData.GetAllCodes().Any(s => s.ToUpper() == currency.ToUpper()))
            {
                throw new Exception("Unsupported currency");
            }

            if (currency == PegCurrency)
            {
                return(Value);
            }
            else if (currency == "BTC")
            {
                return(BTC);
            }
            else if (currency == "USD")
            {
                return(USD);
            }
            else
            {
                return(BitcoinPriceData.ToFiat(BTC, currency));
            }
        }