# 查询宏观指标数据

> 通过 WX 指标编号查询指定日期范围的宏观时间序列

## 接口基本信息

- **接口名称**: `get_edb_data_by_displayid`
- **功能描述**: 使用公开 `displayid` 查询指定日期范围内的宏观经济指标时间序列
- **数据更新频率**: 取决于指标自身频率
- **请求方法**: `POST`
- **API 路径**: `https://api.wanxingai.com/openapi/edb/by_displayid/`
- **认证方式**: `Authorization: Bearer sk-********`

---

## 输入参数说明

| 参数名 | 类型 | 必选 | 描述 | 示例 |
| --- | --- | --- | --- | --- |
| `displayid` | str | **是** | 自然语言匹配接口返回的公开指标编号，格式为 `WX` 加 9 位数字 | `WX567563093` |
| `startdate` | str | **是** | 查询开始日期，格式为 `YYYY-MM-DD` | `2019-01-01` |
| `enddate` | str | **是** | 查询结束日期，格式为 `YYYY-MM-DD` | `2020-12-31` |

`indicators` 可作为 `displayid` 的兼容别名，但新接入建议统一使用 `displayid`。

---

### 返回数据说明

| 字段名 | 类型 | 描述 |
| --- | --- | --- |
| `status` | int | 业务状态码，`200` 表示请求成功 |
| `message.displayid` | str | 本次查询使用的公开指标编号 |
| `message.startdate` | str | 查询开始日期 |
| `message.enddate` | str | 查询结束日期 |
| `message.tables` | array | 指标时间序列表格；没有对应日期数据时仍可能成功返回空数组字段 |
| `tables[].id` | array | 公开指标编号数组，编号仍为 `WX` 格式 |
| `tables[].time` | array | 数据日期数组 |
| `tables[].value` | array | 指标值数组，与 `time` 按下标一一对应 |
| `tables[].rtime` | array | 数据更新时间数组，具体内容取决于上游数据 |
| `tables[].index_name` | array | 指标名称或附加描述数组 |
| `error` | str | 失败原因，仅失败时返回 |

### 返回示例

```
{
  "status": 200,
  "message": {
    "displayid": "WX567563093",
    "startdate": "2019-01-01",
    "enddate": "2020-12-31",
    "tables": [
      {
        "id": ["WX567563093"],
        "time": ["2020-12-31", "2019-12-31"],
        "value": ["43957.0", "45445.0"],
        "rtime": [],
        "index_name": []
      }
    ]
  }
}
```

---

## 使用示例

```python
import requests

url = "https://api.wanxingai.com/openapi/edb/by_displayid/"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer sk-********"
}
payload = {
    "displayid": "WX567563093",
    "startdate": "2019-01-01",
    "enddate": "2020-12-31"
}

resp = requests.post(url, json=payload, headers=headers)
resp.raise_for_status()
print(resp.json())
```

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newHttpClient();
String json = """
    {
      "displayid": "WX567563093",
      "startdate": "2019-01-01",
      "enddate": "2020-12-31"
    }
    """;

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.wanxingai.com/openapi/edb/by_displayid/"))
    .header("Content-Type", "application/json")
    .header("Authorization", "Bearer sk-********")
    .POST(HttpRequest.BodyPublishers.ofString(json))
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

```curl
curl -X POST https://api.wanxingai.com/openapi/edb/by_displayid/ \\
  -H "Content-Type: application/json" \\
  -H "Authorization: Bearer sk-********" \\
  -d '{
    "displayid": "WX567563093",
    "startdate": "2019-01-01",
    "enddate": "2020-12-31"
  }'
```

### 注意事项

1. 该接口只接受 `WX` 加 9 位数字的公开编号，不能传入其他来源的原始指标编号
2. `startdate` 和 `enddate` 均为闭区间日期，且开始日期不能晚于结束日期
3. 指标发布频率可能是日、月、季或年；请求成功但 `time`、`value` 为空，表示该日期范围没有观测值
4. 建议先调用“自然语言匹配宏观指标”接口获取 `displayid`，再调用本接口查询数据
