HKUDS/Vibe-Trading · error · TushareFallbackUnavailable
unsupported Tushare symbol: {code}
Error message
unsupported Tushare symbol: {code} What it means
_ts_code converts an exchange-agnostic stock code into Tushare's 'NNNNNN.SH/SZ/BJ' format. This first raise fires when the symbol already contains a dot but is malformed: the suffix is not SH/SZ/BJ, or the bare part is not exactly 6 digits. Examples: '600519.SS' (wrong suffix), 'AAPL.US', '60051.SH' (5 digits), '600519.SH.X'.
Source
Thrown at agent/src/tools/tushare_fallbacks.py:95
def _net_amount(row: dict[str, Any], buy_key: str, sell_key: str) -> float | None:
buy = _to_float(row.get(buy_key))
sell = _to_float(row.get(sell_key))
if buy is None and sell is None:
return None
# Tushare moneyflow amount fields are in 10k CNY; the Eastmoney tool emits
# CNY, so convert to keep the existing bucket units.
return ((buy or 0.0) - (sell or 0.0)) * 10_000
def _ts_code(code: str) -> str:
token = code.strip().upper()
if "." in token:
bare, suffix = token.split(".", 1)
if suffix in {"SH", "SZ", "BJ"} and len(bare) == 6 and bare.isdigit():
return f"{bare}.{suffix}"
raise TushareFallbackUnavailable(f"unsupported Tushare symbol: {code}")
for prefix in ("SH", "SZ", "BJ"):
if token.startswith(prefix):
token = token[len(prefix) :]
break
if len(token) != 6 or not token.isdigit():
raise TushareFallbackUnavailable(f"unsupported Tushare symbol: {code}")
if token.startswith(("5", "6", "9")):
suffix = "SH"
elif token.startswith(("0", "2", "3")):
suffix = "SZ"
elif token.startswith(("4", "8")):
suffix = "BJ"
else:
raise TushareFallbackUnavailable(f"unsupported Tushare symbol: {code}")
return f"{token}.{suffix}"
def fetch_fund_flow(symbol: str, *, days: int) -> dict[str, Any]:View on GitHub (pinned to 80ffdda44c)
Solutions
- Map '.SS' to '.SH' (and similar) before calling the fetchers
- Filter out non-A-share symbols (HK/US) before invoking Tushare fallbacks
- Strip the suffix and pass the bare 6-digit code, letting _ts_code infer the exchange from the leading digit
- Validate symbols against ^\d{6}\.(SH|SZ|BJ)$ before calling
Example fix
# before
fetch_fund_flow("600519.SS")
# after
fetch_fund_flow("600519.SH") # or just "600519" Defensive patterns
Strategy: type-guard
Validate before calling
import re
def valid_dotted_symbol(sym: str) -> bool:
return bool(re.fullmatch(r'\d{6}\.(SH|SZ|BJ)', sym.strip().upper())) Type guard
import re
from typing import TypeGuard
def is_tushare_symbol(sym: str) -> TypeGuard[str]:
s = sym.strip().upper()
return bool(re.fullmatch(r'(?:\d{6}\.(?:SH|SZ|BJ))|(?:(?:SH|SZ|BJ)?\d{6})', s)) Try / catch
try:
_ = fetch_fund_flow(sym, days=5)
except TushareFallbackUnavailable as exc:
if 'unsupported Tushare symbol' in str(exc):
logger.info('skipping non-A-share symbol %s', sym)
continue
raise Prevention
- Map vendor suffixes before calling: .SS -> .SH
- Filter HK/US tickers out of A-share pipelines
- Validate symbols with a regex before batch jobs so one bad code doesn't abort a loop
When it happens
Trigger: Calling fetch_fund_flow, fetch_dragon_tiger, or fetch_margin_trading with a dotted symbol whose exchange suffix is not one of SH/SZ/BJ (e.g. '.SS', '.US', '.HK') or whose numeric part isn't a 6-digit code (e.g. '60051.SH', '0700.HK').
Common situations: Feeding Yahoo-style suffixes (.SS for Shanghai instead of .SH); passing Hong Kong or US tickers into an A-share-only fallback; copy-pasting codes with typos or extra segments; codes normalized by another library that appends a different suffix.
Related errors
- invalid date for tushare fallback: {value!r}
- invalid alpha_id
- alpha_id not found
- invalid period: {exc}
- too many running benches; wait for one to finish
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/c228832fe6bebc4f.
Report an issue: GitHub.