This is a self hosted, free, currency exchange rate api, free demo at exchange-rate.bai.uno.
The current and historical foreign exchange rates data are from European Central Bank.
Make sure docker is installed.
git clone https://github.com/tim-hub/sanic-currency-exchange-rates-api
- run docker
docker build -t rate-api . && docker run --name rate-api -t -i -e DATABASE_URL=postgresql://dbuser:pwd@dburl:5432/dbname rate-api
This project is a fork from ExchangeRatesApi project, the original project is great, but as a project, is seems like they have some outdated dependencies (security issues) and difficulties to deploy.
Difference | Original | Fork |
---|---|---|
sanic version | 0.8.x | latest/19.12.2 |
python | 3.6 | 3.7 |
pin dependencies | false | true |
deploy to heroic | one click | (can be too) |
deploy as container | got some problem | easy |
xml parser | xml.etree | defusedxml |
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)
MIT