Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(symbols): resolve Beijing 920/4/8 codes to .BJ in search and Tushare fallback

Rudy Celekli702006c032f5
diff --git a/agent/src/tools/symbol_search_tool.py b/agent/src/tools/symbol_search_tool.py
index 8c250696d..af62d202d 100644
--- a/agent/src/tools/symbol_search_tool.py
+++ b/agent/src/tools/symbol_search_tool.py
@@ -718,6 +718,10 @@ def _eastmoney_candidate(row: Dict[str, Any]) -> Optional[Dict[str, Any]]:
suffix = _EASTMONEY_SUFFIX_BY_MARKET.get(market)
if not suffix or not code:
return None
+ # Market 0 also carries the Beijing exchange: 920xxx (current) and
+ # legacy 4xxxxx/8xxxxx codes. Shenzhen codes start with 0/2/3.
+ if suffix == "SZ" and len(code) == 6 and code.startswith(("4", "8", "92")):
+ suffix = "BJ"
symbol = _format_symbol(code, suffix)
if symbol is None:
diff --git a/agent/src/tools/tushare_fallbacks.py b/agent/src/tools/tushare_fallbacks.py
index 100c465a1..79871a27b 100644
--- a/agent/src/tools/tushare_fallbacks.py
+++ b/agent/src/tools/tushare_fallbacks.py
@@ -99,12 +99,12 @@ def _ts_code(code: str) -> str:
break
if len(token) != 6 or not token.isdigit():
raise TushareFallbackUnavailable(f"unsupported Tushare symbol: {code}")
- if token.startswith(("5", "6", "9")):
+ if token.startswith(("4", "8", "920")):
+ suffix = "BJ"
+ elif 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}"
diff --git a/agent/tests/test_symbol_search_tool.py b/agent/tests/test_symbol_search_tool.py
index 4b4c4d012..97a185651 100644
--- a/agent/tests/test_symbol_search_tool.py
+++ b/agent/tests/test_symbol_search_tool.py
@@ -1212,3 +1212,22 @@ def test_mt5_ambiguous_catalog_leaves_grounding_unresolved(monkeypatch, tmp_path
ledger.ingest_tool_result(tool_name="search_symbol", arguments={"query": "XAUUSD"}, result=result, call_id="ambiguous-mt5", success=True)
assert ledger.identity_status != "locked"
assert ledger.identity_summary()["authorized_symbols"] == []
+
+
+ "quote_id, expected",
+ [
+ ("0.920002", "920002.BJ"),
+ ("0.830799", "830799.BJ"),
+ ("0.430139", "430139.BJ"),
+ ("0.000001", "000001.SZ"),
+ ("0.300750", "300750.SZ"),
+ ("1.600519", "600519.SH"),
+ ],
+)
+def test_eastmoney_market_zero_splits_beijing_from_shenzhen(quote_id: str, expected: str) -> None:
+ code = quote_id.split(".", 1)[1]
+ row = {"QuoteID": quote_id, "Code": code, "Name": "x", "SecurityTypeName": "A"}
+ candidate = ss._eastmoney_candidate(row)
+ assert candidate is not None
+ assert candidate["symbol"] == expected
diff --git a/agent/tests/test_tushare_fallbacks.py b/agent/tests/test_tushare_fallbacks.py
index 1f59e6c9d..c4e7955d8 100644
--- a/agent/tests/test_tushare_fallbacks.py
+++ b/agent/tests/test_tushare_fallbacks.py
@@ -118,3 +118,12 @@ def test_margin_trading_maps_and_sorts_most_recent_first() -> None:
assert data["rows"][0]["trade_date"] == "2024-01-03"
assert data["rows"][0]["financing_balance"] == 7.0
assert data["rows"][1]["margin_total_balance"] == 6.0
+
+
+def test_ts_code_routes_beijing_920_codes_to_bj() -> None:
+ assert tf._ts_code("920002") == "920002.BJ"
+ assert tf._ts_code("830799") == "830799.BJ"
+ assert tf._ts_code("430047") == "430047.BJ"
+ assert tf._ts_code("900901") == "900901.SH"
+ assert tf._ts_code("600519") == "600519.SH"
+ assert tf._ts_code("000001") == "000001.SZ"