Skip to content

"Vibe-Trading: Your Personal Trading Agent"

test(market-detection): unpin the unknown-defaults test and add explicit FX/Futures cases

aminak58c81d5679096e
diff --git a/agent/tests/test_market_detection.py b/agent/tests/test_market_detection.py
index c85f4768a..75d9a781e 100644
--- a/agent/tests/test_market_detection.py
+++ b/agent/tests/test_market_detection.py
@@ -99,11 +99,16 @@ class TestDetectMarket:
assert _detect_market("td.to") == "ca_equity"
def test_unknown_defaults_to_a_share(self) -> None:
+ # Symbols that don't match any pattern fall through to the
+ # ``a_share`` default. ``EURUSD`` and ``BTCUSDT`` used to be
+ # examples but are now classified (PR #1280); use truly
+ # unclassifiable inputs so the default-to-``a_share`` behavior
+ # is pinned without coupling to a specific routing decision.
assert _detect_market("UNKNOWN") == "a_share"
assert _detect_market("random-string") == "a_share"
- # Bare codes outside the 1-5 letter US shape keep the old default.
- assert _detect_market("EURUSD") == "a_share"
- assert _detect_market("BTCUSDT") == "a_share"
+ assert _detect_market("12345") == "a_share"
+ assert _detect_market("123456") == "a_share"
+ assert _detect_market("@#$") == "a_share"
# ---------------------------------------------------------------------------
@@ -322,3 +327,40 @@ class TestDetectMarketRequired:
def test_crypto_hyphen_form(self) -> None:
assert _detect_market("BTC-USDT") == "crypto"
+
+ def test_bare_fx_pair_classifies_as_forex(self) -> None:
+ # Bare 6-character G10 / precious-metal pairs. PR #1280 added
+ # the whitelist-restricted regex so ``XAUUSD`` / ``EURUSD`` route
+ # to ``forex`` instead of falling through to the ``a_share``
+ # default. The test pins the new behavior explicitly.
+ assert _detect_market("XAUUSD") == "forex"
+ assert _detect_market("EURUSD") == "forex"
+ assert _detect_market("XAGUSD") == "forex"
+ assert _detect_market("XPTUSD") == "forex"
+ assert _detect_market("XPDUSD") == "forex"
+ assert _detect_market("GBPUSD") == "forex"
+ assert _detect_market("USDJPY") == "forex"
+
+ def test_yahoo_equals_notation_routes_to_underlying_market(self) -> None:
+ # Yahoo's continuous-front-month futures form (``=F``) and forex
+ # form (``=X``). PR #1280 added these patterns.
+ assert _detect_market("GC=F") == "futures"
+ assert _detect_market("CL=F") == "futures"
+ assert _detect_market("SI=F") == "futures"
+ assert _detect_market("HG=F") == "futures"
+ assert _detect_market("MGC=F") == "futures"
+ assert _detect_market("XAUUSD=X") == "forex"
+ assert _detect_market("EURUSD=X") == "forex"
+
+ def test_bare_fx_pair_classification_is_case_insensitive(self) -> None:
+ # The bare-6-character regex in ``_MARKET_PATTERNS`` is compiled
+ # with ``re.I``. This is the same case-insensitive convention the
+ # project has always used for symbol matching (see also
+ # ``test_case_insensitive``), so ``eurusd`` / ``xauusd`` resolving
+ # as ``forex`` is intentional rather than incidental.
+ assert _detect_market("eurusd") == "forex"
+ assert _detect_market("xauusd") == "forex"
+ assert _detect_market("gbpusd") == "forex"
+ assert _detect_market("usdjpy") == "forex"
+ assert _detect_market("gc=f") == "futures"
+ assert _detect_market("eurusd=x") == "forex"