Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(loaders): never degrade an unavailable Toman source into the crypto chain

Haozhe Wu31bf54b2ab88
diff --git a/agent/backtest/loaders/registry.py b/agent/backtest/loaders/registry.py
index 2c3a37387..46bde2bdc 100644
--- a/agent/backtest/loaders/registry.py
+++ b/agent/backtest/loaders/registry.py
@@ -135,7 +135,15 @@ def _ensure_registered() -> None:
# ``fmp`` joins because an explicit ``source="fmp"`` request must not silently
# return data from a different source when the Stable endpoint 403s — the
# caller asked for FMP provenance, not a Yahoo fallback (issue #1270).
-_NO_NETWORK_FALLBACK_SOURCES: frozenset[str] = frozenset({"local", "qveris", "tickerall", "fmp"}) # QVERIS-INTEGRATION
+# ``nobitex``/``wallex`` join for a stronger version of the same reason: they
+# are the only sources quoting in Iranian Toman, and they declare
+# ``markets = {"crypto"}`` purely to be reachable. Degrading an unavailable
+# ``BTCIRT`` request into the crypto chain would hand a USDT-quoted series back
+# as if it were Toman — a caliber error of about six orders of magnitude, not a
+# missing-data error. An unreachable Iranian endpoint must be visible.
+_NO_NETWORK_FALLBACK_SOURCES: frozenset[str] = frozenset(
+ {"local", "qveris", "tickerall", "fmp", "nobitex", "wallex"}
+) # QVERIS-INTEGRATION
# ---------------------------------------------------------------------------
@@ -458,6 +466,12 @@ def get_loader_cls_with_fallback(source: str) -> Type[Any]:
"list at least one source.",
"tickerall": "Set TICKERALL_API_KEY and TICKERALL_ACCOUNT_ID.",
"fmp": "Set FMP_API_KEY.",
+ "nobitex": "Nobitex's public endpoint was unreachable. It quotes in "
+ "Toman (IRT) and has no substitute — check network access "
+ "to apiv2.nobitex.ir.",
+ "wallex": "Wallex's public endpoint was unreachable. It quotes in "
+ "Toman (TMN) and has no substitute — check network access "
+ "to api.wallex.ir.",
}.get(source, "")
raise NoAvailableSourceError(
f"Data source '{source}' is unavailable and does not fall back to a "
diff --git a/agent/tests/test_nobitex_loader.py b/agent/tests/test_nobitex_loader.py
index 9198e1ffb..cd0f57158 100644
--- a/agent/tests/test_nobitex_loader.py
+++ b/agent/tests/test_nobitex_loader.py
@@ -196,3 +196,26 @@ class TestRoutingPattern:
assert detect_source("usdtirt") == "nobitex"
assert detect_source("BTC-USDT") == "okx"
assert detect_source("AAPL.US") == "yahoo"
+
+
+def test_toman_sources_never_degrade_into_the_crypto_chain(monkeypatch) -> None:
+ """An unavailable IRT/TMN source must fail loudly, not fall back.
+
+ Nobitex and Wallex are the only sources quoting in Iranian Toman, and they
+ declare ``markets = {"crypto"}`` only so the resolver can reach them. If an
+ unreachable Iranian endpoint degraded into the crypto chain, a ``BTCIRT``
+ request would come back as a USDT-quoted series presented as Toman — a
+ caliber error of roughly six orders of magnitude. Same rule as ``fmp``
+ (#1270), for a worse failure.
+ """
+ import pytest
+
+ from backtest.loaders import registry as loader_registry
+
+ loader_registry._ensure_registered()
+ for source in ("nobitex", "wallex"):
+ loader_cls = loader_registry.LOADER_REGISTRY[source]
+ monkeypatch.setattr(loader_cls, "is_available", lambda self: False)
+ with pytest.raises(loader_registry.NoAvailableSourceError) as excinfo:
+ loader_registry.get_loader_cls_with_fallback(source)
+ assert "does not fall back" in str(excinfo.value), source