Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(etf-holdings): accept Yahoo's .SS suffix for Shanghai-listed funds

Rudy Celeklibef2bb810655
diff --git a/agent/src/tools/etf_holdings_tool.py b/agent/src/tools/etf_holdings_tool.py
index 34654b1c6..517badb60 100644
--- a/agent/src/tools/etf_holdings_tool.py
+++ b/agent/src/tools/etf_holdings_tool.py
@@ -242,11 +242,12 @@ def _classify_market(symbol: str) -> str:
symbol: An ETF symbol such as ``"510050.SH"``, ``"510050"`` or ``"IVV"``.
Returns:
- ``"CN"`` for a ``.SH`` / ``.SZ`` suffix or a bare six-digit code,
+ ``"CN"`` for a ``.SH`` / ``.SZ`` suffix (or Yahoo's ``.SS`` alias for
+ Shanghai) or a bare six-digit code,
``"US"`` otherwise.
"""
upper = symbol.strip().upper()
- if upper.endswith((".SH", ".SZ")):
+ if upper.endswith((".SH", ".SZ", ".SS")):
return "CN"
if len(upper) == 6 and upper.isdigit():
return "CN"
@@ -286,6 +287,9 @@ def _cn_code_and_secid(symbol: str) -> tuple[str, str | None]:
be determined.
"""
upper = symbol.strip().upper()
+ if upper.endswith(".SS"):
+ # Yahoo's spelling of Shanghai; the shared resolver knows ``.SH`` only.
+ upper = f"{upper[: -len('.SS')]}.SH"
if upper.endswith((".SH", ".SZ")):
return upper.split(".")[0], resolve_secid(upper)
exchange = _CN_PREFIX_EXCHANGE.get(upper[:2])
diff --git a/agent/tests/test_etf_holdings_tool.py b/agent/tests/test_etf_holdings_tool.py
index b9c2f59d6..6fa27b3b6 100644
--- a/agent/tests/test_etf_holdings_tool.py
+++ b/agent/tests/test_etf_holdings_tool.py
@@ -339,6 +339,7 @@ class TestMarketRouting:
("510050.SH", "CN"),
("159915.sz", "CN"),
("510050", "CN"),
+ ("510050.SS", "CN"),
("IVV", "US"),
("SOXX", "US"),
("BRK.B", "US"),
@@ -358,6 +359,11 @@ class TestMarketRouting:
assert etf._cn_code_and_secid("159915") == ("159915", "0.159915")
assert etf._cn_code_and_secid("123456")[1] is None
+ def test_yahoo_shanghai_suffix_resolves_like_sh(self):
+ # Yahoo spells Shanghai ``.SS``; the rest of the repo folds it onto ``.SH``.
+ assert etf._cn_code_and_secid("510050.SS") == ("510050", "1.510050")
+ assert etf._cn_code_and_secid("510050.ss") == ("510050", "1.510050")
+
def test_explicit_market_overrides_detection(self):
with patch.object(etf, "_sec_get_text", side_effect=_sec_router):
payload = json.loads(EtfHoldingsTool().execute(mode="lookup", query="510050", market="US"))