eastmoney_select_stock
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese东方财富智能选股skill (eastmoney_select_stock)
Eastmoney Intelligent Stock Selection Skill (eastmoney_select_stock)
通过自然语言查询进行选股(支持市场:A股、港股、美股),返回符合条件的股票列表,可自动导出为CSV文件。
Stock selection via natural language query (supported markets: A-shares, Hong Kong stocks, US stocks), returns a list of qualified stocks, which can be automatically exported as a CSV file.
使用方式
Usage
-
首先检查环境变量是否存在:
EASTMONEY_APIKEYbashecho $EASTMONEY_APIKEY如果不存在,提示用户在东方财富Skills页面(https://marketing.dfcfs.com/views/finskillshub/indexuNdYscEA?appfenxiang=1)获取apikey并设置到环境变量。⚠️ 安全注意事项- 外部请求: 本 Skill 会将用户的查询关键词(Keyword)发送至东方财富官方 API 接口 () 进行解析与检索。
mkapi2.dfcfs.com - 数据用途: 提交的数据仅用于匹配选股条件,不包含个人隐私信息。
- 凭据保护: API Key 仅通过环境变量 在服务端或受信任的运行环境中使用,不会在前端明文暴露。
EASTMONEY_APIKEY
- 外部请求: 本 Skill 会将用户的查询关键词(Keyword)发送至东方财富官方 API 接口 (
-
使用POST请求调用接口:bash
curl -X POST --location 'https://mkapi2.dfcfs.com/finskillshub/api/claw/stock-screen' \ --header 'Content-Type: application/json' \ --header "apikey: $EASTMONEY_APIKEY" \ --data '{"keyword": "选股条件", "pageNo": 1, "pageSize": 20}'
-
First check if the environment variableexists:
EASTMONEY_APIKEYbashecho $EASTMONEY_APIKEYIf it does not exist, prompt the user to obtain the apikey on the Eastmoney Skills page (https://marketing.dfcfs.com/views/finskillshub/indexuNdYscEA?appfenxiang=1) and set it as an environment variable.⚠️ Security Notes- External Requests: This Skill will send the user's query keywords to the official Eastmoney API interface () for parsing and retrieval.
mkapi2.dfcfs.com - Data Usage: The submitted data is only used to match stock selection criteria and does not contain personal privacy information.
- Credential Protection: The API Key is only used on the server side or in a trusted runtime environment via the environment variable , and will not be exposed in plain text on the frontend.
EASTMONEY_APIKEY
- External Requests: This Skill will send the user's query keywords to the official Eastmoney API interface (
-
Call the interface using a POST request:bash
curl -X POST --location 'https://mkapi2.dfcfs.com/finskillshub/api/claw/stock-screen' \ --header 'Content-Type: application/json' \ --header "apikey: $EASTMONEY_APIKEY" \ --data '{"keyword": "stock selection criteria", "pageNo": 1, "pageSize": 20}'
适用场景
Applicable Scenarios
当用户查询以下类型的内容时使用本skill:
- 条件选股:如"今日涨幅2%的股票"、"市盈率低于10的银行股"、"连续3天上涨的科技股"
- 板块/行业成分股:如"半导体板块的成分股"、"新能源行业的上市公司"
- 指数成分股:如"沪深300成分股"、"科创50成分股列表"
- 股票推荐:如"低估值高分红的股票推荐"、"近期有主力资金流入的股票"
- 市场筛选:如"港股通标的股"、"美股中概股列表"
Use this Skill when users query the following types of content:
- Conditional stock selection: e.g., "stocks with a 2% increase today", "bank stocks with a price-to-earnings ratio below 10", "tech stocks that have risen for 3 consecutive days"
- Sector/industry component stocks: e.g., "component stocks of the semiconductor sector", "listed companies in the new energy industry"
- Index component stocks: e.g., "CSI 300 component stocks", "STAR Market 50 component stock list"
- Stock recommendations: e.g., "recommendations for undervalued high-dividend stocks", "stocks with recent main capital inflow"
- Market screening: e.g., "Hong Kong Stock Connect target stocks", "list of US-listed Chinese concept stocks"
请求参数说明
Request Parameter Description
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| 字符串 | 是 | 自然语言描述的选股条件 |
| 数字 | 否 | 页码,默认1 |
| 数字 | 否 | 每页数量,默认20,最大200 |
| Parameter | Type | Required | Description |
|---|---|---|---|
| String | Yes | Natural language description of stock selection criteria |
| Number | No | Page number, default is 1 |
| Number | No | Number of items per page, default is 20, maximum is 200 |
接口结果释义
Interface Result Interpretation
一、顶层核心状态/统计字段
1. Top-level Core Status/Statistics Fields
| 字段路径 | 类型 | 核心释义 |
|---|---|---|
| 数字 | 接口全局状态,0 = 成功 |
| 字符串 | 接口全局提示,ok = 成功 |
| 字符串 | 选股业务层状态码,100 = 解析成功 |
| 字符串 | 选股业务层提示 |
| 数字 | 结果类型枚举,2000 为标准选股结果 |
| 数字 | 【核心】选股结果总数量(符合条件的股票数) |
| Field Path | Type | Core Interpretation |
|---|---|---|
| Number | Global interface status, 0 = success |
| String | Global interface prompt, ok = success |
| String | Stock selection business layer status code, 100 = parsing successful |
| String | Stock selection business layer prompt |
| Number | Result type enumeration, 2000 = standard stock selection result |
| Number | [Core] Total number of stock selection results (number of qualified stocks) |
2.1 列定义:data.data.result.columns
(数组)
data.data.result.columns2.1 Column Definition: data.data.result.columns
(Array)
data.data.result.columns核心作用:定义表格每一列的展示规则,与的行数据键一一映射。
dataList| 子字段 | 类型 | 核心释义 |
|---|---|---|
| 字符串 | 表格列展示标题(如最新价 (元)、涨跌幅 (%)) |
| 字符串 | 【核心】列唯一业务键,与 |
| 字符串 | 列数值单位(元、%、股、倍) |
| 字符串 | 列数据类型(String/Double/Long) |
Core function: Defines the display rules for each column of the table, which maps one-to-one with the row data keys in .
dataList| Sub-field | Type | Core Interpretation |
|---|---|---|
| String | Display title of the table column (e.g., Latest Price (CNY), Price Change (%) |
| String | [Core] Unique business key of the column, maps to the keys of objects in |
| String | Unit of column values (CNY, %, shares, times) |
| String | Data type of the column (String/Double/Long) |
2.2 行数据:data.data.result.dataList
(数组)
data.data.result.dataList2.2 Row Data: data.data.result.dataList
(Array)
data.data.result.dataList核心作用:选股结果的具体股票数据,每个对象对应一只符合条件的股票。
| 核心键 | 数据类型 | 核心释义 |
|---|---|---|
| 字符串 | 表格行序号 |
| 字符串 | 股票代码(如 603866、300991) |
| 字符串 | 股票简称(如桃李面包、创益通) |
| 字符串 | 市场简称(SH = 上交所,SZ = 深交所,HK = 港交所,US = 美股) |
| 数字/字符串 | 最新价(单位:元) |
| 数字/字符串 | 涨跌幅(单位:%) |
| 数字/字符串 | 涨跌额(单位:元) |
Core function: Specific stock data of stock selection results, each object corresponds to one qualified stock.
| Core Key | Data Type | Core Interpretation |
|---|---|---|
| String | Table row number |
| String | Stock code (e.g., 603866, 300991) |
| String | Abbreviated stock name (e.g., Taoli Bread, Chuangyitong) |
| String | Abbreviated market name (SH = Shanghai Stock Exchange, SZ = Shenzhen Stock Exchange, HK = Hong Kong Stock Exchange, US = US Stock Market) |
| Number/String | Latest price (unit: CNY) |
| Number/String | Price change percentage (unit: %) |
| Number/String | Price change amount (unit: CNY) |
三、选股条件说明
3. Stock Selection Criteria Description
| 字段路径 | 类型 | 核心释义 |
|---|---|---|
| 数组 | 单条筛选条件的统计,每个对象对应1个筛选条件 |
| 字符串 | 筛选条件描述(如今日涨跌幅在 [1.5%,2.5%] 之间) |
| 字符串 | 组合条件描述(所有条件叠加后的最终筛选规则) |
| 字符串 | 选股条件的解析文本,以分号分隔单条件 |
| Field Path | Type | Core Interpretation |
|---|---|---|
| Array | Statistics of single screening criteria, each object corresponds to 1 screening condition |
| String | Description of screening criteria (e.g., Today's price change is between [1.5%,2.5%]) |
| String | Description of combined criteria (final screening rule after all conditions are superimposed) |
| String | Parsed text of stock selection criteria, single conditions separated by semicolons |
示例
Example
python
import os
import csv
import json
import requests
api_key = os.getenv("EASTMONEY_APIKEY")
if not api_key:
raise ValueError("请先设置EASTMONEY_APIKEY环境变量")
url = "https://mkapi2.dfcfs.com/finskillshub/api/claw/stock-screen"
headers = {
"Content-Type": "application/json",
"apikey": api_key
}
data = {
"keyword": "今日涨幅2%的股票",
"pageNo": 1,
"pageSize": 20
}
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
result = response.json()python
import os
import csv
import json
import requests
api_key = os.getenv("EASTMONEY_APIKEY")
if not api_key:
raise ValueError("Please set the EASTMONEY_APIKEY environment variable first")
url = "https://mkapi2.dfcfs.com/finskillshub/api/claw/stock-screen"
headers = {
"Content-Type": "application/json",
"apikey": api_key
}
data = {
"keyword": "stocks with a 2% increase today",
"pageNo": 1,
"pageSize": 20
}
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
result = response.json()检查是否有数据返回
Check if data is returned
if result.get("status") != 0 or not result.get("data") or result["data"].get("code") != "100":
print("选股查询失败,建议到东方财富妙想AI进行选股。")
print(f"错误信息: {result.get('message', '未知错误')}")
sys.exit(0)
result_data = result["data"]["data"]["result"]
if not result_data.get("dataList"):
print("没有找到符合条件的股票,建议调整筛选条件或到东方财富妙想AI查询。")
sys.exit(0)
if result.get("status") != 0 or not result.get("data") or result["data"].get("code") != "100":
print("Stock selection query failed. It is recommended to conduct stock selection on Eastmoney Miaoxiang AI.")
print(f"Error message: {result.get('message', 'Unknown error')}")
sys.exit(0)
result_data = result["data"]["data"]["result"]
if not result_data.get("dataList"):
print("No qualified stocks found. It is recommended to adjust the screening criteria or query on Eastmoney Miaoxiang AI.")
sys.exit(0)
导出为CSV
Export to CSV
columns = result_data["columns"]
data_list = result_data["dataList"]
columns = result_data["columns"]
data_list = result_data["dataList"]
生成列名映射
Generate column name mapping
column_map = {col["key"]: col["title"] for col in columns}
csv_headers = [column_map[key] for key in data_list[0].keys() if key in column_map]
with open("stock_selection_result.csv", "w", newline="", encoding="utf-8-sig") as f:
writer = csv.DictWriter(f, fieldnames=csv_headers)
writer.writeheader()
for row in data_list:
csv_row = {column_map[key]: value for key, value in row.items() if key in column_map}
writer.writerow(csv_row)
print(f"找到 {result_data['total']} 只符合条件的股票,结果已保存到 stock_selection_result.csv")
undefinedcolumn_map = {col["key"]: col["title"] for col in columns}
csv_headers = [column_map[key] for key in data_list[0].keys() if key in column_map]
with open("stock_selection_result.csv", "w", newline="", encoding="utf-8-sig") as f:
writer = csv.DictWriter(f, fieldnames=csv_headers)
writer.writeheader()
for row in data_list:
csv_row = {column_map[key]: value for key, value in row.items() if key in column_map}
writer.writerow(csv_row)
print(f"Found {result_data['total']} qualified stocks. Results have been saved to stock_selection_result.csv")
undefined异常处理
Exception Handling
- 如果数据结果为空,提示用户到东方财富妙想AI进行选股
- 如果请求失败,检查API Key是否正确,网络是否正常
- 建议单次查询pageSize不超过200,避免数据量过大
- If no data results are returned, prompt the user to conduct stock selection on Eastmoney Miaoxiang AI
- If the request fails, check if the API Key is correct and if the network is normal
- It is recommended that the pageSize for a single query does not exceed 200 to avoid excessive data volume