> ## 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 limit chase

> Rests a limit order on the request’s venue a set distance behind the best price on its own side, and moves it as that price moves until the order fills, is canceled or expires. A buy follows the best bid and a sell the best ask. The order never crosses the spread, and never rests beyond price_limit when one is given. It is booked against the calling key’s limits at the most it can trade for: a buy as an order of this quantity at price_limit, or at the top price of $1 a share without one, and a sell at that same top price. A buy is held to the per-order cap, the account’s venue allow list and the rolling day; a sell only takes risk off, so it counts toward the rolling day and is held to the venue allow list, but no notional limit refuses it. On a test key the limit chase follows the live book and fills, in simulation, once the opposite best price reaches it. Every venue runs limit chases.



## OpenAPI

````yaml api-reference/openapi.json POST /limit-chases
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:
  /limit-chases:
    post:
      tags:
        - Limit chases
      summary: Create a limit chase
      description: >-
        Rests a limit order on the request’s venue a set distance behind the
        best price on its own side, and moves it as that price moves until the
        order fills, is canceled or expires. A buy follows the best bid and a
        sell the best ask. The order never crosses the spread, and never rests
        beyond price_limit when one is given. It is booked against the calling
        key’s limits at the most it can trade for: a buy as an order of this
        quantity at price_limit, or at the top price of $1 a share without one,
        and a sell at that same top price. A buy is held to the per-order cap,
        the account’s venue allow list and the rolling day; a sell only takes
        risk off, so it counts toward the rolling day and is held to the venue
        allow list, but no notional limit refuses it. On a test key the limit
        chase follows the live book and fills, in simulation, once the opposite
        best price reaches it. Every venue runs limit chases.
      operationId: createLimitChase
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                market_id:
                  type: string
                  minLength: 1
                  maxLength: 512
                  description: The market to trade.
                venue:
                  type: string
                  enum:
                    - kalshi
                    - polymarket
                    - polymarket_us
                    - hyperliquid
                    - lighter
                  description: >-
                    The venue to rest the order on. Limit chases run on every
                    venue but Lighter, which is refused with 422 and reason
                    NO_EXECUTABLE_VENUE.
                action:
                  type: string
                  enum:
                    - buy
                    - sell
                  description: buy or sell.
                quantity:
                  type: string
                  pattern: ^\d+(?:\.\d+)?$
                  description: >-
                    Shares to buy or sell. A sell is at most what the account
                    holds beyond its other resting sells and stop losses.
                offset_ticks:
                  type: integer
                  minimum: 0
                  maximum: 10
                  description: >-
                    How many price ticks behind the best price on its own side
                    the order rests, from 0 to 10. Give at most one of
                    offset_ticks, offset_price, offset_shares and
                    offset_beat_best.
                offset_price:
                  type: string
                  description: >-
                    How far behind the best price on its own side the order
                    rests, in dollars from 0 to 0.1. Give at most one of
                    offset_ticks, offset_price, offset_shares and
                    offset_beat_best.
                offset_shares:
                  type: string
                  pattern: ^\d+(?:\.\d+)?$
                  description: >-
                    The most shares the order lets rest ahead of it in the
                    queue, from 0 to 10,000,000 in steps of 0.01. The order
                    rests one tick inside the first price level that would put
                    more shares ahead of it. Give at most one of offset_ticks,
                    offset_price, offset_shares and offset_beat_best.
                offset_beat_best:
                  type: boolean
                  enum:
                    - true
                  description: >-
                    Set to true to rest one tick better than the best price on
                    its own side, so the order is first in the queue. It stops
                    one tick short of the other side, so it never crosses the
                    spread. Give at most one of offset_ticks, offset_price,
                    offset_shares and offset_beat_best.
                price_limit:
                  type: string
                  description: >-
                    The worst price the order rests at, in dollars between
                    0.0001 and 0.9999: a buy never rests above it and a sell
                    never below it. Omit to follow the book wherever it goes.
                expires_at:
                  type: string
                  format: date-time
                  description: >-
                    When the limit chase lapses if it has not filled, in UTC
                    ending in Z, in the future and at most 30 days ahead. On
                    Polymarket, and on any venue with a test key, it must be at
                    least 2 minutes ahead. Omit to keep it until canceled.
              required:
                - market_id
                - venue
                - action
                - quantity
              additionalProperties: false
            example:
              market_id: >-
                mkt_bmZsOjIwMjYtMTAtMTE6REVOLUxBQwpzcHJlYWQ6Z2FtZTpERU46LTMuNQpERU4
              venue: polymarket
              action: buy
              quantity: '25'
              offset_ticks: 1
              price_limit: '0.45'
      responses:
        '200':
          description: The limit chase, following the book
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      success:
                        type: boolean
                        enum:
                          - true
                      data:
                        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'
                          action:
                            type: string
                            enum:
                              - buy
                              - sell
                          quantity:
                            type: string
                            pattern: ^\d+(?:\.\d+)?$
                          offset_ticks:
                            type: integer
                            nullable: true
                            minimum: 0
                            maximum: 10
                            description: >-
                              Ticks behind the best price, or null when the
                              chase uses another offset.
                          offset_price:
                            type: string
                            nullable: true
                            description: >-
                              Dollars behind the best price, or null when the
                              chase uses another offset.
                          offset_shares:
                            type: string
                            nullable: true
                            pattern: ^\d+(?:\.\d+)?$
                            description: >-
                              The most shares the order lets rest ahead of it in
                              the queue, or null when the chase uses another
                              offset.
                          offset_beat_best:
                            type: boolean
                            description: >-
                              True when the order rests one tick better than the
                              best price on its own side.
                          offset_midpoint:
                            type: string
                            nullable: true
                            description: >-
                              For a limit chase made in the Lean app that rests
                              as far back as it can within this many dollars of
                              the midpoint, ignoring the best price on its own
                              side. Null when the chase uses another offset. A
                              request cannot set it.
                          price_limit:
                            type: string
                            nullable: true
                          status:
                            type: string
                            enum:
                              - active
                              - filled
                              - canceled
                              - failed
                              - expired
                          current_price:
                            type: string
                            nullable: true
                            description: >-
                              The price the order rests at now, or null while it
                              waits for a book to follow.
                          filled_quantity:
                            type: string
                            pattern: ^\d+(?:\.\d+)?$
                          avg_fill_price:
                            type: string
                            nullable: true
                          expires_at:
                            type: string
                            nullable: true
                            format: date-time
                          cancel_requested_at:
                            type: string
                            nullable: true
                            format: date-time
                            description: >-
                              When a cancel was asked for, or null. A live limit
                              chase keeps its status until Lean applies the
                              cancel a moment later, then reads canceled.
                          edit_pending:
                            type: boolean
                            nullable: true
                            description: >-
                              True while Lean has accepted an edit but not yet
                              applied it; the other fields show the edited
                              values meanwhile. A list can trail an edit
                              accepted a moment earlier; read the limit chase by
                              id to confirm.
                          last_error:
                            type: string
                            nullable: true
                            description: >-
                              Why Lean last refused an edit or could not rest
                              the order, or null. An edit Lean refuses, such as
                              a smaller size that fills overtook, leaves the
                              earlier values in place.
                          created_at:
                            type: string
                            format: date-time
                          updated_at:
                            type: string
                            format: date-time
                          livemode:
                            type: boolean
                        required:
                          - id
                          - market_id
                          - venue
                          - ticker
                          - side
                          - action
                          - quantity
                          - offset_ticks
                          - offset_price
                          - offset_shares
                          - offset_beat_best
                          - offset_midpoint
                          - price_limit
                          - status
                          - current_price
                          - filled_quantity
                          - avg_fill_price
                          - expires_at
                          - cancel_requested_at
                          - edit_pending
                          - last_error
                          - 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: 7b2f4e19-0c6d-4a83-9e51-d4a8b3c2f706
                  market_id: >-
                    mkt_bmZsOjIwMjYtMTAtMTE6REVOLUxBQwpzcHJlYWQ6Z2FtZTpERU46LTMuNQpERU4
                  venue: polymarket
                  ticker: >-
                    pm:0x2222222222222222222222222222222222222222222222222222222222222222
                  side: 'yes'
                  action: buy
                  quantity: '25'
                  offset_ticks: 1
                  offset_price: null
                  offset_shares: null
                  offset_beat_best: false
                  offset_midpoint: null
                  price_limit: '0.45'
                  status: active
                  current_price: '0.39'
                  filled_quantity: '0'
                  avg_fill_price: null
                  expires_at: null
                  cancel_requested_at: null
                  edit_pending: false
                  last_error: null
                  created_at: '2026-11-11T15:00:00.000Z'
                  updated_at: '2026-11-11T15:00:00.000Z'
                  livemode: false
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '400':
          description: >-
            The offset, price limit, quantity or expiry are invalid for this
            market, a test key’s buy costs more than its simulated balance, or a
            sell is more than the account holds beyond its other resting sells
            and stop losses
          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 the 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 limit chase 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 limit chase
                    was being created
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '422':
          description: >-
            details.reason is NO_EXECUTABLE_VENUE, VENUE_NOT_ALLOWED,
            ORDER_NOTIONAL_LIMIT or DAILY_NOTIONAL_LIMIT
          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, or Lean has
            paused limit chases on the venue for a live key
          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.