Exchange rates API is a free service for current and historical foreign exchange rates published by the European Central Bank.
Get the latest foreign exchange rates.
GET /latest
Get historical rates for any day since 1999.
GET /2018-03-26
Rates are quoted against the Euro by default. Quote against a different currency by setting the base parameter in your request.
GET /latest?base=USD
Request specific exchange rates by setting the symbols parameter.
GET /latest?symbols=USD,GBP
Get historical rates for a time period.
GET /history?start_at=2018-01-01&end_at=2018-09-01
Limit results to specific exchange rates to save bandwidth with the symbols parameter.
GET /history?start_at=2018-01-01&end_at=2018-09-01&symbols=ILS,JPY
Quote the historical rates against a different currency.
GET /history?start_at=2018-01-01&end_at=2018-09-01&base=USD
The primary use case is client side. For instance, with money.js in the browser
let demo = () => {
let rate = fx(1).from("GBP").to("USD")
alert("£1 = $" + rate.toFixed(4))
}
fetch('https://api.exchangeratesapi.io/latest')
.then((resp) => resp.json())
.then((data) => fx.rates = data.rates)
.then(demo)
Exchange rates API is built upon Sanic to achieve high throughput. The current setup can asyncronously handle thousands of requests per second.
Set the DISABLE_META_SITE environment variable to '1' to stop responding to GET at / and serving the static website.
Set the SCHEDULER_LOCKFILE environment variable to override the default 'scheduler.lock' file (used in Docker development mode)
pipenv shell
pipenv install
You may build a container exposing the API on (container) port 8000:
cd exchangeratesapi
docker build --build-arg TARGET_ENV=production -t exchangeratesapi .
docker run -e "DATABASE_URL=postgresql://user:pass@dbhost/dbname" exchangeratesapi:latest
Or alternatively through docker-compose (assuming the docker-compose.yml file is outside the exchangeratesapi directory):
exchangeratesapi:
build:
args:
TARGET_ENV: production
context: ./exchangeratesapi
environment:
DATABASE_URL: postgresql://user:pass@dbhost/dbname
expose:
- '8000'
restart: always
The scheduler will keep your database up to date hourly with information from European Central bank. It will download the last 90 days worth of data every hour.
The reference rates are usually updated around 16:00 CET on every working day, except on TARGET closing days. They are based on a regular daily concertation procedure between central banks across Europe, which normally takes place at 14:15 CET.
On initialization it will check the database. If it's empty all the historic rates will be downloaded and records created in the database.
gunicorn exchangerates.app:app --worker-class sanic.worker.GunicornWorker --reload
You may develop while running the app in docker, and have code changes reload automatically. For that we mount the current directory (exchangeratesapi) as a volume into the docker and run gunicorn with --reload
cd exchangeratesapi
docker build --build-arg TARGET_ENV=development -t exchangeratesapi_dev .
docker run -e "DATABASE_URL=postgresql://user:pass@dbhost/dbname" -v "$PWD:/usr/src/app:ro" exchangeratesapi_dev:latest
Or alternatively through docker-compose (assuming the docker-compose.yml file is outside the exchangeratesapi directory):
exchangeratesapi:
build:
args:
TARGET_ENV: development
context: ./exchangeratesapi
environment:
DATABASE_URL: postgresql://user:pass@dbhost/dbname
expose:
- '8000'
restart: always
volumes:
- ./exchangeratesapi:/usr/src/app:ro
Thanks for your interest in the project! All pull requests are welcome from developers of all skill levels. To get started, simply fork the master branch on GitHub to your personal account and then clone the fork into your development environment.
Madis Väin (madisvain on Github, Twitter) is the original creator of the Exchange Rates API framework.
MIT