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

  1. 首先检查环境变量
    EASTMONEY_APIKEY
    是否存在:
    bash
    echo $EASTMONEY_APIKEY
    ⚠️ 安全注意事项
    • 外部请求: 本 Skill 会将用户的查询关键词(Keyword)发送至东方财富官方 API 接口 (
      mkapi2.dfcfs.com
      ) 进行解析与检索。
    • 数据用途: 提交的数据仅用于匹配选股条件,不包含个人隐私信息。
    • 凭据保护: API Key 仅通过环境变量
      EASTMONEY_APIKEY
      在服务端或受信任的运行环境中使用,不会在前端明文暴露。
  2. 使用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}'
  1. First check if the environment variable
    EASTMONEY_APIKEY
    exists:
    bash
    echo $EASTMONEY_APIKEY
    If 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 (
      mkapi2.dfcfs.com
      ) for parsing and retrieval.
    • 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
      EASTMONEY_APIKEY
      , and will not be exposed in plain text on the frontend.
  2. 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

参数类型必填说明
keyword
字符串自然语言描述的选股条件
pageNo
数字页码,默认1
pageSize
数字每页数量,默认20,最大200
ParameterTypeRequiredDescription
keyword
StringYesNatural language description of stock selection criteria
pageNo
NumberNoPage number, default is 1
pageSize
NumberNoNumber of items per page, default is 20, maximum is 200

接口结果释义

Interface Result Interpretation

一、顶层核心状态/统计字段

1. Top-level Core Status/Statistics Fields

字段路径类型核心释义
status
数字接口全局状态,0 = 成功
message
字符串接口全局提示,ok = 成功
data.code
字符串选股业务层状态码,100 = 解析成功
data.msg
字符串选股业务层提示
data.data.resultType
数字结果类型枚举,2000 为标准选股结果
data.data.result.total
数字【核心】选股结果总数量(符合条件的股票数)
Field PathTypeCore Interpretation
status
NumberGlobal interface status, 0 = success
message
StringGlobal interface prompt, ok = success
data.code
StringStock selection business layer status code, 100 = parsing successful
data.msg
StringStock selection business layer prompt
data.data.resultType
NumberResult type enumeration, 2000 = standard stock selection result
data.data.result.total
Number[Core] Total number of stock selection results (number of qualified stocks)

2.1 列定义:
data.data.result.columns
(数组)

2.1 Column Definition:
data.data.result.columns
(Array)

核心作用:定义表格每一列的展示规则,与
dataList
的行数据键一一映射。
子字段类型核心释义
title
字符串表格列展示标题(如最新价 (元)、涨跌幅 (%))
key
字符串【核心】列唯一业务键,与
dataList
中对象的键映射
unit
字符串列数值单位(元、%、股、倍)
dataType
字符串列数据类型(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-fieldTypeCore Interpretation
title
StringDisplay title of the table column (e.g., Latest Price (CNY), Price Change (%)
key
String[Core] Unique business key of the column, maps to the keys of objects in
dataList
unit
StringUnit of column values (CNY, %, shares, times)
dataType
StringData type of the column (String/Double/Long)

2.2 行数据:
data.data.result.dataList
(数组)

2.2 Row Data:
data.data.result.dataList
(Array)

核心作用:选股结果的具体股票数据,每个对象对应一只符合条件的股票。
核心键数据类型核心释义
SERIAL
字符串表格行序号
SECURITY_CODE
字符串股票代码(如 603866、300991)
SECURITY_SHORT_NAME
字符串股票简称(如桃李面包、创益通)
MARKET_SHORT_NAME
字符串市场简称(SH = 上交所,SZ = 深交所,HK = 港交所,US = 美股)
NEWEST_PRICE
数字/字符串最新价(单位:元)
CHG
数字/字符串涨跌幅(单位:%)
PCHG
数字/字符串涨跌额(单位:元)
Core function: Specific stock data of stock selection results, each object corresponds to one qualified stock.
Core KeyData TypeCore Interpretation
SERIAL
StringTable row number
SECURITY_CODE
StringStock code (e.g., 603866, 300991)
SECURITY_SHORT_NAME
StringAbbreviated stock name (e.g., Taoli Bread, Chuangyitong)
MARKET_SHORT_NAME
StringAbbreviated market name (SH = Shanghai Stock Exchange, SZ = Shenzhen Stock Exchange, HK = Hong Kong Stock Exchange, US = US Stock Market)
NEWEST_PRICE
Number/StringLatest price (unit: CNY)
CHG
Number/StringPrice change percentage (unit: %)
PCHG
Number/StringPrice change amount (unit: CNY)

三、选股条件说明

3. Stock Selection Criteria Description

字段路径类型核心释义
data.data.responseConditionList
数组单条筛选条件的统计,每个对象对应1个筛选条件
data.data.responseConditionList[].describe
字符串筛选条件描述(如今日涨跌幅在 [1.5%,2.5%] 之间)
data.data.totalCondition.describe
字符串组合条件描述(所有条件叠加后的最终筛选规则)
data.data.parserText
字符串选股条件的解析文本,以分号分隔单条件
Field PathTypeCore Interpretation
data.data.responseConditionList
ArrayStatistics of single screening criteria, each object corresponds to 1 screening condition
data.data.responseConditionList[].describe
StringDescription of screening criteria (e.g., Today's price change is between [1.5%,2.5%])
data.data.totalCondition.describe
StringDescription of combined criteria (final screening rule after all conditions are superimposed)
data.data.parserText
StringParsed 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")
undefined
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"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