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

# Conditional sells

> Sell one position and have Lean sell related positions by the same count as it fills.

A conditional sell sells one position, the leader, and as each leader share sells, Lean sells one
share of every other position you name, the followers. Each follower has a floor price it never
sells below. Use it to unwind positions that only make sense together, such as both sides of a
hedge on two venues, without one side being left open.

Conditional sells run on Kalshi, Polymarket, Polymarket US and Hyperliquid, and the legs may be on
different venues. A leg naming `lighter` is refused with `422` and reason `NO_EXECUTABLE_VENUE`.
This example uses a test key, so nothing real moves:

```bash theme={"dark"}
curl -sS -X POST "$LEAN_API_URL/v1/conditional-sells" \
  -H "Authorization: Bearer $LEAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "leader": {
      "market_id": "'"$LEADER_MARKET_ID"'",
      "venue": "kalshi",
      "type": "limit",
      "limit_price": "0.62"
    },
    "quantity": "25",
    "followers": [
      {
        "market_id": "'"$FOLLOWER_MARKET_ID"'",
        "venue": "polymarket",
        "floor_price": "0.55"
      }
    ]
  }'
```

| Field | Meaning |
| - | - |
| `leader.market_id` | A `mkt_…` ID from `GET /v1/markets` for the position the leader sells. |
| `leader.venue` | `kalshi`, `polymarket`, `polymarket_us` or `hyperliquid`: the venue holding the leader's shares. |
| `leader.type` | `limit` rests a sell at `limit_price` at once. `stop` sells nothing until the best bid falls to `trigger_price`, then sells down to `trigger_price` minus `slippage_limit`. |
| `leader.limit_price` | For a `limit` leader only. The price the sell rests at, in dollars between `0.0001` and `0.9999` on the market's price ticks. |
| `leader.trigger_price` | For a `stop` leader only. The best bid that starts the sale. It must be below the current best bid, or the sale would start at once. |
| `leader.slippage_limit` | Optional, for a `stop` leader only. How far below `trigger_price` the sale may fill, in dollars above `0` and at most `0.2`. The default is `0.05`. |
| `quantity` | Shares the leader sells, as a decimal string. |
| `followers` | From one to five positions to sell as the leader fills. |
| `followers[].market_id` | A `mkt_…` ID for the follower's position. |
| `followers[].venue` | The venue holding the follower's shares. |
| `followers[].floor_price` | The lowest price the follower sells at, in dollars on the market's price ticks, at or below its current best bid. |

The key needs the `trade` scope. The answer is `200` with the conditional sell, which reads
`active` while the leader sells or waits, or `paused` with `pause_reason` `floor` when a follower
cannot sell at its floor yet.

## How it sells

The leader sells first. Each time leader shares fill, Lean sells the same number of shares of every
follower at the best bids down to that follower's floor, and leaves any shares that do not sell at
once resting at the floor. Each leg's `filled_quantity` and `avg_fill_price` grow as it sells, and
`unhedged_quantity` is the number of leader shares a follower has not matched yet.

For a conditional sell led by a `limit` leader, Lean pauses it with `pause_reason` `floor` while a
follower's book does not hold enough shares at or above its floor to match the leader, or while a
follower's book cannot be read for 30 seconds before the leader is placed. A leader already
resting on its venue stays live while a follower's book cannot be read. It carries on by itself
once every follower's book has held enough at its floor for 5 seconds.

| `status` | Final | Meaning |
| - | - | - |
| `active` | No | The leader is selling or waiting for its trigger. |
| `paused` | No | Selling stopped. `pause_reason` says why. |
| `hedging` | No | The leader has sold every share and followers are still selling. |
| `filled` | Yes | Every leg has sold every share. |
| `canceled` | Yes | Canceled by you, or the venue refused the first leader order, which `reject_reason` explains. Shares already sold stay sold. |

A follower's `state` is `idle` before it has anything to sell, `selling` while a sell works,
`retrying` after a sell failed and another is on its way, `below_minimum` while the shares it owes
are under the venue's minimum order, `failed` once it runs out of retries, and `done` once it has
sold every share it owes. A `failed` follower stays unsold until you retry it in the Lean app or
sell it yourself.

`pause_reason` is `floor` for a follower floor, `user` when the sell was paused in the Lean app, or
one of `leader_unconfirmed`, `leader_ended`, `leader_account_changed` and `leader_rejected` when the
venue did not confirm, ended or refused the leader order.

A conditional sell paused for a reason that starts with `leader_` waits for you: resume it in the
Lean app, or cancel it.

## Limits on what can be sold

* Every leg, the leader included, is a different position the trading account holds. Each must
  hold `quantity` shares beyond what the account's resting sells, stop losses and other
  conditional sells already cover, or the request is refused with `400 VALIDATION_ERROR`.
* With a live key, a follower whose market has no bid, or whose floor is above its best bid, does
  not refuse the request. A conditional sell led by a `limit` leader starts `paused` with
  `pause_reason` `floor`, and one led by a `stop` leader starts `active`. A test key refuses such a
  follower with `400 VALIDATION_ERROR`.
* A `stop` leader whose trigger is at or above its best bid, or whose market has no bid, is refused
  with `400 VALIDATION_ERROR`.
* Every leg's market must be open, or the request is refused with `400 VALIDATION_ERROR`, and it
  must trade on the venue you name. A leg that cannot be traded on its venue is refused with
  `422 VALIDATION_ERROR` and `details.reason: "NO_EXECUTABLE_VENUE"`, and a venue the trading
  account does not allow with `details.reason: "VENUE_NOT_ALLOWED"`.
* A conditional sell counts toward the key's rolling day as orders at the leader's lowest price and
  each follower's floor would. It only takes risk off, so neither the per order nor the daily limit
  refuses it.
* With a live key, a request is refused with `403 FORBIDDEN` when the account can't trade on a
  leg's venue: for example, on Kalshi and Polymarket US no API key is connected in the Lean app, or
  on Polymarket the wallet isn't set up or its approvals need refreshing in the Lean app.
* Creating one is refused with `503 FEATURE_DISABLED` while trading is paused or, for a live key,
  while Lean has paused these orders on a leg's venue, and with `503 UPSTREAM_ERROR` when a leg's
  book could not be read. See [Pause trading](https://docs.lean.xyz/orders.md#pause-trading).

## Track and cancel

`GET /v1/conditional-sells` lists the conditional sells of the key's trading account, newest first:
every one still active, paused or hedging, and those that ended in the last day. A live key also
sees the conditional sells made in the Lean app on that account, as long as every leg is on a venue
the API trades. `GET /v1/conditional-sells/{id}` reads one. Conditional buys and OR orders made in
the Lean app are not part of the API: they are not listed, cannot be read and cannot be canceled
here. An ended conditional sell can stay in the list past the day until Lean has finished settling
it.

A conditional sell's sales are not orders you placed, so they send no `order` frame on the stream,
and their fills are listed in `GET /v1/fills` with `order_id` set to `null`. Each leg's
`filled_quantity` and `avg_fill_price` show what it has sold.

Cancel one with `DELETE /v1/conditional-sells/{id}`:

```bash theme={"dark"}
curl -sS -X DELETE "$LEAN_API_URL/v1/conditional-sells/$CONDITIONAL_SELL_ID" \
  -H "Authorization: Bearer $LEAN_API_KEY"
```

The answer is `200` with the conditional sell reading `canceled`. Lean cancels the leader's resting
sell and any follower sells still working, and shares already sold stay sold. Canceling works while
trading is paused. A conditional sell that has already ended is refused with `409 CONFLICT`.

Pausing trading does not stop a conditional sell that is already working. Cancel it if you want it
gone.

## Test keys

A test key's conditional sell is checked like a live one, against each leg's market and the test
account's simulated shares, and it can be listed, read and canceled. It never sells, so it stays
`active` until you cancel it, and its shares count as covered until then. See
[Test mode and live mode](https://docs.lean.xyz/test-mode.md).


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