银行汇率查询:用"历史汇率"接入点拉取任意时段牌价(含 90 天区间)
# 银行汇率查询:用"历史汇率"接入点拉取任意时段牌价(含 90 天区间)
> 接口:银行汇率查询(apiCode=105)· 接入点:查询历史汇率(105-34)· 免费 · 请求方式:POST/GET · 返回格式:JSON · 适用人群:需对账 / 做走势分析的开发者 · 阅读时间:约 6 分钟
## TL;DR
- 历史汇率接入点(105-34)可查自 2009 年 1 月起的外汇牌价,口径为「100 外币兑人民币」。
- 两种查询方式互斥:`month`(yyyyMM,按月)或 `startDate`+`endDate`(yyyyMMdd,按区间,最大 90 天)。
- 每天 1 点更新「昨日」历史数据;返回逐日六价位字段。
## Why
对账、报销、财务分析经常需要「某天某货币的牌价」。实时接入点只给当下,历史接入点补上时间维度:你给它一个月份或一段日期,它返回逐日牌价,方便你画走势、核账目。
## What
| 项目 | 说明 |
|------|------|
| 接口地址 | `https://route.showapi.com/105-34?appKey=YOUR_APPKEY` |
| 选填参数 | `code`(货币编号)、`name`(货币名称)、`month`(yyyyMM)、`startDate`(yyyyMMdd)、`endDate`(yyyyMMdd) |
| 互斥规则 | `month` 与 `startDate/endDate` 二选一 |
| 区间限制 | `startDate`~`endDate` 最大 90 天 |
| 更新频率 | 每天 1 点更新昨日历史牌价 |
| 数据口径 | 历史外币汇率 = 100 外币兑人民币 |
## How
### 步骤:查 2019 年 1 月美元历史牌价
**Python(requests)**
```python
import requests
url = "https://route.showapi.com/105-34"
params = {"appKey": "YOUR_APPKEY"}
data = {"code": "USD", "name": "", "month": "201901", "startDate": "", "endDate": ""}
js = requests.post(url, params=params, data=data, timeout=10).json()
if js.get("showapi_res_code") == 0 and js["showapi_res_body"].get("ret_code") == 0:
body = js["showapi_res_body"]
print("货币:", body["currency_name"], "区间:", body["startDate"], "~", body["endDate"])
for row in body["list"]:
print(row["publish_time"], "中行折算价", row["middle_rate"])
else:
print("失败:", js.get("showapi_res_error"))
```
**cURL**
```bash
curl -X POST "https://route.showapi.com/105-34?appKey=YOUR_APPKEY" \
-H "content-type: application/x-www-form-urlencoded" \
-d "code=USD&name=&month=201901&startDate=&endDate="
```
**Node.js(fetch)**
```javascript
const url = "https://route.showapi.com/105-34?appKey=YOUR_APPKEY";
const body = new URLSearchParams({ code: "USD", name: "", month: "201901", startDate: "", endDate: "" });
const res = await fetch(url, {
method: "POST", body,
headers: { "content-type": "application/x-www-form-urlencoded" }
});
const js = await res.json();
if (js.showapi_res_code === 0 && js.showapi_res_body.ret_code === 0) {
for (const row of js.showapi_res_body.list) {
console.log(row.publish_time, "中行折算价", row.middle_rate);
}
}
```
## 返回示例与解析
```json
{
"showapi_res_code": 0,
"showapi_res_body": {
"ret_code": 0,
"currency_name": "美元",
"currency_code": "USD",
"startDate": "20190101",
"endDate": "20190131",
"month": "201901",
"remark": "查询成功!",
"list": [
{ "publish_time": "2019-01-01", "middle_rate": "686.32",
"buying_rate": "686.07", "selling_rate": "688.98",
"cash_buying_rate": "680.49", "cash_selling_rate": "688.98" }
]
}
}
```
| 字段 | 含义 |
|------|------|
| `middle_rate` | 中行折算价(100 外币兑人民币) |
| `buying_rate` | 现汇买入价 |
| `selling_rate` | 现汇卖出价 |
| `cash_buying_rate` | 现钞买入价 |
| `cash_selling_rate` | 现钞卖出价 |
| `publish_time` | 发布日期 |
## 进阶 / 边界
- **按月批量拉全年**:循环 `month` 从 202401 到 202412,逐月请求即可拼出全年走势(注意免费档位限制,加本地缓存/节流)。
- **区间上限 90 天**:`startDate`~`endDate` 跨度超过 90 天会失败,长区间请按月拆分。
- **口径提醒**:历史接入点是「100 外币兑人民币」,与实时接入点的字段命名(hui_in 等)不同,跨接入点整合时务必对齐口径。
- 今日数据需等次日 1 点后才进历史库,当天牌价请用[实时查询接入点](https://www.showapi.com/guides/exchange-rate-quickstart-105)。
## FAQ
**Q:month 和 startDate/endDate 能同时传吗?**
不能,二者互斥。传了 month 就按月查,传了 startDate+endDate 就按区间查,区间最大 90 天。
**Q:历史数据是哪一年的?最早能查到哪天?**
文档说明自 2009 年 1 月起可查,具体以接口实际返回为准。
**Q:为什么今天的历史表里查不到今天的牌价?**
历史数据每天 1 点更新「昨日」,当天牌价尚未入库,需用实时查询接入点。
**Q:历史汇率是每单位还是每 100 单位?**
历史接入点明确为「100 外币兑人民币」;实时接入点文档未声明每 100 单位基准,跨接入点使用时以各自文档口径为准。
## 相关能力 / 下一步阅读
- [银行汇率查询:返回字段与状态码全解](https://www.showapi.com/guides/exchange-rate-fields-105)
- [银行汇率查询:搭建企业汇率看板——币种列表 + 实时查询 + 历史走势](https://www.showapi.com/guides/exchange-rate-finance-dashboard-105)
- **本系列共 13 篇**:查看[银行汇率查询指南总目录](https://www.showapi.com/guides/exchange-rate-guides-105)