SuperAPI AI Directory

market-data

Data & analytics

View repository

Updated 10-16 10:29

About this skill

HK+US data capabilities

Objective

Pull data directly with Python scripts, without relying on MCP. Runs by default without a password, and provides a multi-channel fallback strategy.

Table of Contents

  • scripts/fetch_realtime_hkus.py
  • scripts/fetch_history_hkus.py
  • scripts/fetch_technical_hkus.py
  • scripts/fetch_fundamental_hkus.py
  • scripts/fetch_sector_hkus.py
  • scripts/fetch_macro_us.py
  • scripts/fetch_universe_hkus.py
  • scripts/fetch_market_realtime_hkus.py
  • scripts/healthcheck_sources.py

Install dependencies

pip3 install yfinance pandas numpy requests pandas_datareader yahooquery pytest

Code conventions

  • US codes are uniformly output as EXCHANGE:TICKER, e.g. NASDAQ:AAPL
  • HK codes are uniformly output as NNNN.HK, e.g. 0700.HK
  • Results uniformly include:
    • source_primary
    • source_actual
    • fallback_used
    • fallback_chain

Channel priority

US / HK (quotes and K-lines)

  • Real-time:tencent_quote -> sina_quote -> yahooquery_realtime -> yfinance -> yahoo_chart
  • Historical/technical:tencent_history -> sina_history -> yfinance -> yahooquery_history -> yahoo_chart

Tencent and Sina both distinguish HK/US codes. For real-time use usAAPL / hk00700; for K-lines use fqkline/get, U.S. stocks need an exchange suffix (e.g. usAAPL.OQ、usJPM.N、usSPY.AM, automatically parsed by qt quotes). Minute K-lines for HK stocks use minute/query; for U.S. stocks during market hours only the current minute snapshot is returned, and historical minutes fall back to Yahoo. Real-time results include market_state and premarket; during market hours, if the primary source does not include pre-market, Yahoo is used to fill it in.

Other

  • Fundamentals (US):yfinance -> yahooquery
  • Macro:fred_reader -> fred_csv

Quick commands

# 实时
python3 scripts/fetch_realtime_hkus.py --symbol AAPL --json
python3 scripts/fetch_realtime_hkus.py --batch AAPL,TSLA,0700.HK --json

# 历史
python3 scripts/fetch_history_hkus.py --symbol AAPL --interval 1d --days 180 --json
python3 scripts/fetch_history_hkus.py --batch AAPL,MSFT,0700.HK --workers 8 --json

# 技术
python3 scripts/fetch_technical_hkus.py AAPL --days 180 --interval 1d --json

# 基本面
python3 scripts/fetch_fundamental_hkus.py --symbol AAPL --json

# 行业与ETF
python3 scripts/fetch_sector_hkus.py --sector-name 半导体 --days 60 --json
python3 scripts/fetch_sector_hkus.py --symbol 0700.HK --json

# 美国宏观
python3 scripts/fetch_macro_us.py --interest-rates --days 365 --json
python3 scripts/fetch_macro_us.py --inflation-employment --months 36 --json
python3 scripts/fetch_macro_us.py --economic-growth --quarters 24 --json

# 渠道健康检查
python3 scripts/healthcheck_sources.py --us-symbol AAPL --hk-symbol 0700.HK

# 拉全市场股票清单
python3 scripts/fetch_universe_hkus.py --market all --json
python3 scripts/fetch_universe_hkus.py --market us --json
python3 scripts/fetch_universe_hkus.py --market hk --json

# 拉市场当前交易数据(可全市场)
python3 scripts/fetch_market_realtime_hkus.py --market all --universe-limit 800 --top 200 --json
python3 scripts/fetch_market_realtime_hkus.py --market us --universe-limit 1000 --top 100 --sort volume_desc --json
python3 scripts/fetch_market_realtime_hkus.py --symbols NASDAQ:AAPL,NYSE:MSFT,0700.HK --json

Output rules

  • By default outputs a brief summary
  • With --json outputs the full structure
  • If both primary and backup sources fail, return the error identifier source_unavailable