jackwener/OpenCLI · error · EmptyResultError

xueqiu/kline

Error message

xueqiu/kline

What it means

The xueqiu kline command requests daily candlestick data from stock.xueqiu.com/v5/stock/chart/kline.json for a given symbol. If the response contains no data.item array entries (empty kline series), it throws EmptyResultError('xueqiu/kline', ...) with a hint to verify the symbol. This distinguishes an authenticated-but-empty response from an auth failure.

Source

Thrown at clis/xueqiu/kline.js:29

    args: [
        {
            name: 'symbol',
            required: true,
            positional: true,
            help: '股票代码,如 SH600519、SZ000858、AAPL',
        },
        { name: 'days', type: 'int', default: 14, help: '回溯天数(默认14天)' },
    ],
    columns: ['date', 'open', 'high', 'low', 'close', 'volume'],
    func: async (page, kwargs) => {
        await page.goto('https://xueqiu.com');
        const symbol = String(kwargs.symbol).toUpperCase();
        const days = kwargs.days;
        const beginTs = Date.now();
        const url = `https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=${encodeURIComponent(symbol)}&begin=${beginTs}&period=day&type=before&count=-${days}`;
        const d = await fetchXueqiuJson(page, url);
        if (!d.data?.item?.length)
            throw new EmptyResultError('xueqiu/kline', '请确认股票代码是否正确: ' + symbol);
        const columns = d.data.column || [];
        const colIdx = {};
        columns.forEach((name, i) => { colIdx[name] = i; });
        return d.data.item.map(row => ({
            date: colIdx.timestamp != null ? formatChinaDate(row[colIdx.timestamp]) : null,
            open: row[colIdx.open] ?? null,
            high: row[colIdx.high] ?? null,
            low: row[colIdx.low] ?? null,
            close: row[colIdx.close] ?? null,
            volume: row[colIdx.volume] ?? null,
            percent: row[colIdx.percent] ?? null,
            symbol,
        }));
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify the symbol on xueqiu.com and use the correct prefixed format (e.g. SH600519, SZ000001, HK00700)
  2. Check the error's detail message, which includes the exact symbol that was queried
  3. Confirm the stock is actively listed and has daily history for the requested days
  4. Try a smaller days value to rule out a range issue, though symbol is the usual culprit

Example fix

// before
kline --symbol 600519
// after
kline --symbol SH600519
Defensive patterns

Strategy: validation

Validate before calling

const SYMBOL_RE = /^(SH|SZ|HK|US)?[0-9A-Za-z.]{4,10}$/;
const symbol = String(kwargs.symbol || '').toUpperCase().trim();
if (!SYMBOL_RE.test(symbol)) {
  throw new Error(`Invalid xueqiu symbol format: '${symbol}' (expected e.g. SH600519, SZ000001, HK00700)`);
}

Try / catch

try {
  const k = await xueqiuKline({ symbol: 'SH600519', days: 30 });
} catch (e) {
  if (/EmptyResultError|xueqiu\/kline/.test(e.message)) {
    console.error(`No kline data — check the symbol format: ${e.message}`);
  } else if (/AuthRequiredError/.test(e.message)) {
    console.error('Log in to xueqiu.com and retry.');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling kline with a symbol that xueqiu doesn't recognize (bad format, wrong market prefix, delisted code), or a symbol that exists but has no daily kline data for the requested count/days window.

Common situations: Using a bare code like '600519' without market prefix when needed (e.g. SH600519/SZ000001); typo'd or invented tickers; querying a delisted or newly listed stock with no history; non-A-share codes not supported by this endpoint.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


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