入门指南
Finexly API 提供170多种货币的实时和历史汇率。开始使用很简单:
- 注册免费账户
- 从仪表板获取您的API访问密钥
- 发起您的第一个 API 请求
基础 URL
https://api.finexly.com/v1/
身份验证
所有 API 请求都需要通过 Bearer 令牌进行身份验证。在 Authorization 标头中包含您的 API 密钥:
授权标头(必需)
Authorization: Bearer YOUR_API_KEY
速率限制:检查响应头以查看您当前的使用情况。
X-RateLimit-Limit,
X-RateLimit-Used,
X-RateLimit-Units
API 端点
GET
/v1/currencies
获取所有支持的货币代码列表。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|
示例
GET https://api.finexly.com/v1/currencies
// 响应
[
"AED",
"ANG",
"AUD",
"EUR",
"GBP",
"USD"
]
GET
/v1/rate
获取特定货币对的汇率。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| from | string | 是 | 基础货币代码(大写) |
| to | string | 是 | 报价货币代码(大写) |
示例
GET https://api.finexly.com/v1/rate?from=USD&to=EUR
// 响应
{
"pair": "USD_EUR",
"rate": 0.9215
}
GET
/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
}
}
GET
/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
}
代码示例
# Get single rate
curl -H "Authorization: Bearer YOUR_API_KEY" \
"https://api.finexly.com/v1/rate?from=USD&to=EUR"
# Get multiple rates
curl -H "Authorization: Bearer YOUR_API_KEY" \
"https://api.finexly.com/v1/convert?q=USD_EUR,USD_GBP,BTC_USD"
# 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 | 发生内部服务器错误。请重试。 |