🇺🇸 us-stock — US Equities Data
Single Python module with multi-source fallback for US stocks. Mirror of cn-stock for the US market. Use whenever the user asks about a US ticker — fundamentals, holders, insiders, financials. For pure price/K-line on US tickers, this skill internally calls the paid TwelveData skill, so you get one consistent interface.
Architecture
your call → exports.py
├─ twelvedata (paid, primary) → realtime quote, time series
└─ yfinance (free, primary for fundamentals)
→ info, holders, insiders,
financials, news, options,
dividends, splits, earnings
Most functions return a uniform envelope:
{"ok": bool, "source": str, "data": <payload>, "error": str|None, "ts": int}
Exception: get_full_report(symbol) returns a combined dict of sub-results (quote/company/holders/insiders/earnings/news).
Quick Start
Preferred — use core.skill_tools (handles import isolation):
python3 - <<'EOF'
from core.skill_tools import _modules
us = _modules["us-stock"]
q = us.get_realtime_quote("AAPL")
print(q["data"]["last"], q["data"]["pct_change"], "%")
c = us.get_company_info("NVDA")
d = c["data"]
print(f"{d['name']} | mcap ${d['market_cap']/1e12:.2f}T | shares {d['shares_outstanding']/1e9:.2f}B")
full = us.get_full_report("MSFT")
print(full["company"]["data"]["sector"])
EOF
Fallback (single-skill scripts only):
python3 - <<'EOF'
import importlib.util as ilu
spec = ilu.spec_from_file_location("us_stock_mod", "/data/workspace/skills/us-stock/exports.py")
us = ilu.module_from_spec(spec); spec.loader.exec_module(us)
print(us.get_realtime_quote("AAPL")["data"])
EOF
⚠️ Do NOT use sys.path.insert + from exports import ... — cn-stock also defines exports.py and they will collide in the same process.
Function Map
| Function |
Returns |
Source |
get_realtime_quote(symbol) |
price, OHLC, change, 52w range, mcap |
twelvedata → yfinance fallback |
get_company_info(symbol) |
mcap, shares_outstanding, float_shares, pct_held_insiders, pct_held_institutions, sector, industry, business summary, valuation, margins, dividend, analyst targets |
yfinance.get_info |
get_institutional_holders(symbol, top=15) |
Top N institutional holders + value + pctChange |
yfinance |
get_mutualfund_holders(symbol, top=15) |
Top N mutual fund holders |
yfinance |
get_insider_transactions(symbol, limit=20) |
Recent Form 4 buys/sells |
yfinance |
get_financials(symbol, statement, period, max_periods=5) |
Income / Balance / Cashflow, annual or quarterly |
yfinance |
get_earnings(symbol, limit=8) |
Past + upcoming earnings dates with EPS est. vs actual |
yfinance |
get_dividends(symbol, limit=20) |
Historical dividends |
yfinance |
get_splits(symbol, limit=10) |
Historical splits |
yfinance |
get_news(symbol, limit=10) |
Recent news titles + summaries + URLs |
yfinance |
get_kline(symbol, interval, outputsize) |
OHLCV bars |
twelvedata → yfinance fallback |
get_recommendations(symbol, limit=12) |
Analyst rating buckets per period |
yfinance |
get_options_expirations(symbol) |
All available option expiry dates |
yfinance |
get_etf_holdings(symbol, top=15) |
ETF/fund top holdings + sector/asset weights (e.g. SPY/QQQ) |
yfinance.funds_data |
get_full_report(symbol) |
quote + company + institutional + insiders + earnings + news combined |
combo |
Symbol Format
Pure US ticker — no exchange suffix:
AAPL, MSFT, NVDA, GOOGL, TSLA
- Dual-class:
BRK.B, BRK-B, GOOG / GOOGL
- Both formats accepted; pass through as-is
TwelveData Reuse (important)
This skill does not register a separate TwelveData credential. It loads the existing TwelveData skill by explicit file path (/data/workspace/skills/twelvedata/exports.py) via importlib, avoiding exports.py name collisions with other skills.
Starchild's TwelveData billing covers these calls. If TwelveData fails, yfinance fallback kicks in automatically.
get_company_info Field Reference
Fields most useful for Telegram replies (all from yfinance):
| Field |
Meaning |
Notes |
market_cap |
总市值 (USD) |
divide by 1e9 → 十亿, 1e12 → 万亿 |
enterprise_value |
EV |
mcap + debt − cash |
shares_outstanding |
流通股 (实际为已发行股数) |
divide by 1e9 |
float_shares |
自由流通股 (排除限售) |
usually slightly < shares_outstanding |
shares_short |
当前空头持仓 |
|
short_pct_of_float |
空头占流通比 |
already ratio, ×100 for % |
pct_held_insiders |
内部人持股比例 |
already ratio |
pct_held_institutions |
机构持股比例 |
already ratio |
trailing_pe / forward_pe |
静态/动态 PE |
|
price_to_book |
市净率 |
|
dividend_yield |
股息率 |
already ratio (0.0036 = 0.36%) |
beta |
贝塔系数 |
vs SP500 |
recommendation |
'buy' / 'hold' / 'sell' |
analyst consensus |
target_mean_price |
分析师目标均价 |
|
Gotchas
- yfinance rate limits: Yahoo throttles aggressive callers (~2000/hour). Per
get_full_report is ~6 calls. For batch monitoring use time.sleep(0.3) between tickers. The skill already has _retry(tries=2).
get_info() is heavy (~1-2s, returns 120+ fields). For pure price use get_realtime_quote() instead (TwelveData ~150ms).
- NaN handling: yfinance returns NaN for missing fields (e.g. dividend yield for non-dividend payers). The skill converts NaN →
null in JSON. Always check for None before formatting.
- Quarterly financials limit: yfinance returns ~4 quarters back. For deeper history use SEC EDGAR 10-Q parsing (future enhancement).
- Real-time vs delayed: TwelveData is exchange-direct (low latency). yfinance has ~1 min lag during market hours. When they conflict, trust TwelveData.
- Institutional holders staleness: 13F filings lag 45 days after quarter-end.
Date Reported field tells you the as-of date.
- News provider IDs change: yfinance's
news schema occasionally adds/removes fields. The skill normalizes to {title, summary, publisher, pub_date, url, type}.
- Options data weight:
get_options_expirations is fast but fetching the full chain (Calls/Puts at each strike) requires per-expiry calls — not exposed yet to keep this skill light.
Output Style for User-Facing Replies
Telegram users want plain text, no markdown. Follow these conventions:
- Market cap:
$3.91T (万亿 = T, 十亿 = B, 百万 = M)
- Shares:
14.69B 股
- Ratios:
+2.34% (sign required), PE 36.2, Beta 1.07
- Holders:
贝莱德 (BlackRock) 7.32%
- Always cite source at end:
数据来源:TwelveData + Yahoo Finance (yfinance),非投资建议
Future Enhancements (not implemented)
- SEC EDGAR 13F deep dive (top N positions over multiple quarters)
- Form 4 raw filings with explicit transaction type (P/S/A/D codes)
- Pre/post-market quote (TwelveData supports
prepost=True — exposed via get_realtime_quote if needed)
- Options chain greeks (requires per-expiry × per-strike calls)
1---2name: us-stock3description: US stock fundamentals: financials, holders, insiders, earnings, dividends, splits. Use for any US ticker beyond price (e.g. AAPL financials, NVDA top holders, MSFT insider trades, TSLA earnings calendar).4---5
6# 🇺🇸 us-stock — US Equities Data
7
8Single Python module with **multi-source fallback** for US stocks. Mirror of `cn-stock` for the US market. Use whenever the user asks about a US ticker — fundamentals, holders, insiders, financials. For pure price/K-line on US tickers, this skill internally calls the paid TwelveData skill, so you get one consistent interface.
9
10## Architecture
11
12```
13your call → exports.py
14 ├─ twelvedata (paid, primary) → realtime quote, time series
15 └─ yfinance (free, primary for fundamentals)
16 → info, holders, insiders,
17 financials, news, options,
18 dividends, splits, earnings
19```
20
21Most functions return a uniform envelope:
22```python
23{"ok": bool, "source": str, "data": <payload>, "error": str|None, "ts": int}
24```
25Exception: `get_full_report(symbol)` returns a combined dict of sub-results (quote/company/holders/insiders/earnings/news).
26
27## Quick Start
28
29**Preferred** — use `core.skill_tools` (handles import isolation):
30
31```bash
32python3 - <<'EOF'
33from core.skill_tools import _modules
34us = _modules["us-stock"]
35
36q = us.get_realtime_quote("AAPL")
37print(q["data"]["last"], q["data"]["pct_change"], "%")
38
39c = us.get_company_info("NVDA")
40d = c["data"]
41print(f"{d['name']} | mcap ${d['market_cap']/1e12:.2f}T | shares {d['shares_outstanding']/1e9:.2f}B")
42
43full = us.get_full_report("MSFT")
44print(full["company"]["data"]["sector"])
45EOF
46```
47
48**Fallback** (single-skill scripts only):
49
50```bash
51python3 - <<'EOF'
52import importlib.util as ilu
53spec = ilu.spec_from_file_location("us_stock_mod", "/data/workspace/skills/us-stock/exports.py")
54us = ilu.module_from_spec(spec); spec.loader.exec_module(us)
55print(us.get_realtime_quote("AAPL")["data"])
56EOF
57```
58
59⚠️ **Do NOT use** `sys.path.insert + from exports import ...` — `cn-stock` also defines `exports.py` and they will collide in the same process.
60
61## Function Map
62
63| Function | Returns | Source |
64|---|---|---|
65| `get_realtime_quote(symbol)` | price, OHLC, change, 52w range, mcap | twelvedata → yfinance fallback |
66| `get_company_info(symbol)` | mcap, **shares_outstanding**, **float_shares**, **pct_held_insiders**, **pct_held_institutions**, sector, industry, business summary, valuation, margins, dividend, analyst targets | yfinance.get_info |
67| `get_institutional_holders(symbol, top=15)` | Top N institutional holders + value + pctChange | yfinance |
68| `get_mutualfund_holders(symbol, top=15)` | Top N mutual fund holders | yfinance |
69| `get_insider_transactions(symbol, limit=20)` | Recent Form 4 buys/sells | yfinance |
70| `get_financials(symbol, statement, period, max_periods=5)` | Income / Balance / Cashflow, annual or quarterly | yfinance |
71| `get_earnings(symbol, limit=8)` | Past + upcoming earnings dates with EPS est. vs actual | yfinance |
72| `get_dividends(symbol, limit=20)` | Historical dividends | yfinance |
73| `get_splits(symbol, limit=10)` | Historical splits | yfinance |
74| `get_news(symbol, limit=10)` | Recent news titles + summaries + URLs | yfinance |
75| `get_kline(symbol, interval, outputsize)` | OHLCV bars | twelvedata → yfinance fallback |
76| `get_recommendations(symbol, limit=12)` | Analyst rating buckets per period | yfinance |
77| `get_options_expirations(symbol)` | All available option expiry dates | yfinance |
78| `get_etf_holdings(symbol, top=15)` | ETF/fund top holdings + sector/asset weights (e.g. SPY/QQQ) | yfinance.funds_data |
79| `get_full_report(symbol)` | quote + company + institutional + insiders + earnings + news combined | combo |
80
81## Symbol Format
82
83Pure US ticker — no exchange suffix:
84- `AAPL`, `MSFT`, `NVDA`, `GOOGL`, `TSLA`
85- Dual-class: `BRK.B`, `BRK-B`, `GOOG` / `GOOGL`
86- Both formats accepted; pass through as-is
87
88## TwelveData Reuse (important)
89
90This skill **does not register a separate TwelveData credential**. It loads the existing TwelveData skill by explicit file path (`/data/workspace/skills/twelvedata/exports.py`) via `importlib`, avoiding `exports.py` name collisions with other skills.
91Starchild's TwelveData billing covers these calls. If TwelveData fails, yfinance fallback kicks in automatically.
92
93## get_company_info Field Reference
94
95Fields most useful for Telegram replies (all from yfinance):
96
97| Field | Meaning | Notes |
98|---|---|---|
99| `market_cap` | 总市值 (USD) | divide by 1e9 → 十亿, 1e12 → 万亿 |
100| `enterprise_value` | EV | mcap + debt − cash |
101| `shares_outstanding` | 流通股 (实际为已发行股数) | divide by 1e9 |
102| `float_shares` | 自由流通股 (排除限售) | usually slightly < shares_outstanding |
103| `shares_short` | 当前空头持仓 | |
104| `short_pct_of_float` | 空头占流通比 | already ratio, ×100 for % |
105| `pct_held_insiders` | 内部人持股比例 | already ratio |
106| `pct_held_institutions` | 机构持股比例 | already ratio |
107| `trailing_pe` / `forward_pe` | 静态/动态 PE | |
108| `price_to_book` | 市净率 | |
109| `dividend_yield` | 股息率 | already ratio (0.0036 = 0.36%) |
110| `beta` | 贝塔系数 | vs SP500 |
111| `recommendation` | 'buy' / 'hold' / 'sell' | analyst consensus |
112| `target_mean_price` | 分析师目标均价 | |
113
114## Gotchas
115
116- **yfinance rate limits**: Yahoo throttles aggressive callers (~2000/hour). Per `get_full_report` is ~6 calls. For batch monitoring use `time.sleep(0.3)` between tickers. The skill already has `_retry(tries=2)`.
117- **`get_info()` is heavy** (~1-2s, returns 120+ fields). For pure price use `get_realtime_quote()` instead (TwelveData ~150ms).
118- **NaN handling**: yfinance returns NaN for missing fields (e.g. dividend yield for non-dividend payers). The skill converts NaN → `null` in JSON. Always check for `None` before formatting.
119- **Quarterly financials limit**: yfinance returns ~4 quarters back. For deeper history use SEC EDGAR 10-Q parsing (future enhancement).
120- **Real-time vs delayed**: TwelveData is exchange-direct (low latency). yfinance has ~1 min lag during market hours. When they conflict, trust TwelveData.
121- **Institutional holders staleness**: 13F filings lag 45 days after quarter-end. `Date Reported` field tells you the as-of date.
122- **News provider IDs change**: yfinance's `news` schema occasionally adds/removes fields. The skill normalizes to `{title, summary, publisher, pub_date, url, type}`.
123- **Options data weight**: `get_options_expirations` is fast but fetching the full chain (Calls/Puts at each strike) requires per-expiry calls — not exposed yet to keep this skill light.
124
125## Output Style for User-Facing Replies
126
127Telegram users want plain text, no markdown. Follow these conventions:
128
129- Market cap: `$3.91T` (万亿 = T, 十亿 = B, 百万 = M)
130- Shares: `14.69B 股`
131- Ratios: `+2.34%` (sign required), `PE 36.2`, `Beta 1.07`
132- Holders: `贝莱德 (BlackRock) 7.32%`
133- Always cite source at end: `数据来源:TwelveData + Yahoo Finance (yfinance),非投资建议`
134
135## Future Enhancements (not implemented)
136
137- SEC EDGAR 13F deep dive (top N positions over multiple quarters)
138- Form 4 raw filings with explicit transaction type (P/S/A/D codes)
139- Pre/post-market quote (TwelveData supports `prepost=True` — exposed via `get_realtime_quote` if needed)
140- Options chain greeks (requires per-expiry × per-strike calls)