SuperAPI AI Directory

eastmoney_select_stock

Data & analytics

View repository

Updated 10-15 14:13

About this skill

Eastmoney Intelligent Stock Selection skill (eastmoney_select_stock)

Throughnatural language queryperform stock selection (supported markets: A-shares, Hong Kong stocks, US stocks), return a list of stocks that meet the conditions, and automatically export to a CSV file.

Usage

  1. First check whether the environment variableEASTMONEY_APIKEYexists:

    echo $EASTMONEY_APIKEY
    

    If it does not exist, prompt the user on the Eastmoney Skills page (https://marketing.dfcfs.com/views/finskillshub/indexuNdYscEA?appfenxiang=1)获取apikey并设置到环境变量。

    ⚠️ Security Considerations

    • External Requests: This Skill will send the user's query keyword (Keyword) to the Eastmoney official API endpoint (mkapi2.dfcfs.com) for parsing and retrieval.
    • Data Usage: The submitted data is only used to match stock selection conditions and does not contain personal privacy information.
    • Credential Protection: The API Key is only used via the environment variable EASTMONEY_APIKEY on the server side or in a trusted runtime environment, and will not be exposed in plaintext on the frontend.
  1. Use a POST request to call the interface:
    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}'
    

Applicable Scenarios

Use this skill when the user queries the following types of content:

  • Conditional stock selection: such as "stocks that rose 2% today", "bank stocks with a P/E ratio below 10", "tech stocks that have risen for 3 consecutive days"
  • Sector/industry constituent stocks: such as "constituent stocks of the semiconductor sector", "listed companies in the new energy industry"
  • Index constituent stocks: such as "CSI 300 constituent stocks", "STAR 50 constituent stock list"
  • Stock recommendations: such as "recommendations for low-valuation high-dividend stocks", "stocks with recent main capital inflows"
  • Market screening: such as "Hong Kong Stock Connect eligible stocks", "list of US-listed Chinese concept stocks"

Request Parameter Description

Parameter Type Required Description
keyword String Yes Stock selection conditions described in natural language
pageNo Number No Page number, default 1
pageSize Number No Number per page, default 20, maximum 200

Interface Result Explanation

I. Top-level Core Status/Statistics Fields

Field Path Type Core Meaning
status Number Interface global status, 0 = success
message String Interface global message, ok = success
data.code String Stock selection business-layer status code, 100 = parsing successful
data.msg String Stock selection business-layer message
data.data.resultType Number Result type enum, 2000 is the standard stock selection result
data.data.result.total Number [Core] Total number of stock selection results (number of stocks meeting the conditions)

2.1 Column Definitions:data.data.result.columns(array)

Core function: defines the display rules for each column of the table, and withdataListmaps one-to-one with the row data keys.

Subfield Type Core description
title String Table column display title (e.g., Latest Price (CNY), Change (%)).
key String [Core] Unique business key of the column, mapped to the keys of the objects indataList.
unit String Column value unit (CNY, %, shares, times).
dataType String Column data type (String/Double/Long).

2.2 Row data:data.data.result.dataList(array)

Core purpose: the specific stock data of the stock selection results; each object corresponds to one stock that meets the criteria.

Core key Data type Core description
SERIAL String Table row number.
SECURITY_CODE String Stock code (e.g., 603866, 300991).
SECURITY_SHORT_NAME String Stock abbreviation (e.g., Toly Bread, Chuangyitong).
MARKET_SHORT_NAME String Market abbreviation (SH = Shanghai Stock Exchange, SZ = Shenzhen Stock Exchange, HK = Hong Kong Stock Exchange, US = US stocks).
NEWEST_PRICE Number/String Latest price (unit: CNY).
CHG Number/String Change (unit: %).
PCHG Number/String Change amount (unit: CNY).

III. Stock Selection Criteria Description

Field path Type Core description
data.data.responseConditionList Array Statistics of a single filter condition; each object corresponds to 1 filter condition.
data.data.responseConditionList[].describe String Filter condition description (e.g., today's change is between [1.5%, 2.5%]).
data.data.totalCondition.describe String Combined condition description (the final filter rule after all conditions are superimposed).
data.data.parserText String Parsed text of the stock selection criteria, with single conditions separated by semicolons.

Example

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()

# 检查是否有数据返回
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)

# 导出为CSV
columns = result_data["columns"]
data_list = result_data["dataList"]

# 生成列名映射
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")

Exception handling

  • If the data result is empty, prompt the user to perform stock selection at East Money Miaoxiang AI.
  • If the request fails, check whether the API Key is correct and whether the network is normal.
  • It is recommended that a single query's pageSize not exceed 200 to avoid an excessively large data volume.