"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(live): keep asset_class through the order-guard notional rebuild
Haozhe Wuba409fe941e7
diff --git a/agent/src/live/order_guard.py b/agent/src/live/order_guard.pyindex e4a69b5ec..88b6c3ea9 100644--- a/agent/src/live/order_guard.py+++ b/agent/src/live/order_guard.py@@ -258,6 +258,11 @@ class LiveOrderGuardTool(MCPRemoteTool):notional_usd=enforced,quantity=intent.quantity,instrument_type=intent.instrument_type,+ # asset_class must survive the rebuild: check_mandate prefers an+ # explicit one over the instrument-type default (enforcement.py:524),+ # so dropping it buckets an HK/A-share order as us_equity and lets it+ # past a mandate that permits only us_equity.+ asset_class=intent.asset_class,limit_price=intent.limit_price,)diff --git a/agent/tests/test_enforcement_l6.py b/agent/tests/test_enforcement_l6.pyindex 0e5f58e11..702e18654 100644--- a/agent/tests/test_enforcement_l6.py+++ b/agent/tests/test_enforcement_l6.py@@ -273,3 +273,50 @@ def test_last_price_usd_fail_closed_on_loader_unavailable(monkeypatch: pytest.Momonkeypatch.setattr(enforcement, "_resolve_loader", _raise)assert enforcement.last_price_usd("AAPL", AssetClass.US_EQUITY) is None+++# --------------------------------------------------------------------------- #+# Normalization must not drop security-relevant intent fields #+# --------------------------------------------------------------------------- #+++def test_normalization_preserves_asset_class(live_runtime: Path) -> None:+ """``_normalize_intent_notional`` rebuilds the intent; asset_class must survive.++ ``check_mandate`` prefers an explicit ``intent.asset_class`` over the+ instrument-type default (enforcement.py:524) precisely so a multi-market+ connector's HK/A-share order buckets correctly. If the rebuild drops it, an+ HK order falls back to the EQUITY default (us_equity) and passes a mandate+ that permits only us_equity — a fail-open on the universe check.+ """+ _write_mandate(live_runtime, max_order_notional_usd=10_000.0)+ guard = _guard(_BrokerQuoteAdapter(price=100.0))+ intent = enforcement.OrderIntent(+ symbol="0700.HK",+ side="buy",+ notional_usd=None,+ quantity=10.0,+ instrument_type=InstrumentType.EQUITY,+ asset_class=AssetClass.HK_EQUITY,+ )+ normalized = guard._normalize_intent_notional(intent)+ assert normalized is not None+ assert normalized.asset_class is AssetClass.HK_EQUITY+ # And the notional reconciliation it exists for still happened.+ assert normalized.notional_usd == pytest.approx(1000.0)+++def test_normalization_preserves_a_none_asset_class(live_runtime: Path) -> None:+ """The Robinhood extractor never sets one; None must stay None, not crash."""+ _write_mandate(live_runtime, max_order_notional_usd=10_000.0)+ guard = _guard(_BrokerQuoteAdapter(price=100.0))+ intent = enforcement.OrderIntent(+ symbol="AAPL",+ side="buy",+ notional_usd=None,+ quantity=10.0,+ instrument_type=InstrumentType.EQUITY,+ )+ normalized = guard._normalize_intent_notional(intent)+ assert normalized is not None+ assert normalized.asset_class is None