decimal ToBTC(decimal amount, string currency_code)
{
m_log.Info("[FreeMoney] Trying to convert "+amount.ToString()+" "+currency_code+" to Bitcoins.");
// If we have a hard-coded exchange rate, use that.
// If not, try to use a dynamic service
// TODO: With the dynamic service, cache the result.
decimal exchange_rate = Decimal.Parse(m_config["bitcoin_exchange_rate"]);
if (exchange_rate == 0m) {
m_log.Info("[FreeMoney] Looking up the exchange rate.");
BitcoinExchangeRateService serv = new BitcoinExchangeRateService(m_config);
exchange_rate = serv.LookupRate(currency_code);
}
decimal btc_amount = Decimal.Round( (amount / exchange_rate), 4);
m_log.Info("[FreeMoney] "+amount.ToString()+" "+currency_code+" equals "+btc_amount.ToString()+" Bitcoins.");
return btc_amount;
}