> ## 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.

# Hedging sportsbook exposure

> Buy the other side on prediction market liquidity when liability crosses a threshold.

**Who it's for:** sportsbooks, B2B odds providers and fantasy operators carrying one sided
liability on a match.

**What you build:** an automatic hedger. When liability on an outcome crosses a threshold, it buys
the other side on prediction market liquidity.

## Call sequence

**1. Trigger**

Your liability feed crosses a threshold. Find the market with
[List markets](https://docs.lean.xyz/api-reference/markets/list-markets.md).

**2. Price and place the hedge**

[Quote a market](https://docs.lean.xyz/api-reference/markets/quote-market.md) →
[Preview an order](https://docs.lean.xyz/api-reference/orders/preview-order.md) →
[Place an order](https://docs.lean.xyz/api-reference/orders/create-order.md). If the cash is on the other venue,
the same call moves it and buys.

**3. Track and unwind**

Confirm each hedge with [Get an order](https://docs.lean.xyz/api-reference/orders/retrieve-order.md) and
[List fills](https://docs.lean.xyz/api-reference/orders/list-fills.md), and watch cash with
[Get balances](https://docs.lean.xyz/api-reference/account/list-balances.md). When liability falls, unwind with a
sell through [Place an order](https://docs.lean.xyz/api-reference/orders/create-order.md).

## Starter

```bash theme={"dark"}
# Hedge: buy 50 shares of the other side, worst price 0.55, fill now or not at all
curl -sS -X POST "$LEAN_API_URL/v1/orders" \
  -H "Authorization: Bearer $LEAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"client_order_id":"hedge-match123-1","market_id":"'"$MARKET_ID"'","action":"buy",
       "quantity":"50","limit_price":"0.55","time_in_force":"ioc","all_or_none":true}'
```

## Guardrails

* **Price protection.** `limit_price` sets the worst price you pay for the hedge.
* **Fill or nothing.** `time_in_force: ioc` with `all_or_none` places the hedge only if the books
  can fill the full size now. It is best effort: a book can move before the fill, so a partial
  hedge is still possible. See [All or none](https://docs.lean.xyz/orders.md#all-or-none). Polymarket takes `ioc` buys by
  dollar amount only, so a hedge sized with `quantity` fills on Hyperliquid.
* **One hedge per trigger.** Derive `client_order_id` from the match and trigger (for example
  `hedge-match123-1`). If your hedger fires twice, the second call returns the first order.
* **Spending caps.** The key's per order and rolling 24 hour limits bound how much any hedger can
  spend.
* **Kill switch.** [Pause order placement](https://docs.lean.xyz/api-reference/account/pause-trading.md) stops the hedger
  in one call.


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