Frankfurter (v1)
v1 API 已标记为 deprecated,由 v2 取代,但会继续可用。
获取最新汇率、历史汇率或时间序列。
最新汇率
获取最近一个工作日的汇率,每天约在欧洲中部时间 16:00 更新。
curl https://api.frankfurter.dev/v1/latest
使用 base 参数更改基准货币,默认为 EUR。
curl https://api.frankfurter.dev/v1/latest?base=USD
将响应限定为特定的目标货币。
curl https://api.frankfurter.dev/v1/latest?symbols=CHF,GBP
历史汇率
获取指定日期的汇率。
curl https://api.frankfurter.dev/v1/1999-01-04
更改基准货币并筛选目标货币。
curl https://api.frankfurter.dev/v1/1999-01-04?base=USD&symbols=EUR
注意:Frankfurter 以 UTC 存储日期,因此在其他时区,你查询到的日历日期可能与预期不同。如果有新汇率发布,当天的汇率仍可能变化。
时间序列数据
获取一段时间内的汇率。
curl https://api.frankfurter.dev/v1/2000-01-01..2000-12-31
获取截至目前的汇率。
curl https://api.frankfurter.dev/v1/2024-01-01..
提示:筛选货币可以减小响应体积并提升性能。
curl https://api.frankfurter.dev/v1/2024-01-01..?symbols=USD
可用货币
获取支持的货币代码及其全称。
curl https://api.frankfurter.dev/v1/currencies
货币换算
获取汇率,然后在你的代码中完成换算。
function convert(from, to, amount) {
fetch(`https://api.frankfurter.dev/v1/latest?base=${from}&symbols=${to}`)
.then((resp) => resp.json())
.then((data) => {
const convertedAmount = (amount * data.rates[to]).toFixed(2);
alert(`${amount} ${from} = ${convertedAmount} ${to}`);
});
}
convert("EUR", "USD", 10);