{"record":{"id":"c228832fe6bebc4f","repo":"HKUDS/Vibe-Trading","slug":"unsupported-tushare-symbol-code","errorCode":null,"errorMessage":"unsupported Tushare symbol: {code}","messagePattern":"unsupported Tushare symbol: (.+?)","errorType":"validation","errorClass":"TushareFallbackUnavailable","httpStatus":null,"severity":"error","filePath":"agent/src/tools/tushare_fallbacks.py","lineNumber":95,"sourceCode":"\n\ndef _net_amount(row: dict[str, Any], buy_key: str, sell_key: str) -> float | None:\n    buy = _to_float(row.get(buy_key))\n    sell = _to_float(row.get(sell_key))\n    if buy is None and sell is None:\n        return None\n    # Tushare moneyflow amount fields are in 10k CNY; the Eastmoney tool emits\n    # CNY, so convert to keep the existing bucket units.\n    return ((buy or 0.0) - (sell or 0.0)) * 10_000\n\n\ndef _ts_code(code: str) -> str:\n    token = code.strip().upper()\n    if \".\" in token:\n        bare, suffix = token.split(\".\", 1)\n        if suffix in {\"SH\", \"SZ\", \"BJ\"} and len(bare) == 6 and bare.isdigit():\n            return f\"{bare}.{suffix}\"\n        raise TushareFallbackUnavailable(f\"unsupported Tushare symbol: {code}\")\n    for prefix in (\"SH\", \"SZ\", \"BJ\"):\n        if token.startswith(prefix):\n            token = token[len(prefix) :]\n            break\n    if len(token) != 6 or not token.isdigit():\n        raise TushareFallbackUnavailable(f\"unsupported Tushare symbol: {code}\")\n    if token.startswith((\"5\", \"6\", \"9\")):\n        suffix = \"SH\"\n    elif token.startswith((\"0\", \"2\", \"3\")):\n        suffix = \"SZ\"\n    elif token.startswith((\"4\", \"8\")):\n        suffix = \"BJ\"\n    else:\n        raise TushareFallbackUnavailable(f\"unsupported Tushare symbol: {code}\")\n    return f\"{token}.{suffix}\"\n\n\ndef fetch_fund_flow(symbol: str, *, days: int) -> dict[str, Any]:","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/tools/tushare_fallbacks.py#L77-L113","documentation":"_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'.","triggerScenarios":"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').","commonSituations":"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.","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"],"exampleFix":"# before\nfetch_fund_flow(\"600519.SS\")\n\n# after\nfetch_fund_flow(\"600519.SH\")  # or just \"600519\"","handlingStrategy":"type-guard","validationCode":"import re\n\ndef valid_dotted_symbol(sym: str) -> bool:\n    return bool(re.fullmatch(r'\\d{6}\\.(SH|SZ|BJ)', sym.strip().upper()))","typeGuard":"import re\nfrom typing import TypeGuard\n\ndef is_tushare_symbol(sym: str) -> TypeGuard[str]:\n    s = sym.strip().upper()\n    return bool(re.fullmatch(r'(?:\\d{6}\\.(?:SH|SZ|BJ))|(?:(?:SH|SZ|BJ)?\\d{6})', s))","tryCatchPattern":"try:\n    _ = fetch_fund_flow(sym, days=5)\nexcept TushareFallbackUnavailable as exc:\n    if 'unsupported Tushare symbol' in str(exc):\n        logger.info('skipping non-A-share symbol %s', sym)\n        continue\n    raise","preventionTips":["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"],"tags":["tushare","symbol-format","stock-code","validation"],"backgroundTag":"invalid-symbol-format","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}