# 证券代码搜索

> 搜索证券代码及相关信息

## 接口基本信息

- **接口名称**: `search_securities_code`
- **功能描述**: 通过行情代码或证券简称查询标准代码，支持多条件筛选
- **数据更新频率**: 实时
- **请求方法**: `POST`
- **API 路径**: `https://api.wanxingai.com/openapi/search_securities_code/`

---

## 输入参数说明

| 参数名 | 类型 | 必选 | 默认值 | 描述 | 示例 |
| --- | --- | --- | --- | --- | --- |
| `query` | str | **是** | — | 查询内容：行情代码（如 000001）或证券简称（如 平安银行） | `000001` |
| `mode` | str | 否 | `seccode` | 查询模式：`seccode`-按代码查 / `secname`-按名称查 | `seccode` |
| `sectype` | str | 否 | `""` | 证券类型，空=查所有；`001`-股票 / `002`-基金 等 | `001` |
| `market` | str | 否 | `""` | 市场代码，空=查所有；`212001`-上交所 / `212100`-深交所 / `212200`-港交所 | `212100` |
| `tradestatus` | str | 否 | `"0"` | 交易状态：`"0"`-全部 / `"1"`-正常交易 / `"2"`-已停牌 | `1` |
| `isexact` | str | 否 | `"0"` | 是否精确匹配：`"0"`-模糊 / `"1"`-精确 | `0` |

---

### 返回数据说明

| 字段名 | 类型 | 描述 |
| --- | --- | --- |
| `seccode` | str | 输入的查询代码 |
| `table.code` | str | 匹配到的所有标准代码，以英文逗号拼接为一个字符串 |

---

## 使用示例

```python
import requests

url = "https://api.wanxingai.com/openapi/search_securities_code/"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer sk-********"
}
payload = {"query": "000001", "mode": "seccode"}

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

```java
import java.net.http.*;
import java.net.URI;

HttpClient client = HttpClient.newHttpClient();
String json = """
    {"query": "000001", "mode": "seccode"}
    """;

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.wanxingai.com/openapi/search_securities_code/"))
    .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/search_securities_code/ \\
  -H "Content-Type: application/json" \\
  -H "Authorization: Bearer sk-********" \\
  -d '{"query": "000001", "mode": "seccode"}'
```

### 注意事项

1. code 返回的是将所有匹配结果以逗号拼接的**单个字符串**，并非字符串数组
2. 一个行情代码可能对应多个市场（如 000001 同时存在于深交所和上交所）
