If you have ever built an application that handles multiple currencies, you have discovered that getting accurate, real-time exchange rates is surprisingly expensive. The major API providers charge $10-$100+ per month for what seems like simple data. But the free alternatives have tradeoffs you need to understand.
Where exchange rates come from
There is no single "exchange rate." Currencies trade on the foreign exchange market continuously, and the rate varies by:
- Dealer: Different banks and brokers offer different rates
- Amount: Large transactions get better rates (interbank rates)
- Time: Rates change constantly during trading hours
- Type: Spot rates, forward rates, and mid-market rates are all different
The "mid-market rate" you see on Google is the midpoint between buy and sell prices on the interbank market. This is the "true" rate, but no consumer or small business actually gets this rate. The rate you get from your bank or payment processor includes a markup of 1-4%.
API pricing and what you get
Premium APIs (Currencylayer, Open Exchange Rates, XE): $10-$100/month. Real-time or near-real-time rates, 160+ currencies, historical data, reliable uptime. Suitable for production financial applications.
Free tier APIs (ExchangeRate-API, Fixer.io free): Limited requests (100-1,500/month), daily rates instead of real-time, fewer currencies. Suitable for personal projects and low-traffic tools.
No-API approaches: Scraping Google Finance or the ECB (European Central Bank) XML feed. The ECB publishes daily reference rates for ~30 currencies for free with no API key. Reliable but limited to daily updates and major currencies.
Accuracy considerations
For most applications, daily rates are perfectly adequate. If you are building an e-commerce site that displays prices in local currency, a rate that is 12 hours old introduces negligible error. The markup your payment processor adds (2-3%) far exceeds the rate movement.
For financial applications where precision matters (treasury, trading, accounting), you need real-time rates from a premium source with documented data provenance.
The distinction matters for legal and accounting reasons. Some jurisdictions require specific rate sources for tax calculations and financial reporting. The IRS, for example, accepts the yearly average exchange rate from their own published tables, not whatever rate your app used at the time of the transaction.
Building a currency converter
The core logic is simple:
function convert(amount, fromRate, toRate) {
return amount * (toRate / fromRate);
}
// If 1 USD = 0.92 EUR and 1 USD = 149.50 JPY
// Convert 100 EUR to JPY:
// First to USD: 100 / 0.92 = 108.70 USD
// Then to JPY: 108.70 * 149.50 = 16,250.65 JPY
Most rate APIs provide rates relative to a base currency (usually USD). Converting between any two currencies requires dividing by the source rate and multiplying by the target rate.
Historical rates and the time dimension
Currency conversion often needs to be done at a historical rate. An invoice from January should use January's exchange rate, not today's. This requires access to historical rate data, which is where free APIs often fall short.
The tool
For quick currency conversions with current rates, I built a currency converter that supports major world currencies with daily-updated rates. It is designed for quick conversions and comparison, not production financial applications, but it handles the common case well.
I'm Michael Lip. I build free developer tools at zovo.one. 500+ tools, all private, all free.
Top comments (0)