ZhuLinsen/daily_stock_analysis · warning · RuntimeError

Longbridge temporarily unavailable for daily_data

Error message

Longbridge temporarily unavailable for daily_data

What it means

LongbridgeFetcher._fetch_raw_data guards on is_available_for_request('daily_data') and raises RuntimeError when its internal availability/circuit-breaker state says the source is temporarily down for that capability (e.g. consecutive recent failures or missing credentials made the fetcher mark itself unavailable). It is a skip-now signal, not a permanent failure.

Source

Thrown at data_provider/longbridge_fetcher.py:873

            circ_mv=circ_mv,
        )

        logger.info(
            f"[Longbridge] {symbol} 行情获取成功: "
            f"价格={price}, 量比={volume_ratio}, 换手率={turnover_rate}"
        )
        return quote

    # ------------------------------------------------------------------
    # BaseFetcher abstract methods (historical daily data)
    # ------------------------------------------------------------------

    def _fetch_raw_data(
        self, stock_code: str, start_date: str, end_date: str
    ) -> pd.DataFrame:
        """Fetch historical candlesticks from Longbridge."""
        if not self.is_available_for_request("daily_data"):
            raise RuntimeError("Longbridge temporarily unavailable for daily_data")

        symbol = _to_longbridge_symbol(stock_code)
        if symbol is None:
            raise ValueError(f"Cannot convert {stock_code} to Longbridge symbol")

        ctx = self._get_ctx()
        if ctx is None:
            raise RuntimeError("Longbridge QuoteContext not available")

        from longbridge.openapi import Period, AdjustType

        start_dt = datetime.strptime(start_date, "%Y-%m-%d").date()
        end_dt = datetime.strptime(end_date, "%Y-%m-%d").date()

        try:
            candles = ctx.history_candlesticks_by_date(
                symbol,
                Period.Day,

View on GitHub (pinned to 5159bd72e8)

Solutions

  1. Wait for the availability window to reset (or restart the process) before retrying Longbridge for daily_data.
  2. Fail over to the next US/HK-capable source (Finnhub/AlphaVantage/YFinance) via DataFetcherManager — the chain already handles this.
  3. If it never becomes available, check Longbridge credentials/config so initialization marks the capability requestable.

Example fix

# before
if fetcher.is_available_for_request('daily_data') is not enforced at call site:
    df = fetcher.get_daily_data(code, ...)  # RuntimeError
# after
if fetcher.is_available_for_request('daily_data'):
    df = fetcher.get_daily_data(code, ...)
else:
    df = manager.get_daily_data(code, ...)  # failover chain
Defensive patterns

Strategy: fallback

Validate before calling

if fetcher.is_available_for_request('daily_data'):
    df = fetcher.get_daily_data(code, ...)
else:
    df = manager.get_daily_data(code, ...)  # chain skips unavailable sources

Try / catch

try:
    df = longbridge.get_daily_data(code, ...)
except RuntimeError as e:
    if 'temporarily unavailable' in str(e):
        df = manager.get_daily_data(code, ...)  # immediate failover; cooldown will reset

Prevention

When it happens

Trigger: Calling get_daily_data on LongbridgeFetcher after earlier Longbridge failures tripped the availability state for daily_data, or when initialization (credentials/context) did not complete, so is_available_for_request returns False.

Common situations: Failover loops that retry Longbridge too soon after an outage; process kept alive across rate-limit windows; Longbridge creds partially configured so the fetcher is registered but not requestable.

Related errors


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