Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(symbol-search): resolve bare US ETFs and funds as US listings

Jackzigenbbf26ccf5b98
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bcf1ea3d3..dbd18dbaf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,12 @@ This project adheres to [Semantic Versioning](https://semver.org/).
### Fixed
+- **Bare US ETF and fund symbols** such as `QQQ` and `SPY` now resolve to
+ `QQQ.US` / market `us` instead of a suffix-less `global` candidate. The fetch
+ layer already routed bare US tickers as US equities, so the resolver was the
+ only place that disagreed: the identity lock then rejected the follow-up call
+ ("consumer symbol/venue differs from the locked resolver identity"). ETFs and
+ mutual funds on non-US venues keep their native form (#2084).
- **Global futures routing and pricing**: digit-bearing contracts such as
`M2K=F` and `6EZ2026.CME`, including `local:` inputs, reach the global
futures engine with their full product code. OJ and ZR use quote-unit
diff --git a/agent/src/tools/symbol_search_tool.py b/agent/src/tools/symbol_search_tool.py
index af62d202d..92ac1654f 100644
--- a/agent/src/tools/symbol_search_tool.py
+++ b/agent/src/tools/symbol_search_tool.py
@@ -165,6 +165,32 @@ _MARKET_BY_SUFFIX: Dict[str, str] = {
"VN": "vn",
}
+# Quote types Yahoo carries bare for US listings, in addition to equities.
+# ETFs and mutual funds are plain US tickers over there (``QQQ``, ``SPY``,
+# ``VFIAX``) and the data layer already treats a bare ticker as ``us_equity``;
+# only the resolver disagreed, which is what #2084 reported.
+_US_LISTED_QUOTE_TYPES = frozenset({"EQUITY", "ETF", "MUTUALFUND"})
+
+# Yahoo exchange codes for US venues. Used only to keep a bare symbol that
+# belongs to a non-US venue on its native form; an empty exchange is treated as
+# US because Yahoo suffixes every non-US listing it lists.
+_US_YAHOO_EXCHANGES = frozenset(
+ {
+ "NMS", # Nasdaq Global Select
+ "NGM", # Nasdaq Global Market
+ "NCM", # Nasdaq Capital Market
+ "NAS",
+ "NYQ", # NYSE
+ "PCX", # NYSE Arca (most ETFs)
+ "ASE", # NYSE American
+ "BTS", # Cboe BZX
+ "OQX", # OTCQX
+ "OQB", # OTCQB
+ "PNK", # Pink Sheets
+ "OTC",
+ }
+)
+
# Hard caps so a broad query cannot bloat the envelope.
_MAX_LIMIT = 25
_DEFAULT_LIMIT = 10
@@ -866,9 +892,21 @@ def _from_yahoo_symbol(raw_symbol: str, quote: Dict[str, Any]) -> tuple[str, str
return raw_symbol, "global"
if raw_symbol.startswith("^"):
return raw_symbol, "index"
- if quote_type == "EQUITY" and "." not in raw_symbol and "-" not in raw_symbol:
+ exchange = str(quote.get("exchange") or "").strip().upper()
+ if (
+ quote_type in _US_LISTED_QUOTE_TYPES
+ and "." not in raw_symbol
+ and "-" not in raw_symbol
+ and (not exchange or exchange in _US_YAHOO_EXCHANGES)
+ ):
+ # ETFs and mutual funds are US listings just like equities: Yahoo
+ # carries them bare (``QQQ``, ``SPY``), and the fetch layer already
+ # routes a bare ticker as ``us_equity``. Leaving them on Yahoo's
+ # native symbol with market ``global`` split the two layers — the
+ # resolver locked ``QQQ`` while ``get_market_data`` demands
+ # ``QQQ.US``, so every ETF question ended degraded (#2084).
return f"{upper}.US", "us"
- # Crypto, indices, FX, ETFs on non-HK exchanges: keep Yahoo's native symbol.
+ # Crypto, indices, FX, ETFs on non-US exchanges: keep Yahoo's native symbol.
return raw_symbol, "global"
diff --git a/agent/tests/test_symbol_search_tool.py b/agent/tests/test_symbol_search_tool.py
index 97a185651..ff94bd52a 100644
--- a/agent/tests/test_symbol_search_tool.py
+++ b/agent/tests/test_symbol_search_tool.py
@@ -941,6 +941,68 @@ class TestFxPairAlignment:
)
+class TestBareUsEtfResolution:
+ """US-listed ETFs and funds resolve like equities, not as ``global``.
+
+ Yahoo carries US ETFs bare (``QQQ``, ``SPY``) while the fetch layer already
+ routes a bare ticker as ``us_equity`` and expects ``<SYM>.US``. The resolver
+ used to emit the bare symbol under market ``global``, so the two layers
+ disagreed and the identity lock rejected every ETF call (#2084).
+ """
+
+ @pytest.mark.parametrize(
+ ("yahoo_symbol", "quote"),
+ [
+ ("QQQ", {"quoteType": "ETF", "exchange": "NGM"}),
+ ("SPY", {"quoteType": "ETF", "exchange": "PCX"}),
+ ("VFIAX", {"quoteType": "MUTUALFUND", "exchange": "NAS"}),
+ # Search payloads do not always carry an exchange row.
+ ("QQQ", {"quoteType": "ETF"}),
+ ],
+ )
+ def test_bare_us_fund_gets_us_suffix(self, yahoo_symbol, quote) -> None:
+ assert ss._from_yahoo_symbol(yahoo_symbol, quote) == (
+ f"{yahoo_symbol}.US",
+ "us",
+ )
+
+ def test_bare_fund_on_foreign_venue_stays_native(self) -> None:
+ """A bare symbol Yahoo files under a non-US venue keeps its own form."""
+ assert ss._from_yahoo_symbol(
+ "XIC", {"quoteType": "ETF", "exchange": "TOR"}
+ ) == ("XIC", "global")
+
+ def test_crypto_and_index_unchanged(self) -> None:
+ assert ss._from_yahoo_symbol(
+ "BTC-USD", {"quoteType": "CRYPTOCURRENCY"}
+ ) == ("BTC-USD", "global")
+ assert ss._from_yahoo_symbol("^SPX", {"quoteType": "INDEX"}) == (
+ "^SPX",
+ "index",
+ )
+
+ def test_us_etf_candidate_row_is_fetchable(self) -> None:
+ """End to end: ``QQQ`` surfaces as ``QQQ.US`` / ``us``."""
+ quotes = [
+ {
+ "symbol": "QQQ",
+ "shortname": "Invesco QQQ Trust",
+ "exchange": "NGM",
+ "exchDisp": "NASDAQ",
+ "quoteType": "ETF",
+ }
+ ]
+ with patch.object(
+ ss.eastmoney_client,
+ "get_json",
+ return_value={"QuotationCodeTable": {"Data": []}},
+ ), patch.object(ss.yahoo_client, "search", return_value=quotes):
+ data = json.loads(ss.SymbolSearchTool().execute(query="QQQ"))["data"]
+
+ row = next(c for c in data["candidates"] if c["symbol"] == "QQQ.US")
+ assert row["market"] == "us"
+
+
class TestCryptoUsdBaseWhitelist:
"""``USD`` quote leg on the crypto resolver is gated on a base whitelist.