"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(backtest): a local: code the dataset lacks is never filled from a network chain (#1467)
Haozhe Wuf2a4d1517a01
diff --git a/agent/backtest/runner.py b/agent/backtest/runner.pyindex 1b9226e37..89965e360 100644--- a/agent/backtest/runner.py+++ b/agent/backtest/runner.py@@ -1624,6 +1624,13 @@ def fetch_data_map(config: dict) -> DataFetchResult:)used_sources = [served_by] if data_map else []missing = [code for code in codes if code not in data_map]+ # With the prefix stripped, a network chain could serve the bare symbol+ # as if the dataset held it. A ``local:`` code is the dataset's or nothing.+ unserved_local = [code for code in prefixed if strip_local_prefix(code) in missing]+ if unserved_local:+ raise NoAvailableSourceError(+ f"incomplete data for source=local; missing symbols: {unserved_local}"+ )if missing:logger.warning("source=%s returned data for %d/%d symbols; missing: %s",diff --git a/agent/tests/test_local_prefix_routing.py b/agent/tests/test_local_prefix_routing.pyindex 35d4bce92..2917eac9a 100644--- a/agent/tests/test_local_prefix_routing.py+++ b/agent/tests/test_local_prefix_routing.py@@ -141,6 +141,20 @@ def test_auto_refuses_a_local_code_the_dataset_lacks_instead_of_fetching_it(assert network.calls == [][email protected]("source", ["local", "auto"])+def test_a_local_code_the_dataset_lacks_is_never_filled_from_the_network(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, network: type[_NetworkLoader], source: str+) -> None:+ """Stripping the prefix must not let a network chain serve the bare symbol instead."""+ _configure_local(monkeypatch, tmp_path, ["AAPL.US"])++ with pytest.raises(NoAvailableSourceError, match=r"source=local; missing symbols: \['local:MSFT.US'\]"):+ runner.fetch_data_map(+ {"source": source, "codes": ["local:AAPL.US", "local:MSFT.US"], "start_date": _START, "end_date": _END}+ )+ assert network.calls == []++def test_a_local_code_from_a_network_source_is_refused(network: type[_NetworkLoader]) -> None:with pytest.raises(ValueError, match="need source='local' or 'auto'"):runner.fetch_data_map({"source": "yahoo", "codes": ["local:AAPL.US"], "start_date": _START, "end_date": _END})