Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(options): reject boolean payoff quantities

Wu Shuwen05f450e59ec5
diff --git a/agent/src/api/options_routes.py b/agent/src/api/options_routes.py
index 8e7372325..eccae6b45 100644
--- a/agent/src/api/options_routes.py
+++ b/agent/src/api/options_routes.py
@@ -76,6 +76,13 @@ class PayoffLeg(BaseModel):
qty: int
premium: float | None = Field(None, ge=0)
+ @field_validator("qty", mode="before")
+ @classmethod
+ def _qty_not_bool(cls, value: Any) -> Any:
+ if isinstance(value, bool):
+ raise ValueError("qty must be a non-zero integer")
+ return value
+
@field_validator("qty")
@classmethod
def _qty_nonzero(cls, v: int) -> int:
diff --git a/agent/tests/test_options_routes.py b/agent/tests/test_options_routes.py
index de6d8d55d..5a796d186 100644
--- a/agent/tests/test_options_routes.py
+++ b/agent/tests/test_options_routes.py
@@ -141,6 +141,13 @@ def test_payoff_rejects_empty_legs() -> None:
assert _client().post("/options/payoff", json=_long_call_body(legs=[])).status_code == 422
+def test_payoff_rejects_boolean_qty() -> None:
+ body = _long_call_body(
+ legs=[{"option_type": "call", "strike": 100.0, "qty": True}],
+ )
+ assert _client().post("/options/payoff", json=body).status_code == 422
+
+
def test_payoff_rejects_zero_qty_and_spot_points_below_min() -> None:
client = _client()
zero_qty = _long_call_body(legs=[{"option_type": "call", "strike": 100.0, "qty": 0}])