U.S. market risk tracking dashboard based on the indicators discussed in the reference video:
- market breadth
- uptrend share
- distribution days
- XLY/XLP defensive rotation
- AI theme dispersion
- FINRA margin debt
- CBOE put/call ratio
The first version runs as a Vite React app plus a Hono API on Cloudflare Workers. D1 stores indicators, alerts, OHLCV bars, instruments, and ingestion runs.
npm install
npm run db:migrate:local
npm run dev:workerOpen:
http://localhost:8787The app defaults to demo data. To run the Vite-only frontend:
npm run devCreate a D1 database:
npx wrangler d1 create as-risk-traceCopy the returned database_id into wrangler.jsonc, then apply migrations:
npm run db:migrate:remoteSet production secrets:
npx wrangler secret put POLYGON_API_KEY
npx wrangler secret put FRED_API_KEY
npx wrangler secret put SEC_USER_AGENT
npx wrangler secret put INGEST_TOKENSwitch to live ingestion by changing this in wrangler.jsonc:
Deploy:
npm run deployGET /api/healthGET /api/dashboardPOST /api/ingest
If INGEST_TOKEN is configured, call manual ingestion with:
curl -X POST https://your-worker.example.workers.dev/api/ingest \
-H "Authorization: Bearer $INGEST_TOKEN"The dashboard has two data modes:
demo: reads static baseline data fromshared/demo.ts.live: stores fetched bars in Cloudflare D1, computes indicators inworker/index.ts, then serves the latest rows throughGET /api/dashboard.
Current live ingestion is intentionally narrow. It does not ingest every S&P 500 constituent yet.
| Area | Current source | Fetch method | Used for | Current limitation |
|---|---|---|---|---|
| Stock / ETF OHLCV | Polygon.io custom aggregate bars | GET /v2/aggs/ticker/{symbol}/range/1/day/{from}/{to} with POLYGON_API_KEY |
8D market breadth, uptrend share, distribution days, XLY/XLP regime, AI watchlist dispersion | Daily bars only in the current Worker implementation. Symbol universe is a small MVP basket. |
| Breadth symbols | Hard-coded list in DEFAULT_BREADTH_SYMBOLS |
Seeded into D1 by seedInstruments() |
Market breadth and uptrend share | This is a proxy basket, not licensed full-index breadth. |
| ETFs | SPY, QQQ, XLY, XLP |
Same Polygon daily bar fetch | Distribution days and discretionary/staples rotation | ETF proxy only. |
| AI watchlist | Hard-coded list in AI_WATCHLIST |
Same Polygon daily bar fetch | AI theme dispersion | Manual thematic basket. |
| FINRA margin debt | FINRA Margin Statistics | Official-source monitor adapter | FINRA margin debt card in the separate official-source block | FINRA states the official data is on the webpage / Excel download and that data feeds are not available. |
| CBOE put/call | Cboe U.S. Options Daily Market Statistics | Official-source monitor adapter | CBOE equity put/call card in the separate official-source block | Daily public statistic; intraday or full option-chain analytics require licensed options data. |
| OpenAI ecosystem page | User-supplied Morgan Stanley exhibit, with FT link as reference | Manually structured in src/openaiEcoData.ts |
/openai_eco capital-flow graph |
Not live market data; figures should be re-checked against primary filings / announcements before investment use. |
The dashboard also renders a separate "Free Official Source Monitor" block. These signals are stored in the same indicators table with official-* keys so they do not affect the composite risk score.
| Signal | Source | Adapter status | Notes |
|---|---|---|---|
official-finra-margin-debt |
FINRA Margin Statistics | Implemented | Parses the latest official monthly margin table. |
official-cboe-put-call |
Cboe Daily Market Statistics | Implemented | Parses the equity put/call ratio from Cboe's daily statistics page. |
official-fred-stress |
FRED API, series STLFSI4 |
Implemented with FRED_API_KEY |
FRED requires a free API key. Without the key, the UI shows Key required. |
official-sec-filings |
SEC EDGAR submissions API | Implemented | Tracks recent 8-K, 10-Q, and 10-K filings for the AI infrastructure watchlist. Set SEC_USER_AGENT to a real contact string for production. |
official-treasury-cash |
U.S. Treasury Fiscal Data Daily Treasury Statement | Implemented | Reads the Treasury General Account closing balance from the DTS API. |
This project currently uses Polygon.io, a financial market data API provider. It does not use Polymarket, and there is no Polymarket endpoint or dependency in the codebase.
Polymarket is a prediction-market site. It should not be treated as a primary data source for this dashboard's core market-risk indicators. At most, prediction-market prices could be added later as a separate sentiment / event-probability signal, clearly labeled as market-implied probability and kept separate from exchange, regulatory, and issuer data.
Recommended upgrade path, from simplest to most institutional:
| Need | Better source / product | Access pattern | Notes |
|---|---|---|---|
| More real-time OHLCV while keeping current vendor | Polygon Stocks WebSocket or minute / second aggregates | WebSocket stream for trades, quotes, minute bars, or second bars | Lowest-friction upgrade because the project already has Polygon auth. Real-time access depends on plan / exchange agreements. |
| Full-market breadth | Licensed S&P 500 constituent + GICS sector data from S&P Dow Jones Indices, Intrinio index constituents, Nasdaq Data Link, LSEG, Bloomberg, or FactSet | Scheduled reference-data ingestion plus OHLCV ingestion for all constituents | Needed to replace the current 20-stock proxy basket. GICS is licensed data; do not rely on scraped, stale constituent lists for production. |
| Official margin debt | FINRA Margin Statistics | Monthly parser for official table / Excel download | Official but not real-time. FINRA generally publishes monthly updates after the reference month. |
| Official put/call ratios | Cboe Daily Market Statistics; for higher-grade feeds use Cboe DataShop / OPRA-based options data vendors | Daily HTML/CSV parser now; licensed feed for intraday/pro use | Cboe's public page is fine for daily dashboarding. Intraday option sentiment needs a licensed options feed. |
| Exchange-authorized real-time equities | Nasdaq Basic, SIP CTA/UTP, IEX, Cboe One, or vendors such as Intrinio | REST snapshots and/or WebSocket | Better for display-grade or business use where licensing matters. |
| Enterprise-grade market data | Bloomberg B-PIPE, LSEG Data Platform / Real-Time, FactSet | Entitled enterprise feed / cloud delivery / API | Best quality and governance, but significantly higher cost and integration overhead. |
| Macro / financial conditions overlays | FRED API, Federal Reserve data, Treasury data | Scheduled REST ingestion | Useful for adding rates, credit spreads, liquidity and stress indicators; not a replacement for price/volume feeds. |
Approximate paid-data budget ranges as of May 2026:
| Upgrade | Public price signal | Practical expectation |
|---|---|---|
| Polygon Stocks Starter / Developer | Polygon lists $29/mo and $79/mo individual plans for delayed data and WebSockets. |
Good for personal or prototype intraday dashboards with 15-minute delayed data. |
| Polygon Stocks Advanced | Polygon lists $199/mo for individual real-time stocks. |
Cheapest path to real-time in this codebase, but marked for non-professional individual use; business redistribution needs a business plan. |
| Intrinio IEX / delayed SIP / Nasdaq Basic | Intrinio lists IEX real-time and 15-minute delayed SIP around $6,000/yr, Nasdaq Basic around $9,000/yr. |
Useful middle tier for business API/WebSocket access without building direct exchange feed infrastructure. |
| Intrinio OPRA options | Intrinio lists 15-minute delayed options around $9,600/yr and real-time OPRA options around $2,500/mo. |
Needed for richer option-chain / intraday put-call analytics. |
| Cboe One direct feed | Cboe lists Summary internal distribution at $1,500/mo, external distribution at $5,000/mo, Digital Media License at $15,000/mo; Premium is higher. |
Relevant if displaying or redistributing real-time U.S. equity data from Cboe venues. |
| Nasdaq Basic direct | Nasdaq describes per-user, enterprise, and digital media licensing; public pages emphasize pricing models rather than a single fixed API price. | Usually vendor quote / contract; can be cheaper than full SIP but still requires market-data licensing work. |
| Bloomberg B-PIPE / LSEG / FactSet enterprise | Bloomberg and LSEG are quote-based. Third-party procurement benchmarks often show five- to six-figure annual budgets for small teams and much higher for enterprise/API scope. | Overkill for this MVP unless you need institutional governance, broad asset coverage, redistribution controls, and enterprise support. |
Practical next implementation steps:
- Replace
DEFAULT_BREADTH_SYMBOLSwith a licensed / maintained S&P 500 constituent and sector source. - Upgrade Polygon ingestion from daily REST polling to WebSocket or minute-bar polling if intraday freshness is required.
- Store richer source metadata per indicator: vendor, endpoint, fetch time, source timestamp, and license notes.
已接的免费官方源:
- FINRA Margin Statistics:月度保证金债务
- Cboe Daily Market Statistics:Equity Put/Call
- FRED STLFSI4:金融压力指数,需要 FRED_API_KEY
- SEC EDGAR:AI watchlist 近期 8-K / 10-Q / 10-K
- U.S. Treasury Fiscal Data:TGA 现金余额
需要补两个 secret:
npx wrangler secret put FRED_API_KEY npx wrangler secret put SEC_USER_AGENT
SEC_USER_AGENT 建议用真实联系信息,例如:ASRiskTrace/0.1 your- email@example.com。
价格大概
- Polygon:$29/月、$79/月 是延迟/开发级;实时股票个人非专业版约 $199/月。
- Intrinio:IEX 实时或 15 分钟 delayed SIP 大约 $6,000/年;Nasdaq Basic 大约 $9,000/年。
- OPRA 期权:15 分钟 delayed options 约 $9,600/年;实时 OPRA options 约 $2,500/月。
- Cboe One:Summary 内部分发约 $1,500/月,外部分发约 $5,000/月,Digital Media License 约 $15,000/月。
- Nasdaq Basic 直连、SIP、Bloomberg B-PIPE、LSEG、FactSet:通常 quote- based,实际会按用户数、展示/非展示、再分发、交易所授权来算;企业级一般进入 五位到六位数年费区间。
参考源:
- Polygon pricing: https://polygon.io/pricing
- Intrinio pricing: https://intrinio.com/pricing
- Cboe One pricing: https://www.cboe.com/market_data_services/us/equities/cboe_one/
- Nasdaq Basic: https://www.nasdaq.com/solutions/nasdaq-basic
- Bloomberg B-PIPE:
https://www.bloomberg.com/professional/products/data/enterprise-catalog/real-time-data-feed/
- LSEG market data:
https://www.lseg.com/en/data-analytics/financial-data/pricing-and-market-data