It is difficult finding a real time Currency Conversion API for free,. in this post we will demo a FREE API. The Exchange rates API published by European Central Bank, is free and great for soft users. The catch is it only updates the rate once in a day.
Note: The API publishers request you to please cache results whenever possible this will allow us to keep the service without any rate limits or api key requirements.
The API provides below features:
- Fast and reliable with no request limit and can handle thousands of request/sec.
- Open source and free to use under MIT license.
- Get historical rates for any date since 1999.
- Rates are quoted against Euro by default but supports 35 different currencies listed here.
- The rates are updated around 16:00 CET on every working day.
DEMO
For this example we will convert currency from CAD to INR. We are using HTTP GET request using Angular 9, this will work with any language.
The API url to convert currency from CAD to INR and it’s response is:
//Request
https://api.exchangeratesapi.io/latest?base=CAD&symbols=INR
//Response
{“rates”:{“INR”:53.9893446306},”base”:”CAD”,”date”:”2020-03-10″}
https://api.exchangeratesapi.io/latest?base=CAD&symbols=INR
//Response
{“rates”:{“INR”:53.9893446306},”base”:”CAD”,”date”:”2020-03-10″}
The CAD and INR can be changed to currency of your choice. To get the historical date rate, replace latest with history and add the date parameter as :
//Request to fetch historical rates
https://api.exchangeratesapi.io/history?start_at=2018-01-01&end_at=2018-09-01&base=CAD&symbols=INR
https://api.exchangeratesapi.io/history?start_at=2018-01-01&end_at=2018-09-01&base=CAD&symbols=INR
The final code in Angular is:
http.get<Currency[]>('https://api.exchangeratesapi.io/latest?base=CAD&symbols=INR').subscribe((result: Currency[]) => { this.currency = result; this.inrRate = this.currency['rates']['INR']; this.inrRate = (Math.round(this.inrRate * 100) / 100).toFixed(2); }, error => console.error(error));