ZhuLinsen/daily_stock_analysis · error · DataFetchError

TickFlow API key is not configured

Error message

TickFlow API key is not configured

What it means

DataFetchError raised in TickFlowFetcher._fetch_raw_data when _get_client() returns None, i.e. no TickFlow API key is configured in the environment (the client cannot be built without credentials). It fails after the symbol check and cache lookup but before any request is attempted.

Source

Thrown at data_provider/tickflow_fetcher.py:183

            if self._client is None:
                self._client = self._build_client()
            return self._client

    def _fetch_raw_data(
        self, stock_code: str, start_date: str, end_date: str
    ) -> pd.DataFrame:
        symbol = self._to_tickflow_symbol(stock_code)
        if not symbol:
            raise DataFetchError("TickFlowFetcher only supports A-share/ETF symbols")

        cache_key = self._daily_cache_key(symbol, start_date, end_date)
        cached = self._get_daily_cache(cache_key)
        if cached is not None:
            return cached

        client = self._get_client()
        if client is None:
            raise DataFetchError("TickFlow API key is not configured")

        request_count = self._daily_kline_count(start_date, end_date)
        try:
            df = client.klines.get(
                symbol,
                period="1d",
                count=request_count,
                start_time=self._date_to_ms(start_date),
                end_time=self._date_to_ms(end_date, end_of_day=True),
                adjust=self.kline_adjust,
                as_dataframe=True,
            )
        except Exception as exc:
            raise DataFetchError(f"TickFlow daily K-line request failed: {exc}") from exc

        raw_df = self._prepare_daily_frame(
            df,
            symbol=symbol,

View on GitHub (pinned to 5159bd72e8)

Solutions

  1. Set the TickFlow API key in the runtime environment (and mirror it in .env.example).
  2. Skip registering TickFlowFetcher in the provider chain when the key is absent, so requests route to keyless providers.
  3. Add a startup credential probe that logs which providers are enabled.

Example fix

# before
df = tickflow_fetcher.get_stock_data("600519", start, end)  # DataFetchError: key not configured

# after
# .env: TICKFLOW_API_KEY=...
if tickflow_fetcher._get_client() is not None:
    df = tickflow_fetcher.get_stock_data("600519", start, end)
else:
    df = akshare_fetcher.get_stock_data("600519", start, end)
Defensive patterns

Strategy: validation

Validate before calling

import os

if not os.getenv("TICKFLOW_API_KEY"):
    logger.info("TickFlow key absent; provider disabled")
    # do not register TickFlowFetcher in the chain

Try / catch

try:
    df = tickflow_fetcher.get_stock_data(code, start, end)
except DataFetchError as e:
    if "API key is not configured" in str(e):
        df = akshare_fetcher.get_stock_data(code, start, end)
    else:
        raise

Prevention

When it happens

Trigger: Any daily-K-line fetch via TickFlowFetcher when the TICKFLOW_API_KEY (or equivalent env/config) is absent, empty, or failed validation during _build_client.

Common situations: New deployment missing the TickFlow key in .env; key present in a different environment (local vs CI vs Docker); key removed or renamed without updating .env.example and deployment docs.

Related errors


AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15). Data as JSON: /api/errors/3e7f3de676268155. Report an issue: GitHub.