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

# Model driven trading with hard limits

> A bot that turns model edge into orders, with spending caps the API enforces.

**Who it's for:** quant teams that have a pricing model and want it trading around the clock.

**What you build:** a bot that turns model edge into orders. Its limits are enforced by the API,
not only by the bot.

## Call sequence

**1. Get data**

[Get prices](https://docs.lean.xyz/api-reference/markets/list-prices.md),
[Get recent trades](https://docs.lean.xyz/api-reference/markets/list-market-trades.md) and
[Get a market orderbook](https://docs.lean.xyz/api-reference/markets/retrieve-market-book.md), plus the WebSocket stream
([Create a stream ticket](https://docs.lean.xyz/api-reference/streaming/create-stream-ticket.md)).

**2. Trade on edge**

[Preview an order](https://docs.lean.xyz/api-reference/orders/preview-order.md), then
[Place an order](https://docs.lean.xyz/api-reference/orders/create-order.md) with a deterministic `client_order_id`
(for example, model run plus signal id). A retry returns the same order, never a second one.

**3. Set guardrails**

[Get account configuration](https://docs.lean.xyz/api-reference/account/retrieve-account-config.md) shows the per order
and rolling 24 hour limits the key is held to.
[Lower this key's limits](https://docs.lean.xyz/api-reference/account/lower-key-limits.md) lets a bot key tighten its
own limits; raising them needs a person signed in to Lean.
[Pause order placement](https://docs.lean.xyz/api-reference/account/pause-trading.md) is the kill switch: a key can
stop itself or its whole trading account, and only the Lean dashboard can resume.

**4. Reconcile**

[List orders](https://docs.lean.xyz/api-reference/orders/list-orders.md),
[Get an order](https://docs.lean.xyz/api-reference/orders/retrieve-order.md),
[List fills](https://docs.lean.xyz/api-reference/orders/list-fills.md) and
[Get balances](https://docs.lean.xyz/api-reference/account/list-balances.md).

## Starter

```bash theme={"dark"}
# Tighten this key to $25 per order and $200 per rolling 24 hours
curl -sS -X POST "$LEAN_API_URL/v1/account/limits" \
  -H "Authorization: Bearer $LEAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"max_order_notional_usd":"25","daily_notional_limit_usd":"200"}'

# Kill switch: stop new orders from this key
curl -sS -X POST "$LEAN_API_URL/v1/account/pause" \
  -H "Authorization: Bearer $LEAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"scope":"api_key","reason":"model drift"}'
```

## Guardrails

* **Idempotency.** Replaying a `client_order_id` with the same body returns the original order;
  reusing it with a different body is refused with 409.
* **Spending caps.** An order above the key's per order limit is refused with 422
  `ORDER_NOTIONAL_LIMIT`, and the rolling 24 hour limit caps total activity.
* **Kill switch.** One call to [Pause order placement](https://docs.lean.xyz/api-reference/account/pause-trading.md)
  stops the key or the whole trading account.
* **Slippage bounds.** `max_slippage_bps` caps every order when set.


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