Skip to content

"Vibe-Trading: Your Personal Trading Agent"

feat(agent): add mStock read-only profile

Jackzigenec87d3f414ad
diff --git a/README.md b/README.md
index f151e9803..215266bd0 100644
--- a/README.md
+++ b/README.md
@@ -474,6 +474,7 @@ use a broker sandbox or local simulation. See each profile's notes and the
| `longbridge-live-sdk-readonly` | longbridge | live | broker_sdk | read-only | `account.read`, `history.read`, `orders.read`, `positions.read`, `quotes.read` | broker_sdk | none declared | disabled (read-only) |
| `longbridge-paper-sdk` | longbridge | paper | broker_sdk | read-only | `account.read`, `history.read`, `orders.read`, `positions.read`, `quotes.read` | broker_sdk | none declared | disabled (read-only) |
| `longbridge-paper-trade` | longbridge | paper | broker_sdk | write-enabled | `account.read`, `history.read`, `orders.read`, `positions.read`, `quotes.read` | broker_sdk | `orders.place` | no mandate declared |
+| `mstock-live-rest-readonly` | mstock | live | broker_sdk | read-only | `account.read`, `positions.read` | none declared | none declared | disabled (read-only) |
| `mt5-live-sdk-readonly` | mt5 | live | broker_sdk | read-only | `account.read`, `history.read`, `orders.read`, `positions.read`, `quotes.read` | broker_sdk | none declared | disabled (read-only) |
| `mt5-live-trade` | mt5 | live | broker_sdk | write-enabled | `account.read`, `history.read`, `orders.read`, `positions.read`, `quotes.read` | broker_sdk | `orders.place.requires_mandate` | mandate required |
| `mt5-paper-sdk` | mt5 | paper | broker_sdk | read-only | `account.read`, `history.read`, `orders.read`, `positions.read`, `quotes.read` | broker_sdk | none declared | disabled (read-only) |
diff --git a/agent/src/trading/connectors/mstock/README-classification.md b/agent/src/trading/connectors/mstock/README-classification.md
new file mode 100644
index 000000000..a5476b032
--- /dev/null
+++ b/agent/src/trading/connectors/mstock/README-classification.md
@@ -0,0 +1,13 @@
+# mStock classification boundary
+
+mStock is a plain REST broker, not a remote MCP broker. `scalable/classification.py`
+exists to pin the safety class of remote MCP tool names before discovery can
+expose them; mStock has no remote tool names and this first cut deliberately has
+no SDK module or callable operations, so there is nothing for a Tier-2
+classification map to key on.
+
+Adding a `classification.py` now would invent operation names for an HTTP layer
+that is intentionally out of scope. If the follow-up introduces local SDK-style
+functions, follow the KIS and Upbit REST precedent: pin each verified read as
+`READ`, pin every order-path operation as `WRITE`, and register the map in the
+live registry so unknown operations fail closed.
diff --git a/agent/src/trading/connectors/mstock/__init__.py b/agent/src/trading/connectors/mstock/__init__.py
new file mode 100644
index 000000000..8aecf572b
--- /dev/null
+++ b/agent/src/trading/connectors/mstock/__init__.py
@@ -0,0 +1 @@
+"""mStock connector package."""
diff --git a/agent/src/trading/connectors/mstock/profiles.py b/agent/src/trading/connectors/mstock/profiles.py
new file mode 100644
index 000000000..91797de12
--- /dev/null
+++ b/agent/src/trading/connectors/mstock/profiles.py
@@ -0,0 +1,36 @@
+"""Built-in mStock connector profiles.
+
+mStock exposes one production REST host and no paper/sandbox environment, so
+there is no runtime paper/live discriminator to protect. Its settled tier is
+therefore bounded live under the mandate gate, following the Robinhood,
+Scalable, and KIS line. This first cut registers only the read-only Type B
+profile; the subsequent HTTP read path will map holdings into the shared
+portfolio shape before account data is advertised as usable.
+"""
+
+from __future__ import annotations
+
+from src.trading.types import TradingProfile
+
+#: Only the two capabilities required for portfolio-connection eligibility.
+#: Order discovery/history and market data deliberately wait for their HTTP
+#: read mapping in a reviewed follow-up; no order-path capability is declared.
+MSTOCK_READ_CAPABILITIES = ("account.read", "positions.read")
+
+MSTOCK_PROFILES: tuple[TradingProfile, ...] = (
+ TradingProfile(
+ id="mstock-live-rest-readonly",
+ connector="mstock",
+ label="mStock Live · REST Read-Only (India)",
+ environment="live",
+ transport="broker_sdk",
+ capabilities=MSTOCK_READ_CAPABILITIES,
+ readonly=True,
+ config={"auth_flavor": "typeb"},
+ notes=(
+ "Registry-only first cut for mStock's production Type B REST API; "
+ "no credentials are stored here and the HTTP read mapper is a "
+ "follow-up. This profile exposes no order path."
+ ),
+ ),
+)
diff --git a/agent/src/trading/profiles.py b/agent/src/trading/profiles.py
index 0dcd3d57a..7348ee47f 100644
--- a/agent/src/trading/profiles.py
+++ b/agent/src/trading/profiles.py
@@ -13,6 +13,7 @@ from src.trading.connectors.futu.profiles import FUTU_PROFILES
from src.trading.connectors.ibkr.profiles import IBKR_PROFILES
from src.trading.connectors.kis.profiles import KIS_PROFILES
from src.trading.connectors.longbridge.profiles import LONGBRIDGE_PROFILES
+from src.trading.connectors.mstock.profiles import MSTOCK_PROFILES
from src.trading.connectors.mt5.profiles import MT5_PROFILES
from src.trading.connectors.okx.profiles import OKX_PROFILES
from src.trading.connectors.robinhood.profiles import ROBINHOOD_PROFILES
@@ -48,6 +49,7 @@ BUILTIN_PROFILES: tuple[TradingProfile, ...] = (
*UPBIT_PROFILES,
*TOSS_PROFILES,
*SCALABLE_PROFILES,
+ *MSTOCK_PROFILES,
)
diff --git a/agent/tests/test_mstock_connector.py b/agent/tests/test_mstock_connector.py
new file mode 100644
index 000000000..9d1697e12
--- /dev/null
+++ b/agent/tests/test_mstock_connector.py
@@ -0,0 +1,94 @@
+"""Tests for the registry-only mStock read-only first cut (#1367)."""
+
+from __future__ import annotations
+
+import ast
+from pathlib import Path
+
+import pytest
+
+from src.trading import profiles, service
+from src.trading.connections import is_portfolio_connection_profile
+
+pytestmark = pytest.mark.unit
+
+_CONNECTOR_ROOT = Path(__file__).resolve().parents[1] / "src" / "trading" / "connectors" / "mstock"
+_PROFILE_ID = "mstock-live-rest-readonly"
+
+
+def test_mstock_profile_is_registered_and_readonly() -> None:
+ profile = profiles.profile_by_id(_PROFILE_ID)
+
+ assert profile.connector == "mstock"
+ assert profile.environment == "live"
+ assert profile.transport == "broker_sdk"
+ assert profile.readonly is True
+ assert profile.config == {"auth_flavor": "typeb"}
+ assert profile.capabilities == ("account.read", "positions.read")
+ assert is_portfolio_connection_profile(profile) is True
+
+
+def test_mstock_profile_has_no_order_path_capability() -> None:
+ profile = profiles.profile_by_id(_PROFILE_ID)
+ declared = {p.id for p in profiles.list_profiles() if p.connector == "mstock"}
+
+ assert declared == {_PROFILE_ID}
+ assert not any(
+ capability.startswith(("orders.", "runner.", "positions.close."))
+ for capability in profile.capabilities
+ )
+ assert "orders.place" not in profile.capabilities
+ assert "orders.place.requires_mandate" not in profile.capabilities
+
+
[email protected]("operation", ["place_order", "cancel_order"])
+def test_mstock_order_service_refuses_before_a_connector_sdk(operation: str) -> None:
+ result = getattr(service, operation)(
+ "RELIANCE",
+ _PROFILE_ID,
+ side="buy" if operation == "place_order" else None,
+ quantity=1,
+ )
+
+ assert result["status"] == "error"
+ assert result["profile_id"] == _PROFILE_ID
+ assert result["connector"] == "mstock"
+ assert result["environment"] == "live"
+ assert "does not support orders." in result["error"]
+
+
+def test_mstock_is_bounded_live_not_paper_capped() -> None:
+ tier_path = _CONNECTOR_ROOT.parents[3] / "tests" / "test_paper_capped_connectors_refuse_live.py"
+ tree = ast.parse(tier_path.read_text(encoding="utf-8"))
+ tiers = {}
+ for node in tree.body:
+ if not isinstance(node, ast.Assign):
+ continue
+ for target in node.targets:
+ if not isinstance(target, ast.Name) or target.id not in {"_LIVE_CAPABLE", "_PAPER_CAPPED"}:
+ continue
+ value = node.value
+ if isinstance(value, ast.Call) and getattr(value.func, "id", "") == "frozenset":
+ value = value.args[0]
+ tiers[target.id] = frozenset(ast.literal_eval(value))
+
+ assert "mstock" in tiers["_LIVE_CAPABLE"]
+ assert "mstock" not in tiers["_PAPER_CAPPED"]
+
+
+def test_first_cut_adds_no_http_auth_or_order_surface() -> None:
+ assert not (_CONNECTOR_ROOT / "sdk.py").exists()
+ for path in _CONNECTOR_ROOT.glob("*.py"):
+ tree = ast.parse(path.read_text(encoding="utf-8"))
+ function_names = {
+ node.name for node in ast.walk(tree) if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef))
+ }
+ imported_roots = set()
+ for node in ast.walk(tree):
+ if isinstance(node, ast.Import):
+ imported_roots.update(alias.name.split(".")[0] for alias in node.names)
+ elif isinstance(node, ast.ImportFrom) and node.module:
+ imported_roots.add(node.module.split(".")[0])
+
+ assert not function_names & {"place_order", "cancel_order", "authenticate"}
+ assert not imported_roots & {"httpx", "requests", "aiohttp", "urllib"}
diff --git a/agent/tests/test_paper_capped_connectors_refuse_live.py b/agent/tests/test_paper_capped_connectors_refuse_live.py
index 0f54f5103..3e504d117 100644
--- a/agent/tests/test_paper_capped_connectors_refuse_live.py
+++ b/agent/tests/test_paper_capped_connectors_refuse_live.py
@@ -51,6 +51,8 @@ _LIVE_CAPABLE = frozenset(
# against. Tier settled as bounded live in #1367; the profile that ships
# today is read-only and exposes no order capability.
"scalable",
+ # mStock has only a production host and no paper environment, so no discriminator ambiguity exists (#1367).
+ "mstock",
}
)