入门指南
Finexly API 提供170多种货币的实时和历史汇率。开始使用很简单:
- 注册免费账户
- 从仪表板获取您的API访问密钥
- 发起您的第一个 API 请求
基础 URL
https://api.finexly.com/v1/
身份验证
所有 API 请求都需要通过 Bearer 令牌进行身份验证。在 Authorization 标头中包含您的 API 密钥:
选项 1:授权标头(推荐)
授权标头(必需)
Authorization: Bearer YOUR_API_KEY
选项2:查询参数
将您的 API 密钥作为查询参数传递:
GET https://api.finexly.com/v1/rate?from=USD&to=EUR&api_key=YOUR_API_KEY
⚠ 安全提示: 在URL中使用API密钥可能会记录在服务器访问日志中,并可能通过HTTP引用头泄露。对于生产环境,我们建议使用Authorization头方法。查询参数作为一种方便,适用于快速测试和简单集成。
速率限制:检查响应头以查看您当前的使用情况。
X-RateLimit-Limit,
X-RateLimit-Used,
X-RateLimit-Units
API 端点
/v1/currencies
获取所有支持的货币代码列表。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|
示例
GET https://api.finexly.com/v1/currencies
// 响应
[
"AED",
"ANG",
"AUD",
"EUR",
"GBP",
"USD"
]
/v1/rate
获取特定货币对的汇率。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| from | string | 是 | 基础货币代码(大写) |
| to | string | 是 | 报价货币代码(大写) |
示例
GET https://api.finexly.com/v1/rate?from=USD&to=EUR
// 响应
{
"pair": "USD_EUR",
"rate": 0.9215
}
/v1/convert
在单个请求中获取多个货币对的汇率。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| q | string | 是 | 以 BASE_QUOTE 格式用逗号分隔的货币对 |
示例
GET https://api.finexly.com/v1/convert?q=USD_EUR,USD_GBP
// 响应
{
"USD_EUR": {
"rate": 0.9215
},
"USD_GBP": {
"rate": 0.7892
}
}
/v1/convert-amount
将特定金额从一种货币转换为另一种货币。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| from | string | 是 | 源货币代码(大写) |
| to | string | 是 | 目标货币代码(大写) |
| amount | number | 是 | 要转换的金额 |
示例
GET https://api.finexly.com/v1/convert-amount?from=USD&to=EUR&amount=100
// 响应
{
"pair": "USD_EUR",
"rate": 0.9215,
"amount": 100,
"result": 92.15
}
代码示例
# Using Authorization header (recommended)
curl -H "Authorization: Bearer YOUR_API_KEY" \
"https://api.finexly.com/v1/rate?from=USD&to=EUR"
# Using query parameter
curl "https://api.finexly.com/v1/rate?from=USD&to=EUR&api_key=YOUR_API_KEY"
# Get multiple rates
curl -H "Authorization: Bearer YOUR_API_KEY" \
"https://api.finexly.com/v1/convert?q=USD_EUR,USD_GBP"
# Convert amount
curl -H "Authorization: Bearer YOUR_API_KEY" \
"https://api.finexly.com/v1/convert-amount?from=USD&to=EUR&amount=100"
<?php
$apiKey = 'YOUR_API_KEY';
// Using cURL
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.finexly.com/v1/rate?from=USD&to=EUR',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
],
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
echo "USD/EUR Rate: " . $data['rate'];
const apiKey = 'YOUR_API_KEY';
// Get single rate
const response = await fetch('https://api.finexly.com/v1/rate?from=USD&to=EUR', {
headers: {
'Authorization': `Bearer ${apiKey}`
}
});
const data = await response.json();
console.log(`USD/EUR Rate: ${data.rate}`);
// Convert amount
const convertResponse = await fetch(
'https://api.finexly.com/v1/convert-amount?from=USD&to=EUR&amount=100',
{ headers: { 'Authorization': `Bearer ${apiKey}` } }
);
const result = await convertResponse.json();
console.log(`100 USD = ${result.result} EUR`);
import requests
api_key = 'YOUR_API_KEY'
headers = {'Authorization': f'Bearer {api_key}'}
# Get single rate
response = requests.get(
'https://api.finexly.com/v1/rate',
params={'from': 'USD', 'to': 'EUR'},
headers=headers
)
data = response.json()
print(f"USD/EUR Rate: {data['rate']}")
# Convert amount
response = requests.get(
'https://api.finexly.com/v1/convert-amount',
params={'from': 'USD', 'to': 'EUR', 'amount': 100},
headers=headers
)
result = response.json()
print(f"100 USD = {result['result']} EUR")
错误代码
| 代码 | 类型 | 描述 |
|---|---|---|
| 400 | BAD_REQUEST | 请求参数无效或缺少必填字段。 |
| 401 | UNAUTHORIZED | API 令牌缺失或无效。 |
| 403 | FORBIDDEN | 访问被拒绝。您的账户可能处于非活动状态。 |
| 413 | PAYLOAD_TOO_LARGE | 请求负载超出最大允许大小。 |
| 429 | RATE_LIMIT_EXCEEDED | 您已超出速率限制。请检查 X-RateLimit 标头。 |
| 500 | INTERNAL_ERROR | 发生内部服务器错误。请重试。 |
Tutorials & Guides
Learn how to integrate Finexly with your favorite programming languages and frameworks.
JavaScript Integration Tutorial
Step-by-step guide to integrating Finexly API with JavaScript and Node.js.
Python Integration Tutorial
Complete guide to using Finexly API with Python and popular libraries.
Developer Guide
Comprehensive guide to free currency API features and best practices.
Historical Rates Guide
Learn how to retrieve and work with historical exchange rate data.