Skip to content

feat(sync): add per-ticker sync mode with relay/proxy API support + data coverage check - #5

Open
827346462 wants to merge 2 commits into
zer0quant:mainfrom
827346462:feat/ticker-mode-sync
Open

feat(sync): add per-ticker sync mode with relay/proxy API support + data coverage check#5
827346462 wants to merge 2 commits into
zer0quant:mainfrom
827346462:feat/ticker-mode-sync

Conversation

@827346462

Copy link
Copy Markdown

Overview

Two features that together solve the problem of syncing data through relay/proxy APIs that don't support the standard Tushare date-range query pattern.

1. Data Coverage Check (Quality Rule)

Adds check_coverage() rule that validates all expected ETF/stock codes are present in each daily partition:

  • FAIL (< 80% coverage)
  • WARN (80-95% coverage)
  • WARN (missing well-known ETF like 510300.SH)

Integrates into _check_frame for fund_daily and daily_kline targets.

2. Per-Ticker Sync Mode (--ticker-mode)

Adds a new TickerSyncJob that syncs data by iterating over ETF tickers instead of trading dates. This is needed when the data source:

  • Is a relay API that authenticates via X-API-Key header instead of body token
  • Only supports per-ticker date-range queries (not per-date bulk queries)

Architecture

  • _ProxiedDataApi: Tushare DataApi-compatible client using requests.Session with X-API-Key auth, trust_env=False, and empty proxies
  • TushareFetcher: accepts optional proxy_url; auto-selects between standard ts.pro_api() and _ProxiedDataApi based on URL pattern
  • TickerSyncJob: iterates ETF codes from etf_basic, fetches date range per ticker, writes daily partitions with dedup
  • CLI: --ticker-mode flag activates per-ticker sync path

Config

[tushare]
token = "your_token"
proxy_url = "https://your-relay.example.com/tushare/pro"  # optional, for relay/proxy APIs

No breaking changes — existing users without proxy_url continue using the standard ts.pro_api().

Testing

  • Ticker-mode sync verified: 1671 ETFs × full-year data through relay
  • Coverage check verified: correctly detects missing dates from otherwise healthy store

Add check_coverage rule that validates all expected ETF/stock codes
are present in each daily partition. Uses the basic reference table
(list_date/delist_date) to compute expected codes per date.

- New rule: check_coverage() in rules.py with severity tiers:
  - FAIL (<80% coverage)
  - WARN (80-95% coverage)
  - WARN (missing well-known ETF like 510300.SH)
- New method: _expected_codes_for_date() in runner.py
- Integrated into _check_frame for fund_daily and daily_kline targets
- Well-known ETF codes (510300, 510050, 159915, etc.) trigger WARN
  even when coverage is above 95%
Add TickerSyncJob that iterates over ETF tickers instead of trading
dates, enabling sync through relay/proxy APIs that only support
per-ticker date-range queries.

Key changes:
- New _ProxiedDataApi class: Tushare DataApi-compatible client using
  X-API-Key header auth + proxy-free session for relay endpoints
- TushareFetcher accepts optional proxy_url; auto-selects between
  standard pro_api and _ProxiedDataApi based on URL pattern
- New fetch_fund_daily_range(ts_code, start, end) method for
  per-ticker queries
- New get_etf_codes() helper returning sorted ETF list from etf_basic
- TickerSyncJob: iterates tickers, fetches date range per ticker,
  writes daily partitions with dedup
- Pipeline build_registry accepts ticker_mode flag; etf module
  conditionally creates TickerSyncJob vs DailySyncJob
- CLI: '--ticker-mode' flag activates per-ticker sync path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant