jackwener/OpenCLI · error · CommandExecutionError

Failed to fetch quote for ${symbol}

Error message

Failed to fetch quote for ${symbol}

What it means

The yahoo-finance quote command tries two strategies inside the page: the v8 chart API and DOM scraping of the quote page ([data-testid="qsp-price"]). If both fail, the page.evaluate returns {error: 'Could not fetch quote for SYM'} (or null) and the wrapper throws CommandExecutionError. The library throws this because it could not obtain any price data for the requested ticker — usually the symbol does not exist, was delisted, or Yahoo served a page without the expected markup.

Source

Thrown at clis/yahoo-finance/quote.js:71

        const titleEl = document.querySelector('title');
        const priceEl = document.querySelector('[data-testid="qsp-price"]');
        const changeEl = document.querySelector('[data-testid="qsp-price-change"]');
        const changePctEl = document.querySelector('[data-testid="qsp-price-change-percent"]');
        if (priceEl) {
          return {
            symbol: sym,
            name: titleEl ? titleEl.textContent.split('(')[0].trim() : sym,
            price: priceEl.textContent.replace(/,/g, ''),
            change: changeEl ? changeEl.textContent : null,
            changePercent: changePctEl ? changePctEl.textContent : null,
            open: null, high: null, low: null, volume: null, marketCap: null,
          };
        }
        return {error: 'Could not fetch quote for ' + sym};
      })()
    `);
        if (!data || data.error)
            throw new CommandExecutionError(data?.error || `Failed to fetch quote for ${symbol}`);
        return [data];
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify the ticker symbol exists on finance.yahoo.com and retry with the correct symbol
  2. Open the finance.yahoo.com quote page in the CLI browser and complete any consent/captcha interstitial, then retry
  3. Retry later if Yahoo rate-limited the v8 chart API (429)
  4. If the DOM selectors are outdated, update the [data-testid=...] selectors to Yahoo's current markup

Example fix

// before
await page.goto(`https://finance.yahoo.com/quote/${symbol}/`);
const data = await page.evaluate(...); // both strategies fail for bad symbol
// after (pre-validate symbol via chart API status)
const resp = await fetch(`https://query1.finance.yahoo.com/v8/finance/chart/${symbol}?interval=1d&range=1d`);
if (resp.status === 404) throw new CommandExecutionError(`Unknown symbol: ${symbol}`);
Defensive patterns

Strategy: validation

Validate before calling

if (!/^[A-Z0-9.\-]{1,10}$/i.test(symbol)) throw new Error(`Invalid ticker format: ${symbol}`);

Type guard

function isQuoteData(d) { return d != null && typeof d === 'object' && !('error' in d) && d.price != null; }

Try / catch

try {
  const [quote] = await yahooQuote(symbol);
} catch (e) {
  if (e instanceof CommandExecutionError && e.message.includes('fetch quote')) {
    return { error: 'QUOTE_UNAVAILABLE', symbol, hint: 'Verify the ticker exists on finance.yahoo.com' };
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling `yahoo-finance quote <SYMBOL>` where the v8 chart API returns non-ok or empty chart.result AND the quote page has no qsp-price element — invalid/delisted ticker, Yahoo consent/anti-bot page, or Yahoo DOM redesign breaking the selectors.

Common situations: Typo in ticker symbol (e.g. lowercase handled, but nonexistent like 'ZZZZZ'); delisted or OTC symbol not on Yahoo; Yahoo showing GDPR/consent interstitial; Yahoo changed their page markup so data-testid selectors no longer match; query1 API blocked (429).

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/475786249c851e63. Report an issue: GitHub.