Skip to content
Back to skills

2481 Readme Hk Daily 5ddf8c7f

ASecurity

This script fetches historical daily data for all HK stocks from Finnhub API and stores them in the ClickHouse database.

  • 9 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 11, 2026
databasesbashapidatabase

Works with

  • cli
  • api

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add tools-only/X-Skills --skill 2481-readme_hk_daily_5ddf8c7f --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 2481 Readme Hk Daily 5ddf8c7f?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 2481 Readme Hk Daily 5ddf8c7f
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-2481-readme-hk-daily-5ddf8c7f/badge)](https://www.skillsdirectory.com/skills/tools-only-2481-readme-hk-daily-5ddf8c7f)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

SKILL.md
# HK Stock Daily Data Fetch Script

This script fetches historical daily data for all HK stocks from Finnhub API and stores them in the ClickHouse database.

## Prerequisites

1. **Finnhub API Key**
   - Register at: https://finnhub.io/register
   - Get your free API key
   - Free tier: 60 calls/minute

2. **Database Setup**
   - Ensure ClickHouse is running
   - Ensure `ods_hk_basic` table is populated with HK stock list
   - Run: `uv run cli.py load-hk-basic` if needed

## Configuration

Add to your `.env` file:
```bash
FINNHUB_API_KEY=your_api_key_here
```

## Usage

### Fetch all HK stocks (1 year history)
```bash
uv run scripts/fetch_hk_daily_from_finnhub.py
```

### Fetch with custom date range
```bash
uv run scripts/fetch_hk_daily_from_finnhub.py --start-date 20240101 --end-date 20241231
```

### Test with limited stocks
```bash
uv run scripts/fetch_hk_daily_from_finnhub.py --max-stocks 10
```

### Dry run (test mode)
```bash
uv run scripts/fetch_hk_daily_from_finnhub.py --dry-run
```

## Features

- **Rate Limiting**: Strictly controls API calls to 60/minute
- **Error Handling**: Automatic retries (up to 3 times) with exponential backoff
- **Progress Tracking**: Real-time progress reports every 50 stocks
- **Data Quality**: Validates and maps Finnhub data to TuShare format
- **Resumable**: Can be stopped and restarted

## Output

Data is inserted into `ods_hk_daily` table with the following fields:
- ts_code: Stock code in TuShare format (e.g., 00001.HK)
- trade_date: Trading date (YYYYMMDD)
- open, high, low, close: Price data
- pre_close, change, pct_chg: Calculated fields
- vol: Volume
- amount: NULL (not available from Finnhub)

## Notes

1. **Rate Limit**: Free tier allows 60 calls/minute. The script respects this limit strictly.
2. **Time Estimate**: For ~2500 HK stocks at 60 calls/min, expect about 40-45 minutes.
3. **Missing Data**: Some stocks may not have data (newly listed, delisted, etc.)
4. **Amount Field**: Finnhub doesn't provide trading amount, so this field is NULL.

## Troubleshooting

### Error: FINNHUB_API_KEY not found
- Add `FINNHUB_API_KEY` to your `.env` file

### Error: No HK stocks found
- Run `uv run cli.py load-hk-basic` to populate stock list

### Rate limit errors
- The script automatically handles rate limits
- If errors persist, the script will retry up to 3 times

### Connection errors
- Check if ClickHouse is running
- Check database connection settings in `.env`

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.