-
First check if the environment variable
exists:
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 () 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 , and will not be exposed in plain text on the frontend.
-
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}'
Core function: Defines the display rules for each column of the table, which maps one-to-one with the row data keys in
.
Core function: Specific stock data of stock selection results, each object corresponds to one qualified stock.
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("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)
# Export to CSV
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"Found {result_data['total']} qualified stocks. Results have been saved to stock_selection_result.csv")