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

# Create a conditional sell

> Sells a leader position and, as it fills, sells the same number of shares of each follower position, never below the follower’s floor price. A limit leader rests a sell at limit_price at once; a stop leader waits until its best bid falls to trigger_price, then sells down to trigger_price minus slippage_limit. With a limit leader, the conditional sell pauses while a follower’s book holds too little at or above its floor, and resumes by itself once that depth has held for 5 seconds; a live key’s create can answer paused for that reason. Every leg is a different position this key’s trading account holds, on a venue its allow list includes, and each must hold the quantity beyond the account’s other resting sells, stop losses and conditional sells. The sale is booked as orders at the leader’s lowest price and each follower’s floor would be: it counts toward the rolling day and is held to the venue allow list, but as a sale it only takes risk off, so no notional limit refuses it. On a test key the conditional sell is checked, recorded, listed and booked but never sells. Kalshi, Polymarket, Polymarket US and Hyperliquid run conditional sells.



## OpenAPI

````yaml api-reference/openapi.json POST /conditional-sells
openapi: 3.0.0
info:
  title: Lean API
  version: 0.1.0
  description: >-
    Programmatic access to Lean: canonical sports markets, quotes, orders,
    positions and balances.
servers:
  - url: '{baseUrl}/v1'
    description: Lean API
    variables:
      baseUrl:
        default: https://api.lean.xyz
        description: >-
          The Lean API base URL, without /v1. Same value as LEAN_API_URL in the
          guides.
security:
  - apiKey: []
paths:
  /conditional-sells:
    post:
      tags:
        - Conditional sells
      summary: Create a conditional sell
      description: >-
        Sells a leader position and, as it fills, sells the same number of
        shares of each follower position, never below the follower’s floor
        price. A limit leader rests a sell at limit_price at once; a stop leader
        waits until its best bid falls to trigger_price, then sells down to
        trigger_price minus slippage_limit. With a limit leader, the conditional
        sell pauses while a follower’s book holds too little at or above its
        floor, and resumes by itself once that depth has held for 5 seconds; a
        live key’s create can answer paused for that reason. Every leg is a
        different position this key’s trading account holds, on a venue its
        allow list includes, and each must hold the quantity beyond the
        account’s other resting sells, stop losses and conditional sells. The
        sale is booked as orders at the leader’s lowest price and each
        follower’s floor would be: it counts toward the rolling day and is held
        to the venue allow list, but as a sale it only takes risk off, so no
        notional limit refuses it. On a test key the conditional sell is
        checked, recorded, listed and booked but never sells. Kalshi,
        Polymarket, Polymarket US and Hyperliquid run conditional sells.
      operationId: createConditionalSell
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                leader:
                  type: object
                  properties:
                    market_id:
                      type: string
                      minLength: 1
                      maxLength: 512
                      description: The market whose shares the leader sells.
                    venue:
                      type: string
                      enum:
                        - kalshi
                        - polymarket
                        - polymarket_us
                        - hyperliquid
                        - lighter
                      description: >-
                        The venue holding the leader’s shares. Lighter is
                        refused with 422 and reason NO_EXECUTABLE_VENUE.
                    type:
                      type: string
                      enum:
                        - limit
                        - stop
                      description: >-
                        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.
                    limit_price:
                      type: string
                      description: >-
                        For a limit leader, the price the sell rests at, in
                        dollars between 0.0001 and 0.9999 on the market’s price
                        tick.
                    trigger_price:
                      type: string
                      description: >-
                        For a stop leader, the best bid that starts the sale, in
                        dollars between 0.0001 and 0.9999. It must be below the
                        current best bid, or the sale would start at once.
                    slippage_limit:
                      type: string
                      description: >-
                        For a stop leader, how far below trigger_price the sale
                        may fill, in dollars above 0 and at most 0.2, below
                        trigger_price. Defaults to 0.05.
                  required:
                    - market_id
                    - venue
                    - type
                  additionalProperties: false
                  description: The position whose sale drives the rest.
                quantity:
                  type: string
                  pattern: ^\d+(?:\.\d+)?$
                  description: >-
                    Shares the leader sells. Each follower sells the same count
                    as the leader fills, so every leg’s position must cover it
                    beyond the account’s other resting sells, stop losses and
                    conditional sells.
                followers:
                  type: array
                  items:
                    type: object
                    properties:
                      market_id:
                        type: string
                        minLength: 1
                        maxLength: 512
                        description: The market whose shares the follower sells.
                      venue:
                        type: string
                        enum:
                          - kalshi
                          - polymarket
                          - polymarket_us
                          - hyperliquid
                          - lighter
                        description: >-
                          The venue holding the follower’s shares. Lighter is
                          refused with 422 and reason NO_EXECUTABLE_VENUE.
                      floor_price:
                        type: string
                        description: >-
                          The lowest price the follower sells at, in dollars
                          between 0.0001 and 0.9999 on the market’s price tick.
                          A test key also needs it at or below the follower’s
                          current best bid. With a limit leader, the conditional
                          sell pauses while the book holds too little at or
                          above it.
                    required:
                      - market_id
                      - venue
                      - floor_price
                    additionalProperties: false
                  minItems: 1
                  maxItems: 5
                  description: >-
                    From 1 to 5 positions to sell as the leader fills. Every
                    leg, leader included, is a different position.
              required:
                - leader
                - quantity
                - followers
              additionalProperties: false
            example:
              leader:
                market_id: >-
                  mkt_bmZsOjIwMjYtMTAtMTE6REVOLUxBQwpzcHJlYWQ6Z2FtZTpERU46LTMuNQpERU4
                venue: polymarket
                type: limit
                limit_price: '0.62'
              quantity: '25'
              followers:
                - market_id: mkt_bmZsOjIwMjYtMTAtMTE6REVOLUxBQwptb25leWxpbmU6Z2FtZTpERU4
                  venue: kalshi
                  floor_price: '0.55'
      responses:
        '200':
          description: >-
            The conditional sell, selling, waiting or paused for a follower’s
            floor
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      success:
                        type: boolean
                        enum:
                          - true
                      data:
                        type: object
                        properties:
                          id:
                            type: string
                            minLength: 1
                          status:
                            type: string
                            enum:
                              - active
                              - paused
                              - hedging
                              - canceled
                              - filled
                            description: >-
                              active: the leader is selling or waiting. paused:
                              selling stopped for pause_reason. hedging: the
                              leader is done and followers are still selling.
                              canceled or filled: ended.
                          pause_reason:
                            type: string
                            nullable: true
                            enum:
                              - user
                              - floor
                              - ceiling
                              - leader_unconfirmed
                              - leader_ended
                              - leader_account_changed
                              - leader_rejected
                            description: >-
                              Why a paused conditional sell stopped: floor when
                              a follower’s book holds too little at or above its
                              floor, user when it was paused in the app, or a
                              leader_ reason when the venue did not confirm,
                              ended or refused the leader order.
                          quantity:
                            type: string
                            pattern: ^\d+(?:\.\d+)?$
                          leader:
                            type: object
                            properties:
                              market_id:
                                type: string
                                nullable: true
                                minLength: 1
                              venue:
                                type: string
                                enum:
                                  - kalshi
                                  - polymarket
                                  - polymarket_us
                                  - hyperliquid
                              ticker:
                                type: string
                                minLength: 1
                              side:
                                type: string
                                enum:
                                  - 'yes'
                                  - 'no'
                              type:
                                type: string
                                enum:
                                  - limit
                                  - stop
                              limit_price:
                                type: string
                                description: >-
                                  The lowest price the leader sells at:
                                  limit_price for a limit leader, trigger_price
                                  minus slippage_limit for a stop.
                              trigger_price:
                                type: string
                                nullable: true
                              slippage_limit:
                                type: string
                                nullable: true
                              filled_quantity:
                                type: string
                                pattern: ^\d+(?:\.\d+)?$
                              avg_fill_price:
                                type: string
                                nullable: true
                            required:
                              - market_id
                              - venue
                              - ticker
                              - side
                              - type
                              - limit_price
                              - trigger_price
                              - slippage_limit
                              - filled_quantity
                              - avg_fill_price
                          followers:
                            type: array
                            items:
                              type: object
                              properties:
                                id:
                                  type: string
                                  minLength: 1
                                market_id:
                                  type: string
                                  nullable: true
                                  minLength: 1
                                venue:
                                  type: string
                                  enum:
                                    - kalshi
                                    - polymarket
                                    - polymarket_us
                                    - hyperliquid
                                ticker:
                                  type: string
                                  minLength: 1
                                side:
                                  type: string
                                  enum:
                                    - 'yes'
                                    - 'no'
                                floor_price:
                                  type: string
                                state:
                                  type: string
                                  enum:
                                    - idle
                                    - selling
                                    - retrying
                                    - below_minimum
                                    - failed
                                    - done
                                  description: >-
                                    idle: nothing to sell yet. selling: a sell
                                    is working. retrying: a sell failed and
                                    another will be sent. below_minimum: the
                                    shares owed are under the venue minimum and
                                    wait for more leader fills. failed: out of
                                    retries, so the shares stay unsold. done:
                                    every share owed is sold.
                                dispatched_quantity:
                                  type: string
                                  pattern: ^\d+(?:\.\d+)?$
                                filled_quantity:
                                  type: string
                                  pattern: ^\d+(?:\.\d+)?$
                                avg_fill_price:
                                  type: string
                                  nullable: true
                                unhedged_quantity:
                                  type: string
                                  pattern: ^\d+(?:\.\d+)?$
                                  description: >-
                                    Shares the leader has sold that this
                                    follower has not sold yet.
                                failed_attempts:
                                  type: integer
                                  minimum: 0
                              required:
                                - id
                                - market_id
                                - venue
                                - ticker
                                - side
                                - floor_price
                                - state
                                - dispatched_quantity
                                - filled_quantity
                                - avg_fill_price
                                - unhedged_quantity
                                - failed_attempts
                          unhedged_quantity:
                            type: string
                            pattern: ^\d+(?:\.\d+)?$
                            description: >-
                              The most leader shares sold that any follower has
                              not sold yet.
                          reject_reason:
                            type: string
                            nullable: true
                            description: >-
                              Why the venue refused the first leader order,
                              which canceled the conditional sell.
                          created_at:
                            type: string
                            format: date-time
                          updated_at:
                            type: string
                            format: date-time
                          livemode:
                            type: boolean
                        required:
                          - id
                          - status
                          - pause_reason
                          - quantity
                          - leader
                          - followers
                          - unhedged_quantity
                          - reject_reason
                          - created_at
                          - updated_at
                          - livemode
                      meta:
                        type: object
                        properties:
                          timestampMs:
                            type: integer
                            minimum: 0
                          requestId:
                            type: string
                            minLength: 1
                          traceId:
                            type: string
                            minLength: 1
                          cachedAtMs:
                            type: integer
                            minimum: 0
                          source:
                            type: string
                            enum:
                              - cache
                              - database
                              - clickhouse
                              - upstream
                              - fallback
                              - internal
                        required:
                          - timestampMs
                          - requestId
                    required:
                      - success
                      - data
                      - meta
                  - $ref: '#/components/schemas/ApiError'
              example:
                success: true
                data:
                  id: 5b2f8c14-7d3e-4a91-8c06-e4f1a9d27b30
                  status: active
                  pause_reason: null
                  quantity: '25'
                  leader:
                    market_id: >-
                      mkt_bmZsOjIwMjYtMTAtMTE6REVOLUxBQwpzcHJlYWQ6Z2FtZTpERU46LTMuNQpERU4
                    venue: polymarket
                    ticker: >-
                      pm:0x2222222222222222222222222222222222222222222222222222222222222222
                    side: 'yes'
                    type: limit
                    limit_price: '0.62'
                    trigger_price: null
                    slippage_limit: null
                    filled_quantity: '0'
                    avg_fill_price: null
                  followers:
                    - id: 9e41c7a2-3b58-4f6d-a0e9-7c2d5b18f364
                      market_id: >-
                        mkt_bmZsOjIwMjYtMTAtMTE6REVOLUxBQwptb25leWxpbmU6Z2FtZTpERU4
                      venue: kalshi
                      ticker: KXNFLGAME-26OCT11DENLAC-DEN
                      side: 'yes'
                      floor_price: '0.55'
                      state: idle
                      dispatched_quantity: '0'
                      filled_quantity: '0'
                      avg_fill_price: null
                      unhedged_quantity: '0'
                      failed_attempts: 0
                  unhedged_quantity: '0'
                  reject_reason: null
                  created_at: '2026-11-17T15:00:00.000Z'
                  updated_at: '2026-11-17T15:00:00.000Z'
                  livemode: false
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '400':
          description: >-
            The prices or quantity are invalid for a leg’s market, a leg’s
            market is not open, two legs are the same position, a stop leader’s
            trigger price is at or above its best bid, a leg holds less than the
            quantity beyond the account’s other sells, or, with a test key only,
            a follower has no bid or a floor above its best bid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: VALIDATION_ERROR
                  message: Invalid request
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '401':
          description: Missing, invalid, expired or revoked API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: UNAUTHORIZED
                  message: Invalid, expired or revoked API key
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '403':
          description: >-
            The key lacks the trade scope, or a live key’s account cannot trade
            on a leg’s venue: no API key is connected for Kalshi or Polymarket
            US, or the Polymarket wallet is not set up or its approvals need
            refreshing
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: FORBIDDEN
                  message: This API key lacks the scope this route needs
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '404':
          description: API error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: Not found
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '409':
          description: >-
            The Polymarket account setup changed while the conditional sell was
            being created; finish setup in the Lean app and send it again
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: CONFLICT
                  message: >-
                    The Polymarket account setup changed while the conditional
                    sell was being created
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '422':
          description: details.reason is NO_EXECUTABLE_VENUE or VENUE_NOT_ALLOWED
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: VALIDATION_ERROR
                  message: Refused by a limit; nothing was changed
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '429':
          description: API error
          headers:
            Retry-After:
              description: Seconds remaining in the upstream read cooldown, when available
              schema:
                type: integer
                minimum: 0
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: RATE_LIMITED
                  message: Too many requests for this API key
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '500':
          description: API error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: INTERNAL_ERROR
                  message: An internal error occurred.
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '503':
          description: >-
            Trading is paused for this key or its trading account, Lean has
            paused managed orders on a leg’s venue, or a leg’s book could not be
            read
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: FEATURE_DISABLED
                  message: A required service is temporarily unavailable.
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
components:
  schemas:
    ApiError:
      type: object
      properties:
        success:
          type: boolean
          enum:
            - false
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - VALIDATION_ERROR
                - NOT_FOUND
                - UNAUTHORIZED
                - FORBIDDEN
                - CONFLICT
                - UPSTREAM_ERROR
                - RATE_LIMITED
                - INTERNAL_ERROR
                - FEATURE_DISABLED
                - CONDITIONAL_SELL_REJECTED
                - CONDITIONAL_SELL_ACTIVE
            message:
              type: string
              minLength: 1
            details:
              nullable: true
          required:
            - code
            - message
        meta:
          type: object
          properties:
            timestampMs:
              type: integer
              minimum: 0
            requestId:
              type: string
              minLength: 1
            traceId:
              type: string
              minLength: 1
            cachedAtMs:
              type: integer
              minimum: 0
            source:
              type: string
              enum:
                - cache
                - database
                - clickhouse
                - upstream
                - fallback
                - internal
          required:
            - timestampMs
            - requestId
      required:
        - success
        - error
        - meta
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: >-
        A Lean API key, sent as `Authorization: Bearer <key>`. A test key
        (`lean_sk_test_...`) simulates orders and fills with no money; a live
        key (`lean_sk_live_...`) trades for real within the key's limits. Every
        successful response says which mode answered in `data.livemode`.

````

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