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

# Quote a market

> The best price to buy a quantity across venues right now, or to sell it from the shares the account holds, with the venue legs that would fill it. A venue symbol is quoted on the one listing it names, which is all an order naming it trades. Nothing is placed or reserved, and books can move before you order.



## OpenAPI

````yaml api-reference/openapi.json GET /markets/{id}/quote
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:
  /markets/{id}/quote:
    get:
      tags:
        - Markets
      summary: Quote a market
      description: >-
        The best price to buy a quantity across venues right now, or to sell it
        from the shares the account holds, with the venue legs that would fill
        it. A venue symbol is quoted on the one listing it names, which is all
        an order naming it trades. Nothing is placed or reserved, and books can
        move before you order.
      operationId: quoteMarket
      parameters:
        - schema:
            type: string
            minLength: 1
            maxLength: 512
            description: >-
              A market id from GET /markets, or a venue symbol that names one
              market: a Polymarket token id, a Hyperliquid book coin (`#…`,
              written `%23…` in a path), or a leg `ticker` (`pm:…`, `hl:…`,
              `pmus:…` or a Kalshi market ticker) that lists only this outcome.
              A symbol that names more than one market, such as a Polymarket
              condition id, is refused with 400; use the token id or the market
              id instead.
            example: >-
              mkt_bmZsOjIwMjYtMTAtMTE6REVOLUxBQwpzcHJlYWQ6Z2FtZTpERU46LTMuNQpERU4
          required: true
          description: >-
            A market id from GET /markets, or a venue symbol that names one
            market: a Polymarket token id, a Hyperliquid book coin (`#…`,
            written `%23…` in a path), or a leg `ticker` (`pm:…`, `hl:…`,
            `pmus:…` or a Kalshi market ticker) that lists only this outcome. A
            symbol that names more than one market, such as a Polymarket
            condition id, is refused with 400; use the token id or the market id
            instead.
          name: id
          in: path
        - schema:
            type: string
            enum:
              - buy
              - sell
            default: buy
          required: false
          name: action
          in: query
        - schema:
            type: string
            pattern: ^\d+(?:\.\d+)?$
            description: Shares to buy or sell. Send exactly one of quantity or notional.
            example: '10'
          required: false
          description: Shares to buy or sell. Send exactly one of quantity or notional.
          name: quantity
          in: query
        - schema:
            type: string
            pattern: ^\d+(?:\.\d{1,2})?$
            description: >-
              Dollars to spend on a buy, in place of quantity. The quote covers
              the shares that amount buys within limit_price and
              max_slippage_bps, when set.
            example: '25'
          required: false
          description: >-
            Dollars to spend on a buy, in place of quantity, at most two
            decimals. The quote covers the shares that amount buys within
            limit_price and max_slippage_bps, when set.
          name: notional
          in: query
      responses:
        '200':
          description: >-
            Best executable route for buying a quantity, or for selling it from
            the shares held; places nothing
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      success:
                        type: boolean
                        enum:
                          - true
                      data:
                        type: object
                        properties:
                          market_id:
                            type: string
                            minLength: 1
                            description: >-
                              The market id from GET /markets, however the
                              request named the market.
                          action:
                            type: string
                            enum:
                              - buy
                              - sell
                          quantity:
                            type: string
                            pattern: ^\d+(?:\.\d+)?$
                          executable_quantity:
                            type: string
                            pattern: ^\d+(?:\.\d+)?$
                          average_price:
                            type: string
                            nullable: true
                          legs:
                            type: array
                            items:
                              type: object
                              properties:
                                venue:
                                  type: string
                                  enum:
                                    - kalshi
                                    - polymarket
                                    - polymarket_us
                                    - hyperliquid
                                ticker:
                                  type: string
                                  minLength: 1
                                side:
                                  type: string
                                  enum:
                                    - 'yes'
                                    - 'no'
                                quantity:
                                  type: string
                                  pattern: ^\d+(?:\.\d+)?$
                                average_price:
                                  type: string
                                limit_price:
                                  type: string
                                fee_usd:
                                  type: string
                                  pattern: ^\d+(?:\.\d+)?$
                                executable:
                                  type: boolean
                              required:
                                - venue
                                - ticker
                                - side
                                - quantity
                                - average_price
                                - limit_price
                                - fee_usd
                                - executable
                          expected_total_usd:
                            type: string
                            pattern: ^\d+(?:\.\d+)?$
                          max_total_usd:
                            type: string
                            pattern: ^\d+(?:\.\d+)?$
                          network_cost_usd:
                            type: string
                            pattern: ^\d+(?:\.\d+)?$
                          limited_by:
                            type: string
                            nullable: true
                          quoted_at:
                            type: string
                            format: date-time
                          expires_at:
                            type: string
                            format: date-time
                          livemode:
                            type: boolean
                        required:
                          - market_id
                          - action
                          - quantity
                          - executable_quantity
                          - average_price
                          - legs
                          - expected_total_usd
                          - max_total_usd
                          - network_cost_usd
                          - limited_by
                          - quoted_at
                          - expires_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'
              examples:
                Quote:
                  summary: A buy of 5 shares
                  value:
                    success: true
                    data:
                      market_id: >-
                        mkt_bmZsOjIwMjYtMTAtMTE6REVOLUxBQwpzcHJlYWQ6Z2FtZTpERU46LTMuNQpERU4
                      action: buy
                      quantity: '5'
                      executable_quantity: '5'
                      average_price: '0.47'
                      legs:
                        - venue: hyperliquid
                          ticker: <venue ticker>
                          side: 'yes'
                          quantity: '5'
                          average_price: '0.47'
                          limit_price: '0.50'
                          fee_usd: '0'
                          executable: true
                        - venue: hyperliquid
                          ticker: <venue ticker>
                          side: 'yes'
                          quantity: '5'
                          average_price: '0.47'
                          limit_price: '0.50'
                          fee_usd: '0'
                          executable: true
                      expected_total_usd: '2.35'
                      max_total_usd: '2.5'
                      network_cost_usd: '0'
                      limited_by: null
                      quoted_at: '2026-10-11T18:00:00.000Z'
                      expires_at: '2026-10-11T18:00:15.000Z'
                      livemode: true
                    meta:
                      timestampMs: 1791741600000
                      requestId: c4e19a72-8d05-4f3b-a6e1-7b2d9c0f5e48
        '400':
          description: API error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              examples:
                Invalid quantity:
                  summary: quantity is not a positive decimal
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Invalid request
                      details:
                        - path: quantity
                          message: Invalid
                        - path: quantity
                          message: Invalid
                    meta:
                      timestampMs: 1791741600000
                      requestId: c4e19a72-8d05-4f3b-a6e1-7b2d9c0f5e48
        '401':
          description: Missing, invalid, expired or revoked API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              examples:
                Unknown key:
                  summary: Unknown, expired or revoked key
                  value:
                    success: false
                    error:
                      code: UNAUTHORIZED
                      message: Invalid, expired or revoked API key
                    meta:
                      timestampMs: 1791741600000
                      requestId: c4e19a72-8d05-4f3b-a6e1-7b2d9c0f5e48
                Missing key:
                  summary: No Authorization header
                  value:
                    success: false
                    error:
                      code: UNAUTHORIZED
                      message: Missing API key
                    meta:
                      timestampMs: 1791741600000
                      requestId: c4e19a72-8d05-4f3b-a6e1-7b2d9c0f5e48
        '403':
          description: The key lacks the scope this route needs
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              examples:
                Missing scope:
                  summary: The key lacks the read scope
                  value:
                    success: false
                    error:
                      code: FORBIDDEN
                      message: This API key lacks the read scope
                    meta:
                      timestampMs: 1791741600000
                      requestId: c4e19a72-8d05-4f3b-a6e1-7b2d9c0f5e48
        '404':
          description: API error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              examples:
                Not found:
                  summary: Market not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Market not found
                    meta:
                      timestampMs: 1791741600000
                      requestId: c4e19a72-8d05-4f3b-a6e1-7b2d9c0f5e48
        '409':
          description: >-
            A venue has stopped trading the market, so it has no book to quote;
            details.reason is MARKET_NOT_TRADABLE
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              examples:
                market_not_tradable:
                  summary: The venue stopped trading the market
                  value:
                    success: false
                    error:
                      code: CONFLICT
                      message: Polymarket has stopped trading this market
                      details:
                        reason: MARKET_NOT_TRADABLE
                    meta:
                      timestampMs: 1792771200000
                      requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '422':
          description: >-
            Send exactly one of quantity or notional, and notional only with a
            buy
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: VALIDATION_ERROR
                  message: >-
                    Send exactly one of quantity or notional, and notional only
                    with a buy
                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'
              examples:
                Rate limited:
                  summary: Over 5 requests a second; wait for Retry-After
                  value:
                    success: false
                    error:
                      code: RATE_LIMITED
                      message: Too many requests for this API key
                    meta:
                      timestampMs: 1791741600000
                      requestId: c4e19a72-8d05-4f3b-a6e1-7b2d9c0f5e48
        '500':
          description: API error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              examples:
                Internal error:
                  summary: Unexpected server error
                  value:
                    success: false
                    error:
                      code: INTERNAL_ERROR
                      message: An internal error occurred.
                    meta:
                      timestampMs: 1791741600000
                      requestId: c4e19a72-8d05-4f3b-a6e1-7b2d9c0f5e48
        '503':
          description: A venue failed or did not answer, or routing is paused
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              examples:
                Venue error:
                  summary: The venue failed or did not answer
                  value:
                    success: false
                    error:
                      code: UPSTREAM_ERROR
                      message: A required service is temporarily unavailable.
                    meta:
                      timestampMs: 1791741600000
                      requestId: c4e19a72-8d05-4f3b-a6e1-7b2d9c0f5e48
                Routing paused:
                  summary: Routing is not available, so quotes cannot be served
                  value:
                    success: false
                    error:
                      code: FEATURE_DISABLED
                      message: Cross-venue routing is paused
                    meta:
                      timestampMs: 1791741600000
                      requestId: c4e19a72-8d05-4f3b-a6e1-7b2d9c0f5e48
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.