"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(futu): stop profiles from pinning the HK trade market
Frank-zhu2000d62beff8883e
diff --git a/agent/src/trading/connectors/futu/profiles.py b/agent/src/trading/connectors/futu/profiles.pyindex 0bed8d905..9edab48a3 100644--- a/agent/src/trading/connectors/futu/profiles.py+++ b/agent/src/trading/connectors/futu/profiles.py@@ -22,6 +22,9 @@ from src.trading.types import (# runtime SDK call._FUTU_READS = READ_CAPABILITIES + FUTU_EXTENDED_READ_CAPABILITIES+# Market filter is omitted on purpose. Profile config overwrites futu.json, so+# pinning HK here would hide a saved US (or other) market. Unset stays HK via+# FutuConfig.filter_trdmarket.FUTU_PROFILES: tuple[TradingProfile, ...] = (TradingProfile(id="futu-paper-sdk",@@ -31,7 +34,7 @@ FUTU_PROFILES: tuple[TradingProfile, ...] = (transport="broker_sdk",capabilities=_FUTU_READS,readonly=True,- config={"profile": "paper", "filter_trdmarket": "HK"},+ config={"profile": "paper"},notes=("Reads a Futu paper (SIMULATE) account via futu-api through a local OpenD ""gateway (default 127.0.0.1:11111). OpenD must be running and logged in. "@@ -47,7 +50,7 @@ FUTU_PROFILES: tuple[TradingProfile, ...] = (transport="broker_sdk",capabilities=_FUTU_READS,readonly=True,- config={"profile": "live-readonly", "filter_trdmarket": "HK"},+ config={"profile": "live-readonly"},notes=("Reads a Futu live (REAL) account only, via futu-api through a local OpenD ""gateway (default 127.0.0.1:11111). OpenD must be running and logged in. "@@ -62,7 +65,7 @@ FUTU_PROFILES: tuple[TradingProfile, ...] = (transport="broker_sdk",capabilities=_FUTU_READS + ("orders.place",),readonly=False,- config={"profile": "paper", "filter_trdmarket": "HK"},+ config={"profile": "paper"},notes=("Places orders on a Futu paper (SIMULATE) account via futu-api through a ""local OpenD gateway (default 127.0.0.1:11111). OpenD must be running and "@@ -79,7 +82,7 @@ FUTU_PROFILES: tuple[TradingProfile, ...] = (transport="broker_sdk",capabilities=_FUTU_READS + ("orders.place.requires_mandate",),readonly=False,- config={"profile": "live", "filter_trdmarket": "HK"},+ config={"profile": "live"},notes=("Places orders on a Futu live (REAL) account via futu-api through a local ""OpenD gateway (default 127.0.0.1:11111). OpenD must be running and logged "diff --git a/agent/src/trading/connectors/futu/sdk.py b/agent/src/trading/connectors/futu/sdk.pyindex 7c263c7cf..5092ac7c8 100644--- a/agent/src/trading/connectors/futu/sdk.py+++ b/agent/src/trading/connectors/futu/sdk.py@@ -165,9 +165,10 @@ _OVERRIDE_KEYS = ("host", "port", "profile", "security_firm", "filter_trdmarket"def build_config(profile_config: Mapping[str, Any] | None = None, overrides: Mapping[str, Any] | None = None) -> "FutuConfig":"""Resolve the effective config: saved file ← profile defaults ← CLI overrides.- Gateway endpoint and account settings come from the saved- ``~/.vibe-trading/futu.json``; the selected connector profile supplies the- ``profile`` / ``filter_trdmarket`` intent; CLI/tool overrides win last.+ Gateway endpoint and account settings, including ``filter_trdmarket``,+ come from the saved ``~/.vibe-trading/futu.json`` (HK when that file does+ not set a market). The selected connector profile supplies the trade+ ``profile`` only; CLI/tool overrides win last.Args:profile_config: The connector profile's ``config`` dict.diff --git a/agent/tests/test_sdk_connectors.py b/agent/tests/test_sdk_connectors.pyindex 3093608b5..28ab352ee 100644--- a/agent/tests/test_sdk_connectors.py+++ b/agent/tests/test_sdk_connectors.py@@ -851,6 +851,52 @@ def test_futu_trd_env_mapping() -> None:assert ft.FutuConfig(profile="live-readonly").trd_env_name == "REAL"+def test_futu_saved_filter_trdmarket_survives_every_profile(monkeypatch, tmp_path) -> None:+ """A market saved in futu.json must not be overwritten by a profile.++ ``build_config`` applies profile config after the saved file. Hard-coding+ ``filter_trdmarket`` to HK on every profile therefore forces the HK trade+ context even for a US-only account. The saved market stays, while the+ profile still selects the paper/live environment.+ """+ from src.trading.connectors.futu.profiles import FUTU_PROFILES++ monkeypatch.setattr(ft, "get_runtime_root", lambda: tmp_path)+ (tmp_path / "futu.json").write_text(+ json.dumps({"filter_trdmarket": "US", "profile": "paper"}),+ encoding="utf-8",+ )++ assert len(FUTU_PROFILES) == 4+ for profile in FUTU_PROFILES:+ cfg = ft.build_config(profile.config, None)+ assert cfg.filter_trdmarket == "US", profile.id+ assert cfg.profile == profile.config["profile"]+++def test_futu_filter_trdmarket_defaults_to_hk(monkeypatch, tmp_path) -> None:+ """With no saved market, every Futu profile still opens the HK default."""+ from src.trading.connectors.futu.profiles import FUTU_PROFILES++ monkeypatch.setattr(ft, "get_runtime_root", lambda: tmp_path)+ for profile in FUTU_PROFILES:+ cfg = ft.build_config(profile.config, None)+ assert cfg.filter_trdmarket == "HK", profile.id+++def test_futu_filter_trdmarket_override_beats_saved_file(monkeypatch, tmp_path) -> None:+ """An explicit override still wins over the saved market."""+ from src.trading.connectors.futu.profiles import FUTU_PROFILES++ monkeypatch.setattr(ft, "get_runtime_root", lambda: tmp_path)+ (tmp_path / "futu.json").write_text(+ json.dumps({"filter_trdmarket": "US"}),+ encoding="utf-8",+ )+ cfg = ft.build_config(FUTU_PROFILES[0].config, {"filter_trdmarket": "SG"})+ assert cfg.filter_trdmarket == "SG"++def test_futu_classification() -> None:assert FUTU_TOOL_CLASS["place_order"] is ToolClass.WRITEassert FUTU_TOOL_CLASS["modify_order"] is ToolClass.WRITE