Fetch real-time quotes for the A-share pharma sector from Sina Finance's free public API, analyze them, and send a daily report via Feishu.
What this skill does
- Fetch real-time data for 20 core pharma stocks (Sina
hq.sinajs.cn, GBK encoding, free with no authentication) - Calculate sub-sector rankings, TOP 3 gainers and losers, and capital flow estimates
- Generate a Feishu rich-text daily report (with gain/loss colors, sub-sector medals)
- Send to a specified Feishu conversation via lark-cli
- Save a snapshot JSON of the day in the raw data directory
Capability boundaries
What it can do:
- Real-time snapshots of 20 core A-share pharma tickers
- Comparison of 7 major sub-sectors (innovative drugs / CXO / medical devices / traditional Chinese medicine / diversified pharma / medical services / biologics)
- Feishu markdown-formatted daily report output
What it cannot do:
- Does not provide investment advice (the daily report includes its own disclaimer)
- Does not fetch paid/paywalled content (only uses Sina's free API)
- Does not guarantee the data is error-free (source is attributed to Sina; cross-verify trading decisions from multiple sources)
Prerequisites
- Python 3.8+ (only uses stdlib's
urllib, no need to pip install any packages) - lark-cli is installed and logged into a Feishu account
- Can access
hq.sinajs.cn
If the user hasn't installed lark-cli:
npm install -g @larksuite/cli
lark-cli auth login --recommend
Note: Feishu is a domestic service, and the lark-cli command line must be prefixed with LARK_CLI_NO_PROXY=1。
Usage flow
Step 1: Confirm parameters
Ask the user to confirm:
- Feishu profile: Which Feishu account to send from? If they don't know which profiles they have, run
lark-cli profile listto check (seereferences/feishu_profiles.md) - Feishu conversation: Which group/person to send to? If the user doesn't know their chat_id, help them find it:
To send to yourself, use the Feishu Assistant conversation. To send to a group, search the group name.LARK_CLI_NO_PROXY=1 lark-cli im +chat-search --query " " --page-size 20 - Stock pool: Defaults to 20 core pharma tickers (see
references/stock_pool.md). Users can customize by saying "only innovative drugs" or "add such-and-such stock".
Step 2: Run the data pipeline
Directly execute scripts/daily_pipeline.py:
python3 scripts/daily_pipeline.py \
--feishu-profile <你的飞书profile名> \
--feishu-chat-id <你的飞书chat_id>
The script does it all in one go: fetch data → analyze → generate daily report → send to Feishu → save snapshot.
Step 3: Report results to the user
Tell the user the key data:
- How many rose / how many fell / average change
- Strongest sub-sector and weakest sub-sector
- TOP 3 gainers and losers
- Whether the Feishu send succeeded
Data pipeline details
Sina Finance real-time quote API
http://hq.sinajs.cn/list=sh600276,sz300122,...
Returns GBK-encoded text, each line in the format:
var hq_str_sh600276="股票名称,今开,昨收,现价,最高,最低,...,成交金额,...,日期,时间"
32 comma-separated fields. Key fields (counting from 0):
| Position | Meaning | Example |
|---|---|---|
| 0 | Stock name | Hengrui Pharmaceuticals |
| 2 | Previous Close | 45.60 |
| 3 | Current Price | 46.10 |
| 4 | Today's High | 46.50 |
| 5 | Today's Low | 45.30 |
| 9 | Turnover (CNY) | 850000000 |
Code Prefix Rule: starts with 6 = sh, others = sz。
For a complete field quick reference, see references/sina_api.md。
Sector Classification
The 20 stocks are divided into 7 sectors (see references/stock_pool.md). When analyzing, aggregate price changes and turnover by sector.
Fund Flow Estimation
The free Sina API does not provide buy/sell direction data. The script uses "turnover of rising stocks - turnover of falling stocks" to roughly estimate net flow, and labels it as "estimated" in the report.
FAQ
Spaces in stock names
Some names returned by Sina contain spaces (e.g., "新 和 成"), and the script has built-in normalization.
Feishu message too long
Feishu markdown messages have a limit of about 4096 bytes. Overly long messages are automatically truncated and marked.
Non-trading hours
Outside trading hours from 9:30 to 15:00, Sina returns the previous closing price, and the price change is close to 0. The report will still display it, but the data time can be used to determine whether it is real-time.
Network issues
When Sina is unreachable, the script errors out and exits, without using cache (for financial data, it is better to have nothing than stale data).
Next Step: Scheduled Sending
After the daily report is ready, the user may want to send it automatically every day. Suggestions:
Daily report test sent successfully! Would you like to set it to automatically send to Feishu every morning at 9:03?
A) Set it for weekdays at 9:03 — receive it before the market opens each trading day (recommended) B) Set it for every day at 9:03 — also send on weekends (the data won't move but you can see it) C) Don't set it for now, just run it manually