金融与汇率

Exchangerate Host

提供实时与历史的外汇汇率和加密货币价格查询服务。支持多种货币对,数据准确可靠,适用于金融应用和汇率换算需求。

查看官方文档 ↗

接入教程

1. 访问官网注册获取免费API密钥
2. 调用实时汇率端点,如:GET https://api.exchangerate.host/latest?base=USD
3. 查询历史汇率使用历史端点,如:GET https://api.exchangerate.host/2020-01-01
4. 加密货币汇率查询添加参数:source=crypto
5. 解析返回的JSON数据并集成到您的应用中
6. 根据文档设置缓存或频率限制优化性能

Python 获取实时汇率

python
import requests

url = 'https://api.exchangerate.host/latest'
params = {
    'base': 'USD',
    'symbols': 'EUR,GBP,JPY',
    'apikey': 'YOUR_API_KEY'
}
try:
    response = requests.get(url, params=params)
    response.raise_for_status()
    data = response.json()
    print(f"汇率数据: {data}")
except requests.exceptions.RequestException as e:
    print(f"请求出错: {e}")

PHP 查询历史汇率

php
<?php
$apiKey = 'YOUR_API_KEY';
$date = '2023-12-25';
$baseCurrency = 'CNY';
$targetCurrencies = 'USD,EUR,GBP';

$url = "https://api.exchangerate.host/{$date}";
$queryParams = http_build_query([
    'base' => $baseCurrency,
    'symbols' => $targetCurrencies,
    'apikey' => $apiKey
]);

$fullUrl = $url . '?' . $queryParams;
$response = file_get_contents($fullUrl);

if ($response !== false) {
    $data = json_decode($response, true);
    echo "历史汇率: " . print_r($data, true);
} else {
    echo "请求失败";
}
?>

JavaScript 转换货币金额

javascript
const apiKey = 'YOUR_API_KEY';
const amount = 100;
const fromCurrency = 'EUR';
const toCurrency = 'USD';

async function convertCurrency() {
    const url = 'https://api.exchangerate.host/convert';
    const params = new URLSearchParams({
        'from': fromCurrency,
        'to': toCurrency,
        'amount': amount,
        'apikey': apiKey
    });

    try {
        const response = await fetch(`${url}?${params}`);
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        const data = await response.json();
        console.log(`转换结果: ${data.result}`);
    } catch (error) {
        console.error('请求失败:', error);
    }
}

convertCurrency();

常见问题

如何获取 API 密钥?

访问 Exchangerate Host 官方网站注册账户,在控制台页面可生成专属 API 密钥。免费套餐通常提供基础请求额度。

API 请求频率有限制吗?

是的,根据您选择的套餐不同,请求频率限制会有所区别。免费套餐通常有每分钟或每小时的请求次数限制,具体请查阅官方文档。

支持哪些货币和加密货币?

API 支持全球主要法定货币(如 USD、EUR、CNY、JPY 等)和主流加密货币(如 BTC、ETH)。具体支持的代码列表可在官方文档中查询。

相似接口推荐

AWS Import/Export

AWS Import/Export服务通过邮寄物理存储设备的方式,在AWS云和用户本地环境间高效传输海量数据。该服务利用亚马逊高速内部网络直接读写存储设备,适用于大规模数据迁移场景。

待确认
AWS Greengrass

AWS IoT Greengrass可将AWS功能无缝扩展至物理设备,使设备能够本地处理生成的数据,同时仍利用云端进行管理、分析和持久存储。该服务确保设备能够快速响应本地事件,并在间歇性连接下稳定运行。

待确认
Amazon ElastiCache

Amazon ElastiCache是一项Web服务,可简化云端分布式缓存的设置、操作和扩展。它让客户能够获得高性能内存缓存的所有优势,同时减少管理负担。

待确认
Amazon Elastic Inference

Elastic Inference是AWS提供的弹性推理服务公共API。自2023年4月15日起,AWS不再接受新客户使用该服务,并协助现有客户迁移至性价比更优的替代方案。该API用于管理云端AI推理的加速计算资源。

待确认