"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
style(loaders): apply Black to changed registry files
AJ61f4624163db
diff --git a/agent/backtest/loaders/registry.py b/agent/backtest/loaders/registry.pyindex 92c461e2a..7f32d63d5 100644--- a/agent/backtest/loaders/registry.py+++ b/agent/backtest/loaders/registry.py@@ -164,38 +164,69 @@ _NO_NETWORK_FALLBACK_SOURCES: frozenset[str] = frozenset(# that must be politely throttled; Finnhub/AlphaVantage/Tiingo/FMP are key-gated# REST fallbacks placed deeper in the chain.FALLBACK_CHAINS: dict[str, list[str]] = {- "a_share": ["tencent", "mootdx", "eastmoney", "baostock", "akshare", "tushare", "local"],- "us_equity": ["yahoo", "stooq", "sina", "eastmoney", "yfinance", "tiingo", "fmp", "finnhub", "alphavantage", "longbridge", "akshare", "local"],+ "a_share": [+ "tencent",+ "mootdx",+ "eastmoney",+ "baostock",+ "akshare",+ "tushare",+ "local",+ ],+ "us_equity": [+ "yahoo",+ "stooq",+ "sina",+ "eastmoney",+ "yfinance",+ "tiingo",+ "fmp",+ "finnhub",+ "alphavantage",+ "longbridge",+ "akshare",+ "local",+ ],# HK: tencent leads (no observed IP ban); akshare (Eastmoney-backed)# precedes the Yahoo-SDK family, which is blocked from mainland IPs;# tushare hk_daily is key-gated.- "hk_equity": ["tencent", "eastmoney", "yahoo", "futu", "akshare", "yfinance", "tushare", "longbridge", "local"],+ "hk_equity": [+ "tencent",+ "eastmoney",+ "yahoo",+ "futu",+ "akshare",+ "yfinance",+ "tushare",+ "longbridge",+ "local",+ ],"india_equity": ["yahoo", "yfinance", "india_broker", "local"],- "kr_equity": ["pykrx", "yahoo", "yfinance", "local"],+ "kr_equity": ["pykrx", "yahoo", "yfinance", "local"],# TSX (.TO) / TSX Venture (.V): direct Yahoo first, SDK fallback second.- "ca_equity": ["yahoo", "yfinance", "local"],+ "ca_equity": ["yahoo", "yfinance", "local"],# UK (LSE .L): direct Yahoo first, SDK fallback second.- "uk_equity": ["yahoo", "yfinance", "local"],+ "uk_equity": ["yahoo", "yfinance", "local"],# Vietnam (.VN): Yahoo lists HOSE only — HNX and UPCOM are unsupported,# so those two are reachable only through the user's local files."vietnam_equity": ["yahoo", "yfinance", "local"],# OKX first (native), then dedicated Binance, then generic CCXT / Yahoo.- "crypto": ["okx", "binance", "ccxt", "yfinance", "local"],+ "crypto": ["okx", "binance", "ccxt", "yfinance", "local"],# tushare led this chain while implementing no futures endpoint at all# (#1395): ``resolve_loader`` walks FALLBACK_CHAINS and never consults a# loader's ``markets`` set, so trimming that set alone would have left# tushare first in line, returning empty frames before akshare was ever# asked. akshare serves Chinese contracts off the token-free Sina daily# endpoints; a global contract has no network source and reaches ``local``.- "futures": ["akshare", "local"],- "fund": ["tushare", "akshare", "local"],- "macro": ["akshare", "tushare", "local"],+ "futures": ["akshare", "local"],+ "fund": ["tushare", "akshare", "local"],+ "macro": ["akshare", "tushare", "local"],# mt5 leads when a local MetaTrader 5 terminal is attached (Windows-only,# broker feed); otherwise it reports unavailable and the chain proceeds.- "forex": ["mt5", "akshare", "yfinance", "local"],+ "forex": ["mt5", "akshare", "yfinance", "local"],# Yahoo index symbols (^SPX, ^NDX, ^FTSE, ^VIX, ...): served verbatim by# the public chart endpoint, same as the =F/=X conventions.- "index": ["yahoo", "yfinance", "local"],+ "index": ["yahoo", "yfinance", "local"],}@@ -394,7 +425,9 @@ def refresh_source_order_overrides() -> None:logger.warning("Ignoring invalid %s=%r: value must be a permutation of the"" default chain %s; keeping default order",- source_order_env_var(market), raw, default,+ source_order_env_var(market),+ raw,+ default,)FALLBACK_CHAINS[market] = default[:]_ACTIVE_SOURCE_ORDER_OVERRIDES.pop(market, None)@@ -476,16 +509,16 @@ def get_loader_cls_with_fallback(source: str) -> Type[Any]:if source in _NO_NETWORK_FALLBACK_SOURCES:hint = {"local": "Check your Data Bridge config "- "(~/.vibe-trading/data-bridge/config.yaml) — it must exist and "- "list at least one source.",+ "(~/.vibe-trading/data-bridge/config.yaml) — it must exist and "+ "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.",+ "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.",+ "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 "@@ -498,7 +531,9 @@ def get_loader_cls_with_fallback(source: str) -> Type[Any]:fallback = resolve_loader(market)logger.warning("%s is unavailable, falling back to %s for market %s",- source, fallback.name, market,+ source,+ fallback.name,+ market,)return type(fallback)except NoAvailableSourceError:diff --git a/agent/tests/test_registry.py b/agent/tests/test_registry.pyindex 9e196cff0..e5579180d 100644--- a/agent/tests/test_registry.py+++ b/agent/tests/test_registry.py@@ -196,9 +196,20 @@ class TestProtocol:class TestFallbackChains:def test_all_expected_markets_present(self) -> None:expected = {- "a_share", "us_equity", "hk_equity", "india_equity", "kr_equity",- "ca_equity", "uk_equity", "vietnam_equity", "crypto", "futures",- "fund", "macro", "forex", "index",+ "a_share",+ "us_equity",+ "hk_equity",+ "india_equity",+ "kr_equity",+ "ca_equity",+ "uk_equity",+ "vietnam_equity",+ "crypto",+ "futures",+ "fund",+ "macro",+ "forex",+ "index",}assert expected == set(FALLBACK_CHAINS.keys())@@ -225,14 +236,38 @@ class TestFallbackChains:"""Equity chains lead with throttle-tolerant public sources and trailwith key-gated REST fallbacks, in the exact reviewed order."""assert FALLBACK_CHAINS["a_share"] == [- "tencent", "mootdx", "eastmoney", "baostock", "akshare", "tushare", "local",+ "tencent",+ "mootdx",+ "eastmoney",+ "baostock",+ "akshare",+ "tushare",+ "local",]assert FALLBACK_CHAINS["us_equity"] == [- "yahoo", "stooq", "sina", "eastmoney", "yfinance", "tiingo", "fmp",- "finnhub", "alphavantage", "longbridge", "akshare", "local",+ "yahoo",+ "stooq",+ "sina",+ "eastmoney",+ "yfinance",+ "tiingo",+ "fmp",+ "finnhub",+ "alphavantage",+ "longbridge",+ "akshare",+ "local",]assert FALLBACK_CHAINS["hk_equity"] == [- "tencent", "eastmoney", "yahoo", "futu", "akshare", "yfinance", "tushare", "longbridge", "local",+ "tencent",+ "eastmoney",+ "yahoo",+ "futu",+ "akshare",+ "yfinance",+ "tushare",+ "longbridge",+ "local",]def test_us_equity_includes_sina_fallback(self) -> None:@@ -249,7 +284,13 @@ class TestFallbackChains:def test_unchanged_chains_preserved(self) -> None:"""crypto/fund/macro/forex chains must be left untouched."""- assert FALLBACK_CHAINS["crypto"] == ["okx", "binance", "ccxt", "yfinance", "local"]+ assert FALLBACK_CHAINS["crypto"] == [+ "okx",+ "binance",+ "ccxt",+ "yfinance",+ "local",+ ]assert FALLBACK_CHAINS["fund"] == ["tushare", "akshare", "local"]assert FALLBACK_CHAINS["macro"] == ["akshare", "tushare", "local"]# mt5 heads the forex chain (terminal feed when attached), degrading to@@ -278,9 +319,9 @@ class TestFallbackChains:for name in FALLBACK_CHAINS["futures"]:loader_cls = LOADER_REGISTRY.get(name)assert loader_cls is not None, f"{name} is in the chain but not registered"- assert "futures" in loader_cls.markets, (- f"{name} leads the futures chain without declaring the market"- )+ assert (+ "futures" in loader_cls.markets+ ), f"{name} leads the futures chain without declaring the market"def test_tickerall_is_explicit_only_never_a_fallback(self) -> None:"""TickerAll is a valid explicit source but must NEVER join an automatic@@ -289,7 +330,9 @@ class TestFallbackChains:as a degradation target for another source. This guards that contract."""assert "tickerall" in VALID_SOURCESfor market, chain in FALLBACK_CHAINS.items():- assert "tickerall" not in chain, f"tickerall must not be in the {market} fallback chain"+ assert (+ "tickerall" not in chain+ ), f"tickerall must not be in the {market} fallback chain"# ---------------------------------------------------------------------------@@ -301,8 +344,14 @@ class TestValidSources:def test_includes_new_loaders(self) -> None:"""Newly registered loaders must be accepted config sources."""new_sources = {- "eastmoney", "sina", "stooq", "yahoo",- "finnhub", "alphavantage", "tiingo", "fmp",+ "eastmoney",+ "sina",+ "stooq",+ "yahoo",+ "finnhub",+ "alphavantage",+ "tiingo",+ "fmp",}assert new_sources <= VALID_SOURCES@@ -329,23 +378,37 @@ class TestValidSources:class TestResolveLoader:def test_returns_first_available(self) -> None:- with patch.dict(LOADER_REGISTRY, {- "fake_unavailable": _FakeUnavailableLoader,- "fake_available": _FakeAvailableLoader,- }, clear=True):- with patch.dict(FALLBACK_CHAINS, {- "a_share": ["fake_unavailable", "fake_available"],- }):+ with patch.dict(+ LOADER_REGISTRY,+ {+ "fake_unavailable": _FakeUnavailableLoader,+ "fake_available": _FakeAvailableLoader,+ },+ clear=True,+ ):+ with patch.dict(+ FALLBACK_CHAINS,+ {+ "a_share": ["fake_unavailable", "fake_available"],+ },+ ):loader = resolve_loader("a_share")assert loader.name == "fake_available"def test_raises_when_none_available(self) -> None:- with patch.dict(LOADER_REGISTRY, {- "fake_unavailable": _FakeUnavailableLoader,- }, clear=True):- with patch.dict(FALLBACK_CHAINS, {- "a_share": ["fake_unavailable"],- }):+ with patch.dict(+ LOADER_REGISTRY,+ {+ "fake_unavailable": _FakeUnavailableLoader,+ },+ clear=True,+ ):+ with patch.dict(+ FALLBACK_CHAINS,+ {+ "a_share": ["fake_unavailable"],+ },+ ):with pytest.raises(NoAvailableSourceError):resolve_loader("a_share")@@ -362,20 +425,31 @@ class TestResolveLoader:class TestGetLoaderWithFallback:def test_returns_requested_if_available(self) -> None:- with patch.dict(LOADER_REGISTRY, {- "fake_available": _FakeAvailableLoader,- }, clear=True):+ with patch.dict(+ LOADER_REGISTRY,+ {+ "fake_available": _FakeAvailableLoader,+ },+ clear=True,+ ):cls = get_loader_cls_with_fallback("fake_available")assert cls is _FakeAvailableLoaderdef test_falls_back_when_unavailable(self) -> None:- with patch.dict(LOADER_REGISTRY, {- "fake_unavailable": _FakeUnavailableLoader,- "fake_available": _FakeAvailableLoader,- }, clear=True):- with patch.dict(FALLBACK_CHAINS, {- "a_share": ["fake_unavailable", "fake_available"],- }):+ with patch.dict(+ LOADER_REGISTRY,+ {+ "fake_unavailable": _FakeUnavailableLoader,+ "fake_available": _FakeAvailableLoader,+ },+ clear=True,+ ):+ with patch.dict(+ FALLBACK_CHAINS,+ {+ "a_share": ["fake_unavailable", "fake_available"],+ },+ ):cls = get_loader_cls_with_fallback("fake_unavailable")assert cls is _FakeAvailableLoader@@ -385,9 +459,13 @@ class TestGetLoaderWithFallback:get_loader_cls_with_fallback("nonexistent")def test_no_fallback_raises(self) -> None:- with patch.dict(LOADER_REGISTRY, {- "fake_unavailable": _FakeUnavailableLoader,- }, clear=True):+ with patch.dict(+ LOADER_REGISTRY,+ {+ "fake_unavailable": _FakeUnavailableLoader,+ },+ clear=True,+ ):with patch.dict(FALLBACK_CHAINS, {"a_share": ["fake_unavailable"]}):with pytest.raises(NoAvailableSourceError):get_loader_cls_with_fallback("fake_unavailable")@@ -395,10 +473,14 @@ class TestGetLoaderWithFallback:def test_explicit_local_does_not_fall_through_to_network(self) -> None:"""An explicit unavailable 'local' request must raise a clear error, neversilently degrade to an unrelated network loader via its broad markets."""- with patch.dict(LOADER_REGISTRY, {- "local": _FakeLocalLoader,- "fake_available": _FakeAvailableLoader, # available a_share network src- }, clear=True):+ with patch.dict(+ LOADER_REGISTRY,+ {+ "local": _FakeLocalLoader,+ "fake_available": _FakeAvailableLoader, # available a_share network src+ },+ clear=True,+ ):# Even though a network loader is available for one of local's markets,# the explicit 'local' request must not borrow it.with patch.dict(FALLBACK_CHAINS, {"a_share": ["fake_available"]}):@@ -412,7 +494,9 @@ class TestGetLoaderWithFallback:def test_explicit_tickerall_does_not_fall_through_to_network(self) -> None:"""An explicit unavailable 'tickerall' must raise, never silently degrade to apublic forex source (akshare/yfinance) via its markets — it reads the user's own- broker account, so a missing key is a config error to surface, not paper over."""+ broker account, so a missing key is a config error to surface, not paper over.+ """+class _FakeTickerall:name = "tickerall"markets = {"forex"}@@ -424,10 +508,14 @@ class TestGetLoaderWithFallback:def fetch(self, codes, start_date, end_date, *, interval="1D", fields=None):return {}- with patch.dict(LOADER_REGISTRY, {- "tickerall": _FakeTickerall,- "fake_available": _FakeAvailableLoader, # an available loader listed in the forex chain- }, clear=True):+ with patch.dict(+ LOADER_REGISTRY,+ {+ "tickerall": _FakeTickerall,+ "fake_available": _FakeAvailableLoader, # an available loader listed in the forex chain+ },+ clear=True,+ ):with patch.dict(FALLBACK_CHAINS, {"forex": ["fake_available"]}):with pytest.raises(NoAvailableSourceError) as excinfo:get_loader_cls_with_fallback("tickerall")@@ -444,23 +532,37 @@ class TestGetLoaderWithFallback:class TestInitErrorFallback:def test_resolve_loader_skips_init_error(self) -> None:- with patch.dict(LOADER_REGISTRY, {- "fake_init_error": _FakeInitErrorLoader,- "fake_available": _FakeAvailableLoader,- }, clear=True):- with patch.dict(FALLBACK_CHAINS, {- "a_share": ["fake_init_error", "fake_available"],- }):+ with patch.dict(+ LOADER_REGISTRY,+ {+ "fake_init_error": _FakeInitErrorLoader,+ "fake_available": _FakeAvailableLoader,+ },+ clear=True,+ ):+ with patch.dict(+ FALLBACK_CHAINS,+ {+ "a_share": ["fake_init_error", "fake_available"],+ },+ ):loader = resolve_loader("a_share")assert loader.name == "fake_available"def test_get_loader_cls_falls_back_when_requested_init_errors(self) -> None:- with patch.dict(LOADER_REGISTRY, {- "fake_init_error": _FakeInitErrorLoader,- "fake_available": _FakeAvailableLoader,- }, clear=True):- with patch.dict(FALLBACK_CHAINS, {- "a_share": ["fake_init_error", "fake_available"],- }):+ with patch.dict(+ LOADER_REGISTRY,+ {+ "fake_init_error": _FakeInitErrorLoader,+ "fake_available": _FakeAvailableLoader,+ },+ clear=True,+ ):+ with patch.dict(+ FALLBACK_CHAINS,+ {+ "a_share": ["fake_init_error", "fake_available"],+ },+ ):cls = get_loader_cls_with_fallback("fake_init_error")assert cls is _FakeAvailableLoader