wtfutil/wtf · error
yfinance: API error for symbol %q: %v
Error message
yfinance: API error for symbol %q: %v
What it means
Yahoo Finance chart responses wrap application-level errors in a chart.error JSON object even when the HTTP status is 200. fetchChartMeta surfaces that nested error (as %v of the parsed error struct) with the symbol for context.
Source
Thrown at modules/stocks/yfinance/yquote.go:88
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; wtf-yfinance/1.0)")
resp, err := httpClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("yfinance: unexpected status %d for symbol %q", resp.StatusCode, symbol)
}
var parsed chartResponse
if err := json.NewDecoder(resp.Body).Decode(&parsed); err != nil {
return nil, err
}
if parsed.Chart.Error != nil {
return nil, fmt.Errorf("yfinance: API error for symbol %q: %v", symbol, parsed.Chart.Error)
}
if len(parsed.Chart.Result) == 0 {
return nil, fmt.Errorf("yfinance: no results for symbol %q", symbol)
}
return &parsed.Chart.Result[0].Meta, nil
}
// marketState determines whether the quote is trading pre-market, in the
// regular session, post-market, or closed, based on the trading period
// windows Yahoo reports for the current day.
func marketState(periods tradingPeriods) string {
now := time.Now().Unix()
switch {
case now < periods.Pre.Start:
return "CLOSED"View on GitHub (pinned to bb838c1ccb)
Solutions
- Read the wrapped %v message — it names the actual Yahoo-side problem
- Validate the symbol against Yahoo Finance's website search
- Fix symbol formatting in config (e.g. use the exact Yahoo notation like BRK-B, ^GSPC)
- Add retry/backoff if the message indicates a transient Yahoo error
Example fix
// before
client.GetQuote("INVALID SYMBOL WITH SPACES")
// after
client.GetQuote("AAPL") Defensive patterns
Strategy: validation
Validate before calling
valid, _ := regexp.MatchString(`^[A-Za-z0-9^.\-=]+$`, symbol)
if !valid || symbol == "" { return errors.New("invalid symbol format") } Type guard
func hasChartError(cr chartResponse) bool { return cr.Chart.Error != nil } Try / catch
meta, err := fetchChartMeta(symbol)
if err != nil && strings.HasPrefix(err.Error(), "yfinance: API error") {
log.Printf("Yahoo rejected symbol %q: %v", symbol, err)
} Prevention
- Use exact Yahoo Finance symbol notation (BRK-B, ^GSPC) in config
- URL-escape symbols before building the request URL
- Check chart.error before dereferencing chart.result
- Test each configured symbol once at startup and log failures early
When it happens
Trigger: HTTP 200 response whose JSON body contains chart.error non-null — typically "Invalid input - symbol=xxx" for malformed or unknown symbols, or Yahoo-side errors returned in-band.
Common situations: Typo'd ticker symbols in widget config; symbols with special characters not URL-escaped; Yahoo flagging exchange/symbol combinations as invalid; expired/changed symbol listings.
Related errors
AI-assisted analysis of wtfutil/wtf@bb838c1ccb (2026-09-03).
Data as JSON: /api/errors/89a88aa5d146b034.
Report an issue: GitHub.