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

# Risk gates

> Pre-trade safety rails that fail-closed before every order placed by autopilot, CLI agent, terminal, or intent executor.

<Warning>
  Every order — autopilot, CLI agent, web terminal trade ticket, intent executor — runs through these gates. They fail-closed on every violation: the order is rejected with a structured reason, never silently downsized.
</Warning>

## Gate checks (entry orders)

| Check                   | Failing condition                                                    |
| ----------------------- | -------------------------------------------------------------------- |
| **Min balance**         | `balance_cents < min_balance_cents`                                  |
| **Single-order cap**    | `order_cost_cents > max_single_order_cents`                          |
| **Total exposure**      | `(current_exposure + order_cost) > max_total_exposure_cents`         |
| **Daily loss cap**      | `\|daily_realized_pnl\| > max_daily_loss_cents` (if PnL is negative) |
| **Position count**      | `open_positions >= max_positions`                                    |
| **Orders this tick**    | `orders_this_tick >= max_orders_per_tick`                            |
| **Cooldown after loss** | `ticks_since_last_loss < cooldown_after_loss_ticks`                  |

## Gate checks (exit orders)

Exit orders skip the position-count and exposure gates (they reduce exposure), but still respect single-order cap and daily-loss cap.

## Configuration

Per-user limits live in `portfolio_config`. Update with:

```bash theme={null}
sf portfolio config max_total_exposure_cents 500000
sf portfolio config max_per_market_cents 150000
```

Defaults:

```text theme={null}
max_total_exposure_cents:    300000  ($3,000)
max_per_market_cents:        100000  ($1,000)
max_daily_loss_cents:        15000   ($150)
max_positions:               20
min_balance_cents:           10000   ($100)
max_orders_per_tick:         3
max_single_order_cents:      20000   ($200)
cooldown_after_loss_ticks:   4
```

## Drawdown halt

Two thresholds beyond per-trade gates:

* `drawdown_warn_cents` (default \$300) — emits a `health_alert` but doesn't halt.
* `max_drawdown_halt_cents` (default \$500) — auto-flips `execution_mode` to `halted`. Recoverable only by manual `sf portfolio config executionMode live`.

## Where gates apply

The same gate semantics apply across the CLI agent, web terminal trade ticket, intent executor, and portfolio autopilot. Treat the gate result as the contract: accepted orders proceed, rejected orders return a structured reason.

## Next steps

<CardGroup cols={2}>
  <Card title="Portfolio autopilot" href="/guides/portfolio-autopilot">
    The autopilot runtime calling these gates.
  </Card>

  <Card title="Trade intents" href="/build/trade-intents">
    Gate also runs on intent submission.
  </Card>
</CardGroup>
