fix(HEL-356): support Beijing exchange realtime quotes

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
总管
2026-09-09 11:36:01 +08:00
co-authored by multica-agent
parent cb45d742da
commit abee8306be
5 changed files with 27 additions and 9 deletions
+11 -5
View File
@@ -128,13 +128,19 @@ class EastmoneyAdapter(MarketAdapter):
def fetch_quotes(self, codes: list[str]) -> list[dict[str, Any]]:
# Eastmoney ulist.np accepts ~60 secids per request; page remaining codes.
secids = []
suffixes: dict[str, str] = {}
for code in codes:
ts = str(code or "").upper()
symbol = ts.split(".")[0]
if ts.endswith(".SH") or symbol.startswith(("5", "6", "9")):
if ts.endswith(".BJ") or symbol.startswith(("4", "8", "92")):
secids.append(f"0.{symbol}")
suffixes[symbol] = "BJ"
elif ts.endswith(".SH") or symbol.startswith(("5", "6", "9")):
secids.append(f"1.{symbol}")
suffixes[symbol] = "SH"
else:
secids.append(f"0.{symbol}")
suffixes[symbol] = "SZ"
if not secids:
return []
result: list[dict[str, Any]] = []
@@ -154,7 +160,7 @@ class EastmoneyAdapter(MarketAdapter):
symbol = str(row.get("f12") or "")
if not symbol:
continue
ts_code = f"{symbol}.SH" if symbol.startswith(("5", "6", "9")) else f"{symbol}.SZ"
ts_code = f"{symbol}.{suffixes.get(symbol, 'SZ')}"
epoch = int(finite_number(row.get("f124")) or 0)
close = round4(finite_number(row.get("f2")))
previous = round4(finite_number(row.get("f18")))
@@ -462,10 +468,10 @@ def _normalize_market_quote(row: dict[str, Any]) -> dict[str, Any] | None:
if close <= 0 or previous_close <= 0:
return None
market = int(finite_number(row.get("f13")) or 0)
if market == 1 or symbol.startswith(("5", "6", "9")):
ts_code = f"{symbol}.SH"
elif symbol.startswith(("4", "8")):
if market == 0 and symbol.startswith(("4", "8", "92")):
ts_code = f"{symbol}.BJ"
elif market == 1 or symbol.startswith(("5", "6", "9")):
ts_code = f"{symbol}.SH"
else:
ts_code = f"{symbol}.SZ"
epoch = int(finite_number(row.get("f124")) or 0)
+2 -2
View File
@@ -158,10 +158,10 @@ def _tencent_symbol(code: str) -> str:
symbol = raw.split(".")[0]
if not symbol.isdigit() or len(symbol) != 6:
return ""
if raw.endswith(".BJ") or symbol.startswith(("4", "8", "92")):
return f"bj{symbol}"
if raw.endswith(".SH") or symbol.startswith(("5", "6", "9")):
return f"sh{symbol}"
if raw.endswith(".BJ") or symbol.startswith(("4", "8")):
return f"bj{symbol}"
return f"sz{symbol}"
@@ -616,6 +616,8 @@ def _guess_ts_code(code: str) -> str | None:
if "." in raw:
return raw
if len(raw) == 6 and raw.isdigit():
if raw.startswith(("4", "8", "92")):
return f"{raw}.BJ"
if raw.startswith(("5", "6", "9")):
return f"{raw}.SH"
return f"{raw}.SZ"
+1 -1
View File
@@ -192,7 +192,7 @@ class V1API:
limit, offset = self._page(q)
today = yyyymmdd(now_shanghai())
batch_id, snapshot = self.pipeline.published_stock_snapshot(today)
if batch_id:
if batch_id and snapshot:
# Formal view: the latest published stock snapshot, with batch
# metadata. Filters are applied in-memory on the snapshot.
pub = self.pipeline.latest_stocks_publication(today) or {}