> ## Documentation Index
> Fetch the complete documentation index at: https://molelcule.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Risk Controls — Limits, Kill Switch, and Cancel All

> Query risk state, configure per-subaccount risk limits, and activate the kill switch to halt all order activity. Endpoint: GET/PUT /v1/risk/limits.

The `client.risk` namespace exposes risk state inspection, per-subaccount limit configuration, an account-wide kill switch, and a risk-layer cancel-all endpoint. Use these controls to enforce pre-trade guardrails, respond to adverse market conditions, and satisfy operational risk requirements. The kill switch is a hard stop: activating it immediately halts all order submission and rejects new order requests until you explicitly deactivate it.

***

## risk.state

Retrieve the current risk state for a subaccount, including whether any limits are breached or the kill switch is active.

**Method:** `client.risk.state(subaccount_id)` — `GET /v1/risk`

```python theme={"dark"}
from molecule import Molecule

client = Molecule(
    base_url="https://api.molecule.trade",
    key_id="key_abc123",
    private_key="<base64-encoded-ed25519-seed>",
)

state = client.risk.state(subaccount_id="sa_abc123")
print(state)
```

<ParamField query="subaccount_id" type="string" required>
  The subaccount whose risk state to retrieve.
</ParamField>

***

## risk.limits

Retrieve configured risk limits. Pass a `subaccount_id` to get limits for a specific subaccount, or omit it to retrieve account-level limits.

**Method:** `client.risk.limits(subaccount_id=None)` — `GET /v1/risk/limits`

```python theme={"dark"}
# Retrieve limits for a specific subaccount
limits = client.risk.limits(subaccount_id="sa_abc123")
print(limits)

# Retrieve account-level limits
account_limits = client.risk.limits()
print(account_limits)
```

<ParamField query="subaccount_id" type="string">
  The subaccount whose risk limits to retrieve. Omit to retrieve account-level limits.
</ParamField>

***

## risk.set\_limits

Configure risk limits. Provide the fields you want to set as keyword arguments. Fields omitted retain their existing values.

**Method:** `client.risk.set_limits(**payload)` — `PUT /v1/risk/limits`

```python theme={"dark"}
client.risk.set_limits(
    subaccount_id="sa_abc123",
    max_order_qty="500",
    max_position_qty="2000",
    max_open_orders=50,
)
```

<ParamField body="subaccount_id" type="string">
  The subaccount to configure. Omit to set account-level limits.
</ParamField>

<ParamField body="max_order_qty" type="string">
  Maximum quantity allowed on a single order submission.
</ParamField>

<ParamField body="max_position_qty" type="string">
  Maximum aggregate position size across all instruments.
</ParamField>

<ParamField body="max_open_orders" type="integer">
  Maximum number of simultaneously resting orders.
</ParamField>

***

## risk.kill\_switch

Activate or deactivate the kill switch. When activated, Molecule immediately rejects all new order submissions and returns `ForbiddenError` with error code `kill_switch`. Deactivating the kill switch restores normal order flow.

**Method:** `client.risk.kill_switch(enabled)` — `POST /v1/risk/kill-switch`

```python theme={"dark"}
# Halt all activity immediately
client.risk.kill_switch(enabled=True)

# Resume
client.risk.kill_switch(enabled=False)
```

<ParamField body="enabled" type="boolean" required>
  Pass `True` to activate the kill switch and halt all order submission. Pass `False` to deactivate it and resume normal operation.
</ParamField>

<Warning>
  Activating the kill switch is **immediate and affects all subaccounts** associated with your API key. Any in-flight orders that have not yet been acknowledged by the venue may still execute. Open resting orders are **not** automatically cancelled — use `risk.cancel_all()` or `orders.cancel_all()` first if you need to remove resting orders simultaneously.
</Warning>

***

## risk.cancel\_all

Cancel all open orders for a subaccount via the risk layer.

**Method:** `client.risk.cancel_all(subaccount_id)` — `POST /v1/risk/cancel-all`

```python theme={"dark"}
client.risk.cancel_all(subaccount_id="sa_abc123")
```

<ParamField body="subaccount_id" type="string" required>
  The subaccount whose open orders to cancel.
</ParamField>

***

## Error reference

| Exception | HTTP status | When raised |
| - | - | - |
| `UnauthorizedError` | 401 | Invalid or missing Ed25519 signature |
| `ForbiddenError` | 403 | Kill switch active (error code `kill_switch`) or insufficient permissions |
| `ValidationError` | 422 | Invalid limit values or missing required fields |
| `NotFoundError` | 404 | Subaccount not found |
| `RateLimitedError` | 429 | Request rate limit exceeded |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.