# 第N个交易日

- 接口：get_nth_trade_date
- 路径：/api/v1/market/data/time/get-nth-trade-date
- 方法：GET
- 描述：根据给定 N，返回当前日期向前第 N 个交易日（N >= 1）。基于交易日历过滤非交易日，响应使用统一 `code/message/data` 壳，日期结果位于 `data`。
- 数据范围：实时计算（基于交易日历，无固定数据范围）
- 单次限量：单次一个 N 值
- 提示：
  - `n` 必须 >= 1。
  - 「当前日期」以服务端当日为准，目标交易日为向前（历史方向）数第 N 个。

## 输入参数

| 名称 | 类型 | 必选 | 描述 |
|------|------|------|------|
| n | integer | Y | 需要获取的前 N 个交易日，N >= 1 |

## 输出参数

成功响应外层固定为 `code`、`message`、`data`：

| 名称 | 类型 | 默认显示 | 描述 |
|------|------|---------|------|
| code | integer | Y | 状态码：200 成功 |
| message | string | Y | 状态信息 |
| data | object | Y | 交易日计算结果 |

data 对象：

| 名称 | 类型 | 默认显示 | 描述 |
|------|------|---------|------|
| current_date | string | Y | 当前日期（YYYY-MM-DD） |
| nth_trade_date | string | Y | 前 N 个交易日（YYYY-MM-DD） |
| n | integer | Y | 请求的 N 值 |

## 接口示例

```bash
curl -sS "https://market.ft.tech/gateway/api/v1/market/data/time/get-nth-trade-date?n=5"
```

Python（[`ftshare`](https://github.com/FTShare-Lab/FTShare-python-sdk.git) SDK，方法 `market.nth_trade_date`，默认返回 pandas `DataFrame`）：

```python
import ftshare as ft

market = ft.market_api()

# 交易日计算结果（服务端日期为 2026-09-04，向前第 5 个交易日为 2026-08-28）
df = market.nth_trade_date(n=5)
print(df)
#   current_date  n nth_trade_date
# 0    2026-09-04  5     2026-08-28

# 返回 Python list（每行一个 dict）
rows = market.nth_trade_date(n=5, as_dataframe=False)
# rows == [{"current_date": "2026-09-04", "n": 5, "nth_trade_date": "2026-08-28"}]

# 返回原始 JSON（保留 code/message/data 外层结构）
payload = market.nth_trade_date(n=5, raw=True)
# payload == {
#     "code": 200,
#     "message": "success",
#     "data": {"current_date": "2026-09-04", "n": 5, "nth_trade_date": "2026-08-28"},
# }
```

## 数据样例

`n=5`（服务端当前日期为 2026-09-04，向前第 5 个交易日）：

| current_date | n | nth_trade_date |
|--------------|---|----------------|
| 2026-06-17 | 5 | 2026-06-10 |
