汇率换算
最后更新于:2022-04-02 08:18:29
## 汇率换算
>[danger]### 免费接口,每日100次免费调用,会员可不限次数调用,购买[API会员](https://market.topthink.com/product/210)
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/6c/7d/6c7ded8570b696b75b215f75faf4b967_219x210.png =120x)
> 外汇报价,货币汇率,包含三个接口:常用汇率查询、货币列表和实时汇率查询换算
每日100次免费调用
## 接口调用([调用须知](https://docs.topthink.com/think-api/1835086))
## 接口1:常用汇率查询
> 汇率查询,数据仅供参考,交易时以银行柜台成交价为准
### 请求地址
```
GET https://api.topthink.com/exchange/query
```
### 请求参数(无)
### SDK调用
```
$client = new Client("YourAppCode");
// 常用汇率查询
$result = $client->exchangeQuery()
->request();
```
返回示例:
~~~
{
"message": "查询成功",
"data": {
"update": "2016-07-22 10:32:31",
"list": [
[
"美元", /*货币名称*/
"100", /*交易单位*/
"665.63", /*现汇买入价*/
"660.3", /*现钞买入价*/
"668.3", /*现钞卖出价*/
"666.69" /*中行折算价*/
],
[
"港币",
"100",
"85.83",
"85.14",
"86.15",
"85.96"
],
[
"日元",
"100",
"6.2771",
"6.0834",
"6.3211",
"6.3014"
],
[
"欧元",
"100",
"732.74",
"710.13",
"737.88",
"735.79"
],
[
"英镑",
"100",
"879.28",
"852.15",
"885.46",
"879.01"
]
]
},
"code": 0
}
~~~
## 接口2:货币列表
> 支持的货币列表
### 请求地址
```
https://api.topthink.com/exchange/currency
```
### 请求参数(无)
### SDK调用
```
$client = new Client("YourAppCode");
// 获取货币列表
$result = $client->exchangeCurrency()
->request();
```
返回示例:
~~~
{
"message": "查询成功",
"data": {
"list": [
{
"name": "人民币", /*货币名称*/
"code": "CNY" /*货币代码*/
},
{
"name": "美元",
"code": "USD"
},
{
"name": "日元",
"code": "JPY"
},
{
"name": "欧元",
"code": "EUR"
},
{
"name": "英镑",
"code": "GBP"
},
...
]
},
"code": 0
}
~~~
## 接口3:实时汇率查询
实时货币汇率查询换算,数据仅供参考,交易时以银行柜台成交价为准
### 请求地址
```
https://api.topthink.com/exchange/convert
```
### 请求参数
|名称 | 必填 | 类型 | 说明 |
| --- | --- | --- | --- |
| appCode| 是 |string| 用户授权码,参考[API调用](https://docs.topthink.com/think-api/1835086) |
|from | 是 | string | 转换汇率前的货币代码 |
|to | 是 | string | 转换汇率成的货币代码 |
### SDK调用
```
$client = new Client("YourAppCode");
// 查询实时汇率
$result = $client->exchangeConvert()
->withFrom()
->withTo()
->request();
```
返回示例:
~~~
{
"message": "查询成功",
"data": [
{
"currencyF": "JPY", /*货币代码*/
"currencyF_Name": "日元", /*货币名称*/
"currencyT": "BHD", /*货币代码*/
"currencyT_Name": "巴林第纳尔", /*货币名称*/
"currencyFD": 1,
"exchange": "0.0032685972", /*当前汇率*/
"result": "0.0032",/*当前汇率*/
"updateTime": "2014-11-07 13:58:02"
},
{
"currencyF": "BHD",
"currencyF_Name": "巴林第纳尔",
"currencyT": "JPY",
"currencyT_Name": "日元",
"currencyFD": 1,
"exchange": "305.9416445623",
"result": 305.9416,
"updateTime": "2014-11-07 13:58:01"
}
],
"code": 0
}
~~~
';