A self-contained data toolkit providing real-time financial data and quantitative calculations for the Hong Kong stock market. All data sourcesfree,No API key required。
Installation
Install dependencies (one-time):
pip install -r requirements.txt
Available Tools
All scripts are located in the scripts/ directory. Run from the skill root directory.
1. Hong Kong stock quote data (scripts/hk_stock_data.py)
Obtain real-time Hong Kong stock quotes, historical data, and basic information.
| Command | Purpose |
|---|---|
python scripts/hk_stock_data.py 00700 |
Tencent Holdings basic information |
python scripts/hk_stock_data.py 00700 --price |
Real-time prices and historical data |
python scripts/hk_stock_data.py 00700 --financial |
Financial indicators and valuation data |
python scripts/hk_stock_data.py 00700 --dividend |
Dividend history and distribution information |
2. Southbound capital data (scripts/southbound_flow.py)
Obtain southbound capital flow and holdings data.
| Command | Purpose |
|---|---|
python scripts/southbound_flow.py --daily |
Daily southbound capital flow |
python scripts/southbound_flow.py --holdings |
Southbound capital holdings details |
python scripts/southbound_flow.py --sector |
Sector capital flow analysis |
python scripts/southbound_flow.py --top |
Net buy/sell TOP ranking |
3. Hong Kong stock financial data (scripts/hk_financials.py)
Obtain Hong Kong stock financial statements and financial indicators.
| Command | Purpose |
|---|---|
python scripts/hk_financials.py 00700 --income |
Income statement data |
python scripts/hk_financials.py 00700 --balance |
Balance sheet |
python scripts/hk_financials.py 00700 --cashflow |
Cash flow statement |
python scripts/hk_financials.py 00700 --ratios |
Financial ratio analysis |
4. Exchange rate data (scripts/fx_data.py)
Obtain Hong Kong dollar exchange rates and related data.
| Command | Purpose |
|---|---|
python scripts/fx_data.py HKD --spot |
Hong Kong dollar spot exchange rate |
python scripts/fx_data.py HKD --forward |
Forward exchange rate |
python scripts/fx_data.py HKD --history |
Historical exchange rate trends |
python scripts/fx_data.py HKD --volatility |
Exchange rate volatility |
5. Hong Kong stock macro data (scripts/hk_macro.py)
Obtain Hong Kong macroeconomic indicators.
| Command | Purpose |
|---|---|
python scripts/hk_macro.py --gdp |
GDP data |
python scripts/hk_macro.py --cpi |
CPI inflation data |
python scripts/hk_macro.py --unemployment |
Unemployment rate data |
python scripts/hk_macro.py --interest |
Interest rate data |
6. Hong Kong stock ETF data (scripts/hk_etf.py)
Obtain Hong Kong stock ETF-related data.
| Command | Purpose |
|---|---|
python scripts/hk_etf.py --list |
ETF list and basic information |
python scripts/hk_etf.py 02800 --holdings |
ETF holdings details |
python scripts/hk_etf.py 02800 --flow |
ETF capital flow |
python scripts/hk_etf.py --performance |
ETF performance analysis |
Data Source Description
Main Data Sources
- HKEX data: real-time quotes, historical data
- HKEXnews: company announcements, financial statements
- Hong Kong Monetary Authority: exchange rate, interest rate data
- Census and Statistics Department of Hong Kong: macroeconomic data
- Major brokerages: southbound capital data
Data Update Frequency
- Real-time data: updated in real time during trading hours
- Financial data: quarterly updates (quarterly reports), semi-annual updates (interim reports), annual updates (annual reports)
- Macro data: monthly, quarterly, annual updates
- Capital flow: Daily updates
Output Format
Standard Output Format
{
"symbol": "00700.HK",
"name": "腾讯控股",
"price": {
"current": 320.5,
"change": 5.2,
"change_pct": 1.65
},
"market_cap": 3072000000000,
"pe_ratio": 18.5,
"dividend_yield": 0.85,
"timestamp": "2026-02-15 16:00:00"
}
Financial Data Format
{
"symbol": "00700.HK",
"financials": {
"revenue": 560118000000,
"net_profit": 115219000000,
"eps": 12.0,
"roe": 0.156,
"debt_ratio": 0.234
},
"period": "2024Q3",
"currency": "HKD"
}
Error Handling
Common Errors
- Network Connection Issues: Check network connection
- Data Source Restrictions: Some data may have access restrictions
- Stock Code Errors: Ensure the correct Hong Kong stock code format is used
- Time Limits: Avoid overly frequent data requests
Error Message Examples
{
"error": "Invalid stock code",
"message": "Stock code 99999.HK not found",
"suggestion": "Please check the stock code format"
}
Usage Examples
Basic Usage
from scripts.hk_stock_data import get_stock_info
# 获取腾讯控股信息
info = get_stock_info("00700")
print(f"当前价格: {info['price']['current']} HKD")
print(f"市值: {info['market_cap']:,} HKD")
Batch Query
from scripts.southbound_flow import get_daily_flow
# 获取最近5天南向资金流向
for i in range(5):
flow_data = get_daily_flow(days_back=i)
print(f"第{i+1}天净流入: {flow_data['net_flow']:,} HKD")
Configuration Instructions
Environment Variables
# 可选:设置代理(如果需要)
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080
# 可选:设置缓存目录
export HK_DATA_CACHE=/path/to/cache
Configuration File
{
"data_sources": {
"hkex": {
"base_url": "https://www.hkex.com.hk",
"timeout": 30
},
"cache": {
"enabled": true,
"ttl": 300
}
}
}
Notes
- Data Delay: Real-time data may have slight delays
- Trading Hours: Hong Kong stock trading hours are 9:30-12:00, 13:00-16:00
- Currency Unit: All price data is in Hong Kong dollars (HKD)
- Stock Code: Use 5-digit codes, such as 00700 for Tencent Holdings
- Data Accuracy: It is recommended to cross-verify important data
Changelog
v1.0.0 (2026-02-15)
- Initial version released
- Supports basic Hong Kong stock data retrieval
- Southbound capital flow analysis
- Financial data query function
HK Market Data Toolkit - A professional Hong Kong stock data retrieval tool