When the xq_a_token cookie expires, Xueqiu does not return an error. It returns an empty array.
HTTP 200. error_code: 0. data present but hollow. Your loop iterates zero times, writes zero rows, exits cleanly, and your monitoring reports a successful run with no items — which is the same green check you get on a good day. I have had that state persist for six days on a job nobody was watching, and the only reason I caught it was that a chart went flat.
The cold-start failure is a different shape, and knowing both saves time. A request with no cookie at all comes back 400 with an empty body. Not a captcha, not a ban. The quote endpoint simply wants a token that the homepage plants on first contact.
import requests UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " "(KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36") class Xueqiu: def __init__(self): self.s = requests.Session() self.s.headers.update({ "User-Agent": UA, "Accept": "application/json, text/plain, */*", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8", }) def prime(self): """One homepage hit is enough to get xq_a_token planted.""" self.s.get("https://xueqiu.com/", timeout=20) if "xq_a_token" not in self.s.cookies: raise RuntimeError("no xq_a_token — cookie bootstrap failed") def quote(self, symbol): self.prime() r = self.s.get("https://stock.xueqiu.com/v5/stock/quote.json", params={"symbol": symbol, "extend": "detail"}, headers={"Referer": "https://xueqiu.com/"}, timeout=20) q = (r.json().get("data") or {}).get("quote") if not q: raise RuntimeError(f"no quote for {symbol} — bad symbol format?") return q xq = Xueqiu() q = xq.quote("SH600519") print(q["name"], q["current"], q["pe_ttm"]) # 贵州茅台 1472.36 22.402 The raise on an empty quote is the important line. Without it, the expired-cookie case flows straight through as a None and lands in your database as a missing symbol rather than a broken session.
For a list of symbols, /v5/stock/batch/quote.json takes symbol=SH600519,SZ000001,.... I chunk at 20 per request; 25 also worked in testing, but I left headroom because one bad symbol in a batch costs you the whole chunk, and the error tells you nothing about which one it was.
What comes back
Real record, 平安银行, from a batch pulled on 2026-11-29:
{ "symbol": "SZ000001", "code": "000001", "name": "平安银行", "exchange": "SZ", "currency": "CNY", "market_status": "休市", "current": 12.23, "percent": -1.77, "chg": -0.22, "open": 12.45, "high": 12.47, "low": 12.13, "last_close": 12.45, "avg_price": 12.276, "amplitude": 2.73, "high_52w": 12.51, "low_52w": 9.7756, "ytd_percent": 13.14, "volume": 212240760.0, "amount": 2605535116.6, "turnover_rate": 1.09, "volume_ratio": 1.12, "market_capital": 237334379562.0, "float_market_capital": 237331527440.0, "total_shares": 19405918198.0, "float_shares": 19405684991.0, "lot_size": 100.0, "pe_ttm": 5.458, "pe_lyr": 5.567, "pe_forecast": 4.542, "pb": 0.498, "eps": 2.24, "navps": 24.56, "dividend_yield": 4.98, "issue_date": "1991-04-02T16:00:00+00:00", "quoted_at": "2026-11-27T07:34:12+00:00", "url": "https://xueqiu.com/S/SZ000001" } 40 fields on the normalized record; the raw payload carries 63 keys with extend=detail.
The three PE variants are why this endpoint is worth a cookie at all. pe_ttm 5.458 is trailing twelve months, pe_lyr 5.567 is last year, pe_forecast 4.542 is consensus forward. A bank at 0.498 PB with a 4.98% dividend yield is a completely different object from a growth name, and a price feed cannot tell them apart.
navps is the free cross-check: 24.56 against a 12.23 price is the same 0.5 PB seen from the other side. When two of your own columns agree like that, the mapping is probably right. When they disagree, you have a field mix-up, and this endpoint is honest enough to let you catch it.
The 52-week columns tell the story
宁德时代 in the same batch: current 215.89, percent +5.71, low_52w 200.16, high_52w 467.0566, ytd_percent -40.08.
Read those four together. The day's low was also 200.16 — identical to low_52w — so the stock printed a fresh 52-week low that morning and then closed 5.71% up. Current price sits 54% below the 52-week high.
That is a different situation from a stock grinding sideways, and every number needed to see it arrived in one response. No joins, no history table.
The nuance: high_52w and low_52w are rolling values Xueqiu computes, not calendar-year ones. 平安银行's 12.51 high against a 12.23 current reads as "near the top of its range", while its ytd_percent of 13.14 says it started the year lower. Two different questions, two different columns. Mix them up and you build a screen that recommends buying a bank at its yearly high.
Symbol format is the biggest source of empty results
The API is strict and its failure is a plain null, not a message. What works:
| Input | Works? | Notes |
|---|---|---|
SH600519 | yes | prefix + 6 digits |
SZ000001 | yes | Ping An Bank |
SH000001 | yes | Shanghai Composite Index |
000001 | no | ambiguous, endpoint returns nothing useful |
HK00700 | no | Tencent wants bare 00700 |
00700 | yes | Hong Kong, 5 digits, no prefix |
AAPL | yes | US, bare ticker |
HK00700 is the one that bit me. It looks correct — every other market in this API takes a prefix — and it returns null with no error, so the record just does not exist and nothing complains.
import re def normalize(raw): s = str(raw or "").strip().upper().replace(" ", "") if re.fullmatch(r"(SH|SZ|BJ)\d{6}", s): return s m = re.fullmatch(r"HK(\d{1,5})", s) if m: return m.group(1).zfill(5) # HK00700 -> 00700 if re.fullmatch(r"\d{5}", s): return s if re.fullmatch(r"\d{6}", s): # A-share prefix from the first digit: 6/9 = Shanghai, 4/8 = Beijing return ("SH" if s[0] in "69" else "BJ" if s[0] in "48" else "SZ") + s return s # US tickers pass through Guessing the prefix from the first digit is a convenience, not a truth. 000001 exists on both exchanges — index on Shanghai, bank on Shenzhen. If the input came from a human, ask which one they meant instead of guessing.
The closed-market trap
Every record in that batch carried market_status: "休市". The run happened on a Sunday, so all of it is Friday's close, and quoted_at values spread from 2026-11-27T07:00:00Z to 2026-11-27T07:34:57Z — per symbol, not per run.
Two consequences, and the second one is the expensive one.
A "live price" alert has to check market_status first, or you page someone at 2am about a move that happened two days ago. And any time-series table has to use quoted_at as the event time. Use your own scraped_at and you record five different market states as if they were simultaneous, which is how a moving-average signal fires twice on the same tick.
The uptime check is the sneaky part: on a Sunday, every request succeeds and every number is stale. A health check that only asserts HTTP 200 passes happily on a market that has been shut for 48 hours.
This logic is packaged as Xueqiu Stock Scraper on Apify: quote and K-line modes, A-share / HK / US, one 40-field schema, with the empty-array case treated as a re-prime rather than a success.
Next step: run normalize("000001"), look at what it returns, and decide whether your pipeline should guess or reject. Then call the batch endpoint with four symbols whose prices you already know and diff them against your broker app. If they match to the fen, your cookie and your symbol format are both correct.