> ## Documentation Index
> Fetch the complete documentation index at: https://docs.limitless.exchange/llms.txt
> Use this file to discover all available pages before exploring further.

# Cancel and Replace Order

Cancel one order and submit its replacement in one request. The two actions are **not atomic**: cancellation and replacement have independent outcomes, and a successful cancellation does not guarantee a successful replacement.

## Request

| Field         | Type     | Description                                                                                                                                |
| ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `cancel`      | `object` | Identifies the order to cancel. Provide exactly one of `orderId` or `clientOrderId`.                                                       |
| `replacement` | `object` | A standard signed order request. It accepts the same fields as [`POST /orders`](/api-reference/trading/create-order), except `onBehalfOf`. |
| `mode`        | `string` | `STOP_ON_FAILURE` or `ALLOW_FAILURE`. Controls whether replacement is attempted after cancellation fails.                                  |
| `onBehalfOf`  | `number` | Optional profile ID for an authorized partner sub-account. Applies to both cancellation and replacement.                                   |

`replacement.ownerId` must own the order being cancelled. Put `onBehalfOf` only at the operation level, not inside `replacement`.
The `x-on-behalf-of` header is not supported by this endpoint.

### Failure modes

| Mode              | Cancellation fails       | Replacement result                                                                  |
| ----------------- | ------------------------ | ----------------------------------------------------------------------------------- |
| `STOP_ON_FAILURE` | Stops this operation     | `NOT_ATTEMPTED`                                                                     |
| `ALLOW_FAILURE`   | Continues this operation | Placement is attempted and reports `SUCCESS`, `FAILURE`, or `UNKNOWN` independently |

## Authentication and signing

Use a scoped API token with the `trading` scope and HMAC-sign the exact request body and path `/orders/cancel-replace`; see [Authentication](/developers/authentication#hmac-request-signing).

The cancellation itself is not EIP-712 signed. For a direct request, the replacement is a normal order and must contain an [EIP-712 signature](/developers/eip712-signing). The authenticated profile must be a valid signer of the order being cancelled.

For an authorized partner sub-account, set the operation-level `onBehalfOf` to the sub-account profile ID and set `replacement.ownerId` to the same ID. This path requires `delegated_signing` in addition to `trading`. If the replacement omits its order signature, the server signs it only for a managed server-wallet sub-account under the existing [delegated signing](/developers/authentication#delegated-signing) rules.

## Example: stop after cancellation failure

The order values below illustrate the request shape. Generate `order.signature` from the complete replacement payload instead of copying the placeholder signature.

```json theme={null}
{
  "cancel": {
    "clientOrderId": "old-order-001"
  },
  "replacement": {
    "ownerId": 12345,
    "orderType": "GTC",
    "marketSlug": "btc-100k",
    "clientOrderId": "replacement-001",
    "order": {
      "salt": "1778155025318314496",
      "maker": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
      "signer": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
      "taker": "0x0000000000000000000000000000000000000000",
      "tokenId": "19633204485790857949828516737993423758628930235371629943999544859324645414627",
      "makerAmount": 5000000,
      "takerAmount": 10000000,
      "nonce": 0,
      "price": 0.5,
      "feeRateBps": 0,
      "side": 0,
      "signature": "0x1234",
      "signatureType": 0
    }
  },
  "mode": "STOP_ON_FAILURE"
}
```

If `old-order-001` is not found, the response is `409 Conflict`:

```json theme={null}
{
  "cancel": {
    "status": "FAILURE",
    "error": {
      "code": "ORDER_NOT_FOUND",
      "message": "Order not found"
    }
  },
  "replacement": {
    "status": "NOT_ATTEMPTED"
  }
}
```

## Example: allow replacement after cancellation failure

Changing `mode` to `ALLOW_FAILURE` attempts the replacement even if cancellation fails. The replacement reports its own result. The response remains `409 Conflict` because the complete cancel-and-replace operation did not succeed:

```json theme={null}
{
  "cancel": {
    "status": "FAILURE",
    "error": {
      "code": "ORDER_NOT_FOUND",
      "message": "Order not found"
    }
  },
  "replacement": {
    "status": "FAILURE",
    "error": {
      "code": "400",
      "message": "Insufficient balance"
    }
  }
}
```

## Validation and outcomes

Request-level authentication, authorization, validation, market, signature, maintenance-mode, and receive-window failures return their ordinary HTTP status without a cancel/replace result. Maintenance-mode and receive-window rejections use `425 Too Early`.

A successful cancellation does not guarantee replacement success. Insufficient balance or allowance can produce `cancel.status: "SUCCESS"` with `replacement.status: "FAILURE"` and an HTTP-status error code such as `"400"`; the endpoint returns `409 Conflict`.

A receive-window or trading-availability rejection can likewise produce a successful cancellation with `replacement.status: "FAILURE"` and `error.code: "425"`.

```json theme={null}
{
  "cancel": {
    "status": "SUCCESS",
    "orderId": "6f52b6d2-6c9e-4a5c-8a4f-28ab4b7ff203"
  },
  "replacement": {
    "status": "FAILURE",
    "error": {
      "code": "425",
      "message": "order receive window expired: elapsed=2500ms, window=1500ms"
    }
  }
}
```

## Response semantics

`cancel.status` can be `SUCCESS`, `FAILURE`, or `UNKNOWN`. `replacement.status` can be `SUCCESS`, `FAILURE`, `UNKNOWN`, or `NOT_ATTEMPTED`.

| Outcome                                                                    | HTTP status    |
| -------------------------------------------------------------------------- | -------------- |
| Cancellation and replacement are both `SUCCESS`                            | `200 OK`       |
| Cancellation fails under `STOP_ON_FAILURE`; replacement is `NOT_ATTEMPTED` | `409 Conflict` |
| Cancellation fails under `ALLOW_FAILURE`; replacement is attempted         | `409 Conflict` |
| The service returns any other non-success top-level result                 | `409 Conflict` |

Operation error codes are strings, not a closed enum. A missing cancellation target uses `ORDER_NOT_FOUND`; request failures use their decimal HTTP status such as `400`, `404`, `409`, `425`, or `500`; other failures use `INTERNAL_ERROR`. `FAILURE` identifies a known failure and `UNKNOWN` an inconclusive outcome. Cancellation authorization failures remain request-level `401` or `403` responses.

<Warning>
  `replacement.status: "SUCCESS"` means the placement was accepted. It does not guarantee on-chain settlement. A matched replacement remains top-level `SUCCESS` when `replacement.data.execution.settlementStatus` is `FAILED`; the settlement failure and `reason` remain nested under `execution`. There is no top-level `SETTLEMENT_FAILED` replacement status.
</Warning>


## OpenAPI

````yaml POST /orders/cancel-replace
openapi: 3.0.0
info:
  title: Limitless Exchange API
  description: >-

    # Limitless Exchange Trading API


    *Production-ready API for prediction market trading, portfolio management,
    and market data*


    > 🎯 **Quick Navigation**: [Authentication](#tag/authentication) |
    [Markets](#tag/markets) | [Trading](#tag/trading) |
    [Portfolio](#tag/portfolio)


    ---
      


    ## 🚀 Quick Start


    Choose your preferred programming language for complete end-to-end
    implementation:


    ### Overview


    The Limitless Exchange API offers both REST and WebSocket integration:


    **REST API (Trading)**:

    1. **🔐 Authentication**: Use API key for all programmatic access

    2. **📊 Fetch Market Data**: Get market info including venue contract
    addresses (once per market)

    3. **📋 Order Creation**: Build and sign orders using EIP-712 structured
    data

    4. **🚀 Order Submission**: Submit signed orders and receive confirmations


    **WebSocket API (Real-Time Data)**:

    1. **🔌 Connection**: Connect to `/markets` namespace for real-time updates

    2. **📊 Subscriptions**: Subscribe to market prices and position changes

    3. **📡 Events**: Handle live market data and transaction updates


    ### 🔐 Authentication for API Users


    > **⚠️ DEPRECATION NOTICE**: Cookie-based session authentication is
    deprecated and will be removed within weeks. Please migrate to API keys
    immediately.


    | Method | Header | Status |

    |--------|--------|--------|

    | **API Key** | `X-API-Key: lmts_...` | ✅ Required for programmatic access |

    | Cookie Session | `Cookie: limitless_session=...` | ⚠️ Deprecated (removal
    imminent) |


    **Getting an API Key**


    API keys can only be created via the Limitless Exchange UI:

    1. Log in to [limitless.exchange](https://limitless.exchange) using your
    wallet

    2. Click your profile menu (top right)

    3. Select "Api keys"

    4. Generate a new key


    **Using Your API Key**


    Include in all requests via the `X-API-Key` header:


    ```bash

    # REST API

    curl -H "X-API-Key: lmts_your_key_here"
    https://api.limitless.exchange/markets


    # WebSocket - pass X-API-Key header during connection handshake

    ```


    ### Migration from Cookie to API Key


    If you're currently using cookie-based authentication, migrate by:


    1. **Generate an API key** via the UI (profile menu → Api keys)

    2. **Replace cookie header** with API key header:


    ```diff

    # Before (deprecated)

    - Cookie: limitless_session=your_session_token


    # After

    + X-API-Key: lmts_your_key_here

    ```


    3. **Remove session management code** - no more login flow or cookie
    handling needed


    ### Important: Venue System for CLOB Markets


    CLOB markets use a **venue system** where each market is associated with
    specific contract addresses. Before placing orders:


    1. **Fetch market data once**: `GET /markets/:slug` returns venue
    information

    2. **Use venue.exchange**: This is the `verifyingContract` for EIP-712 order
    signing

    3. **Cache the venue**: Venue data is static per market - fetch once and
    reuse


    **Sample venue response:**

    ```json

    {
      "venue": {
        "exchange": "0xA1b2C3...",
        "adapter": "0xD4e5F6..."
      }
    }

    ```


    ### Required Approvals


    Before trading, set up token approvals based on order type:


    | Order Type | Market Type | Approve To |

    |------------|-------------|------------|

    | BUY | All CLOB | USDC → `venue.exchange` |

    | SELL | Simple CLOB | CT → `venue.exchange` |

    | SELL | NegRisk/Grouped | CT → `venue.exchange` AND `venue.adapter` |


    ### Checksummed Addresses


    All addresses must use **checksummed format** (EIP-55 mixed-case):

    - Authentication: `x-account` header

    - Orders: `maker` and `signer` fields

    - Example: `0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed`


    ### Implementation Guides


    **[🐍 Python Quick Start](#description/-python-quick-start)**

    - REST API: eth-account, requests, and web3.py libraries

    - WebSocket: python-socketio, asyncio integration


    **[☕ Java Quick Start](#description/-java-quick-start)**  

    - REST API: Web3j, OkHttp3, and Jackson libraries


    **[📦 Node.js/TypeScript Quick
    Start](#description/-nodejs-typescript-quick-start)**

    - REST API: viem, ethers, and cross-fetch libraries

    - WebSocket: socket.io-client for real-time trading

    - Full TypeScript support with end-to-end examples


    **[🔌 WebSocket Integration](#description/-websocket-integration)**

    - Real-time market data and position updates

    - Production-ready Python client with authentication


    ---
      


    ## 🐍 Python Quick Start


    Complete end-to-end Python implementation for Limitless Exchange API
    integration.
      


    ### 🐍 Python E2E Order Creation Guide


    Complete Python implementation guide is being loaded from external
    documentation...


    **Guide Contents:**

    - 🔐 Complete authentication flow with eth-account

    - 📋 Order construction with Web3.py calculations

    - ✍️ EIP-712 structured data signing

    - 🚀 Order submission with requests library

    - ⚠️ Comprehensive error handling

    - 🛠️ Production deployment considerations


    *For the complete Python guide, ensure the file is available at
    docs/scripts-samples/python-e2e-order-creation.md*
        


    ## ☕ Java Quick Start


    Complete end-to-end Java implementation for Limitless Exchange API
    integration.
      


    ### ☕ Java E2E Order Creation Guide


    Complete Java enterprise implementation guide is being loaded from external
    documentation...


    **Guide Contents:**

    - 🔐 Complete authentication flow with Web3j

    - 📋 Order construction with BigInteger precision

    - ✍️ EIP-712 structured data signing

    - 🚀 Order submission with OkHttp3

    - ⚠️ Enterprise error handling patterns

    - 🏗️ Production Maven project structure


    *For the complete Java guide, ensure the file is available at
    docs/scripts-samples/java-e2e-order-creation.md*
        


    ## 📦 Node.js/TypeScript Quick Start


    Complete end-to-end Node.js/TypeScript implementation for trading and
    WebSocket subscriptions.
      


    ### 📦 Node.js/TypeScript Trading & WebSocket Guide


    Complete Node.js/TypeScript implementation guide is being loaded from
    external documentation...


    **Guide Contents:**

    - 🔐 **Authentication**: Wallet-based auth with ethers and viem

    - 📋 **Order Creation**: EIP-712 signing with viem WalletClient

    - 🚀 **Order Submission**: REST API integration with cross-fetch

    - 🔌 **WebSocket Subscriptions**: socket.io-client for real-time updates

    - 📊 **Market Data**: AMM prices and CLOB orderbook subscriptions

    - ⚠️ **Type Safety**: Full TypeScript support with proper types

    - 🛠️ **Production Ready**: Complete end-to-end working example


    **Key Features:**

    - **Combined Subscriptions**: Subscribe to both AMM and CLOB markets
    simultaneously

    - **Authentication Flow**: Complete wallet-based authentication with session
    management

    - **Trading Integration**: Place orders and receive real-time updates

    - **TypeScript First**: Type-safe implementation with proper interfaces


    *For the complete Node.js guide, ensure the file is available at
    docs/scripts-samples/node-socket-trading-and-subscribe.md*
        


    ## 🔌 WebSocket Integration


    Real-time market data and position updates using WebSocket connections.
      


    ### 🔌 WebSocket Real-Time Integration Guide


    Complete WebSocket implementation guide is being loaded from external
    documentation...


    **Guide Contents:**

    - 🔌 **WebSocket Connection**: python-socketio client with async support

    - 🔐 **Authentication**: JWT session cookie integration

    - 📊 **Market Subscriptions**: Real-time price updates and position changes

    - ⚡ **Event Handling**: Comprehensive event processing patterns

    - 🔄 **Auto-Reconnection**: Production-ready reconnection logic

    - 🛠️ **Error Recovery**: Robust error handling and fallback strategies


    **Key Features:**

    - **Public Mode**: Market price updates without authentication

    - **Authenticated Mode**: Full access to positions and transactions

    - **Multi-Market Support**: Subscribe to multiple markets simultaneously

    - **Production Ready**: Tested patterns for production deployment


    *For the complete WebSocket guide, ensure the file is available at
    docs/scripts-samples/python-socket-subscribe.md*
        
  version: '1.0'
  contact:
    name: API Support
    url: https://limitless.exchange
    email: hey@limitless.network
servers:
  - url: https://api.limitless.exchange
    description: Production API
security: []
tags:
  - name: Authentication
    description: User authentication and session management
  - name: Markets
    description: Browse, search, and analyze prediction markets
  - name: Market Navigation
    description: Navigation tree, market pages, and property filters
  - name: Trading
    description: Create, manage, and cancel orders
  - name: Portfolio
    description: Position tracking, trade history, and performance
  - name: Feed
    description: Public trading activity feeds
paths:
  /orders/cancel-replace:
    post:
      tags:
        - Trading
      summary: Cancel an order and place a replacement non-atomically
      operationId: OrderController_cancelReplace
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CancelReplaceDto'
      responses:
        '200':
          description: Cancellation and replacement both succeeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CancelReplaceResponseDto'
        '400':
          description: >-
            Request validation or cancel-replace preflight failed before
            mutation
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ValidationErrorResponse'
                  - $ref: '#/components/schemas/NestErrorResponse'
                  - $ref: '#/components/schemas/ErrorMessageResponse'
        '401':
          description: Authentication or cancellation authorization failed before mutation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NestErrorResponse'
        '403':
          description: >-
            Required scope, delegated target authorization, or replacement
            ownership check failed
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ErrorMessageResponse'
                  - $ref: '#/components/schemas/NestErrorResponse'
        '404':
          description: Replacement market or profile was not found during preflight
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NestErrorResponse'
        '409':
          description: Cancellation or replacement did not succeed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CancelReplaceResponseDto'
        '425':
          description: >-
            Request-wide receive-window or maintenance-mode preflight failure
            before cancellation
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ErrorMessageResponse'
                  - $ref: '#/components/schemas/TradingModeErrorResponse'
        '500':
          description: Unexpected request-wide server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorMessageResponse'
      security:
        - HmacAuth: []
components:
  schemas:
    CancelReplaceDto:
      type: object
      properties:
        cancel:
          description: Order to cancel; provide exactly one identifier
          allOf:
            - $ref: '#/components/schemas/CancelOrderCombinedDto'
        replacement:
          $ref: '#/components/schemas/CancelReplaceOrderDto'
        mode:
          type: string
          enum:
            - ALLOW_FAILURE
            - STOP_ON_FAILURE
          description: >-
            Whether to stop this operation or attempt replacement after
            cancellation failure
          example: STOP_ON_FAILURE
        onBehalfOf:
          type: number
          minimum: 1
          description: >-
            Authorized partner sub-account profile ID. Applies to both
            cancellation and replacement.
          example: 12345
      additionalProperties: false
      required:
        - cancel
        - replacement
        - mode
    CancelReplaceResponseDto:
      type: object
      properties:
        cancel:
          $ref: '#/components/schemas/CancelReplaceCancelResult'
        replacement:
          $ref: '#/components/schemas/CancelReplacePlacementResult'
      description: Independent cancellation and replacement outcomes.
      required:
        - cancel
        - replacement
    ValidationErrorResponse:
      type: object
      properties:
        message:
          type: array
          items:
            $ref: '#/components/schemas/ValidationErrorItem'
        error:
          type: string
          enum:
            - Bad Request
        statusCode:
          type: number
          enum:
            - 400
      additionalProperties: false
      required:
        - message
        - error
        - statusCode
    NestErrorResponse:
      type: object
      properties:
        message:
          type: string
        error:
          type: string
        statusCode:
          type: integer
      additionalProperties: false
      required:
        - message
        - error
        - statusCode
    ErrorMessageResponse:
      type: object
      properties:
        message:
          type: string
      additionalProperties: false
      required:
        - message
    TradingModeErrorResponse:
      type: object
      properties:
        code:
          type: string
          enum:
            - post_only_mode
            - cancel_only_mode
            - trading_disabled
        message:
          type: string
          example: >-
            Trading is currently cancel-only. New orders are not accepted, but
            cancels are allowed.
        mode:
          type: string
          enum:
            - post_only
            - cancel_only
            - disabled
        resumeAt:
          type: string
          format: date-time
          nullable: true
      additionalProperties: false
      required:
        - code
        - message
        - mode
    CancelOrderCombinedDto:
      type: object
      properties:
        orderId:
          type: string
          description: Internal order ID. Provide exactly one of orderId or clientOrderId.
          example: 6f52b6d2-6c9e-4a5c-8a4f-28ab4b7ff203
          format: uuid
          pattern: >-
            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$
        clientOrderId:
          type: string
          description: >-
            Client-provided order ID from order creation. Provide exactly one of
            orderId or clientOrderId.
          example: partner-order-001
          maxLength: 128
      additionalProperties: false
      oneOf:
        - required:
            - orderId
        - required:
            - clientOrderId
    CancelReplaceOrderDto:
      type: object
      properties:
        order:
          description: Order details including signature and amounts
          allOf:
            - $ref: '#/components/schemas/Order'
        ownerId:
          type: integer
          description: >-
            Required profile ID of the order owner. For delegated signing, send
            the target profile ID as both ownerId and onBehalfOf.
          example: 12345
        orderType:
          type: string
          description: >-
            Order type (GTC=Good Till Cancelled, FAK=Fill And Kill, FOK=Fill Or
            Kill)
          enum:
            - FAK
            - FOK
            - GTC
          example: GTC
        marketSlug:
          type: string
          description: Market identifier slug
          example: biden-vs-trump-2024
        postOnly:
          type: boolean
          description: >-
            Reject the order if it would match immediately. Supported only for
            GTC orders.
          example: true
        clientOrderId:
          type: string
          description: >-
            Optional owner-scoped uniqueness and deduplication key. The
            submitted value is limited to 128 characters, then trimmed; blank
            values are rejected. Reuse returns 409 rather than replaying an
            earlier response.
          example: client-order-001
          maxLength: 128
        timestamp:
          type: integer
          description: >-
            Optional client-stamped order creation time, Unix ms epoch.
            Top-level request field; not part of the EIP-712 signed order
            payload.
          example: 1735689600000
          minimum: 0
        recvWindow:
          type: integer
          description: >-
            Optional maximum accepted order age in milliseconds. Valid range: 1
            to 10000. If omitted, the server applies a 2000 ms default receive
            window. Top-level request field; not part of the EIP-712 signed
            order payload.
          example: 1500
          maximum: 10000
          minimum: 1
        stpPolicy:
          type: string
          description: >-
            Self-trade prevention policy. If omitted, defaults to cancel_maker.
            Top-level request field; not part of the EIP-712 signed order
            payload.
          enum:
            - cancel_both
            - cancel_maker
            - cancel_taker
          example: cancel_maker
      additionalProperties: false
      description: >-
        Replacement order fields. This is the POST /orders request shape without
        onBehalfOf; delegation is set on the enclosing cancel-replace operation.
      required:
        - order
        - ownerId
        - orderType
        - marketSlug
    CancelReplaceCancelResult:
      type: object
      properties: {}
      oneOf:
        - $ref: '#/components/schemas/CancelReplaceCancelSuccess'
        - $ref: '#/components/schemas/CancelReplaceCancelError'
    CancelReplacePlacementResult:
      type: object
      properties: {}
      oneOf:
        - $ref: '#/components/schemas/CancelReplacePlacementSuccess'
        - $ref: '#/components/schemas/CancelReplacePlacementError'
        - $ref: '#/components/schemas/CancelReplacePlacementNotAttempted'
    ValidationErrorItem:
      type: object
      properties:
        field:
          type: string
          example: orderIds
        message:
          type: string
          example: orderIds should not be empty
      additionalProperties: false
      required:
        - field
        - message
    Order:
      type: object
      properties:
        salt:
          description: >-
            Unique random value for signature uniqueness. Send unsafe integers
            as decimal strings to preserve EIP-712 bytes.
          oneOf:
            - type: string
              pattern: ^\d+$
              example: '1778155025318314496'
            - type: number
              example: 1234567890
        maker:
          type: string
          description: Ethereum address of the maker (order creator)
          example: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
          pattern: ^0x[a-fA-F0-9]{40}$
        signer:
          type: string
          description: Address that signed the order
          example: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
          pattern: ^0x[a-fA-F0-9]{40}$
        taker:
          type: string
          description: Specific taker address (optional for open orders)
          example: '0x0000000000000000000000000000000000000000'
          pattern: ^0x[a-fA-F0-9]{40}$
        tokenId:
          type: string
          description: Token ID being traded (YES or NO position ID from conditional token)
          example: >-
            19633204485790857949828516737993423758628930235371629943999544859324645414627
        makerAmount:
          type: integer
          description: >-
            Raw 6-decimal amount offered by the maker. For GTC/FAK: collateral
            for BUY or contracts for SELL. For FOK: maximum collateral for BUY
            or contracts for SELL.
          example: 5000000
          minimum: 100
        takerAmount:
          type: integer
          description: >-
            Raw 6-decimal amount requested. For GTC/FAK: contracts for BUY or
            collateral for SELL. For FOK this must equal 1.
          example: 10000000
          minimum: 1
        expiration:
          type: string
          description: >-
            Omission is signed as zero; if supplied, the value must represent
            zero because non-zero expiration is unsupported.
          example: '0'
          pattern: ^0+$
        nonce:
          type: number
          description: Required numeric zero.
          example: 0
          enum:
            - 0
        price:
          type: number
          description: >-
            Required for GTC/FAK and forbidden for FOK. Decimal price with at
            most three places; price × contracts must equal the collateral
            amount exactly as an integer.
          example: 0.75
          minimum: 0.01
          maximum: 0.99
          multipleOf: 0.001
        feeRateBps:
          type: number
          description: Fee rate in basis points (1% = 100)
          example: 0
        side:
          type: number
          description: 'Order side: 0 = BUY, 1 = SELL'
          enum:
            - 0
            - 1
          example: 0
        signature:
          type: string
          description: >-
            EIP-712 signature of order details as a 0x-prefixed hex string with
            full-byte (even) length. Optional when using delegated signing.
          example: >-
            0x6e3a3f2c2c2bb1ce3a14c4f5e4ad6f3c8b1ad9c44d4d5fa1c4cd5b6e74a4d4a36cc4ad9c44d4d5fa1c4cd5b6e74a4d4a36cc4ad9c44d4d5fa1c4cd5b6e74a4d41b
          pattern: ^0x([a-fA-F0-9]{2})*$
        signatureType:
          type: number
          description: Signature type (0-3). Optional when using delegated signing.
          enum:
            - 0
            - 1
            - 2
            - 3
          example: 2
      additionalProperties: false
      description: >-
        EIP-712 order fields. Signature and signatureType must be supplied
        together for client signing or both omitted for delegated server
        signing.
      oneOf:
        - required:
            - signature
            - signatureType
        - not:
            anyOf:
              - required:
                  - signature
              - required:
                  - signatureType
      required:
        - salt
        - maker
        - signer
        - tokenId
        - makerAmount
        - takerAmount
        - nonce
        - feeRateBps
        - side
    CancelReplaceCancelSuccess:
      type: object
      properties:
        status:
          type: string
          enum:
            - SUCCESS
        orderId:
          type: string
          format: uuid
        clientOrderId:
          type: string
      required:
        - status
        - orderId
    CancelReplaceCancelError:
      type: object
      properties:
        status:
          type: string
          enum:
            - FAILURE
            - UNKNOWN
        error:
          $ref: '#/components/schemas/CancelReplaceError'
      description: >-
        FAILURE covers a missing target or expected HTTP error below 500.
        UNKNOWN means the cancellation outcome could not be determined.
      required:
        - status
        - error
    CancelReplacePlacementSuccess:
      type: object
      properties:
        status:
          type: string
          enum:
            - SUCCESS
        data:
          $ref: '#/components/schemas/OrderResponseDto'
      description: >-
        The matching engine accepted the replacement. The canonical
        created-order, owner, maker-match, and execution schemas are reused;
        nested settlementStatus may still be FAILED with a free-form reason.
      required:
        - status
        - data
    CancelReplacePlacementError:
      type: object
      properties:
        status:
          type: string
          enum:
            - FAILURE
            - UNKNOWN
        error:
          $ref: '#/components/schemas/CancelReplaceError'
      description: >-
        FAILURE covers rejected and thrown placement errors, including balance
        or allowance rejection and an execution-time 425 after cancellation.
        UNKNOWN means placement reported an inconclusive result.
      required:
        - status
        - error
    CancelReplacePlacementNotAttempted:
      type: object
      properties:
        status:
          type: string
          enum:
            - NOT_ATTEMPTED
      required:
        - status
    CancelReplaceError:
      type: object
      properties:
        code:
          type: string
          description: >-
            ORDER_NOT_FOUND, a decimal HTTP status such as 400/404/409/425/500,
            or INTERNAL_ERROR.
          example: ORDER_NOT_FOUND
        message:
          type: string
          example: Order not found
      description: >-
        Operation-level error. Code is not a closed enum: ORDER_NOT_FOUND
        identifies a missing cancellation target, decimal HTTP status strings
        identify captured HTTP failures, and INTERNAL_ERROR identifies
        uncategorized errors.
      required:
        - code
        - message
    OrderResponseDto:
      type: object
      properties:
        order:
          description: Order details including slim market and owner
          allOf:
            - $ref: '#/components/schemas/CreatedOrderDto'
        makerMatches:
          description: Maker matches if order was matched immediately
          type: array
          items:
            $ref: '#/components/schemas/MakerMatch'
        execution:
          description: Execution and settlement summary
          allOf:
            - $ref: '#/components/schemas/OrderExecutionDto'
      required:
        - order
        - execution
    CreatedOrderDto:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Internal order ID
        salt:
          type: string
          description: Order salt as a decimal string
          example: '1778155025318314496'
        maker:
          type: string
          pattern: ^0x[a-fA-F0-9]{40}$
        signer:
          type: string
          pattern: ^0x[a-fA-F0-9]{40}$
        taker:
          type: string
          nullable: true
          pattern: ^0x[a-fA-F0-9]{40}$
        tokenId:
          type: string
        expiration:
          type: string
          format: date-time
          nullable: true
        signatureType:
          type: number
          enum:
            - 0
            - 1
            - 2
            - 3
        feeRateBps:
          type: integer
          nullable: true
        signature:
          type: string
          pattern: ^0x([a-fA-F0-9]{2})*$
        orderType:
          type: string
          enum:
            - GTC
            - FAK
            - FOK
        side:
          type: number
          enum:
            - 0
            - 1
          description: 0 = BUY, 1 = SELL
        marketId:
          type: string
        ownerId:
          type: integer
        createdAt:
          type: string
          format: date-time
        market:
          $ref: '#/components/schemas/MarketSlimDto'
        makerAmount:
          type: integer
          description: Raw 6-decimal amount
          example: 5000000
        takerAmount:
          type: integer
          description: Raw 6-decimal amount
          example: 10000000
        nonce:
          type: number
          enum:
            - 0
          description: Numeric zero
        price:
          type: number
          example: 0.75
        owner:
          $ref: '#/components/schemas/CreatedOrderOwner'
      required:
        - id
        - salt
        - maker
        - signer
        - tokenId
        - signatureType
        - signature
        - orderType
        - side
        - marketId
        - ownerId
        - createdAt
        - market
        - makerAmount
        - takerAmount
        - nonce
        - owner
    MakerMatch:
      type: object
      properties:
        id:
          type: string
          format: uuid
        matchedSize:
          type: string
          description: Matched contracts in raw 6-decimal units.
          example: '1000000'
        fillPrice:
          type: string
          description: Effective taker-perspective fill price.
          example: '0.55'
        fillCost:
          type: string
          description: Fill collateral cost in raw 6-decimal units.
          example: '550000'
        orderId:
          type: string
          format: uuid
        order:
          $ref: '#/components/schemas/MakerMatchOrder'
      required:
        - id
        - matchedSize
        - fillPrice
        - fillCost
        - orderId
        - order
    OrderExecutionDto:
      type: object
      properties:
        matched:
          type: boolean
          example: true
        settlementStatus:
          type: string
          example: MINED
          enum:
            - UNMATCHED
            - MATCHED
            - MINED
            - CONFIRMED
            - RETRYING
            - FAILED
            - DELAYED
            - CANCELED
        reason:
          type: string
          example: settlement transaction reverted
        eligibleAt:
          type: string
          example: '2026-06-08T10:15:30.000Z'
          format: date-time
          nullable: true
        tradeEventId:
          type: string
          example: 4aa706dd-6c57-4f3c-945a-99818dfd95f1
        txHash:
          type: string
          example: '0xabc123'
          nullable: true
        clientOrderId:
          type: string
          example: client-order-001
        stpMakerCancels:
          example:
            - 4aa706dd-6c57-4f3c-945a-99818dfd95f1
          type: array
          items:
            type: string
        feeRateBps:
          type: number
          example: 25
        effectiveFeeBps:
          type: number
          example: 26
        totalsRaw:
          $ref: '#/components/schemas/OrderExecutionTotalsRawDto'
      required:
        - matched
        - settlementStatus
        - feeRateBps
        - effectiveFeeBps
        - totalsRaw
    MarketSlimDto:
      type: object
      properties:
        id:
          type: integer
          example: 7348
        slug:
          type: string
          example: btc-up-or-down-1-hour
        title:
          type: string
          example: BTC Up or Down - Hourly
        status:
          type: string
          example: FUNDED
          enum:
            - CREATED
            - DRAFTED
            - FUNDED
            - LOCKED
            - RESOLVED
        yesPositionId:
          type: string
          example: 11514974713064423461...
          nullable: true
        noPositionId:
          type: string
          example: 14525308260861904048...
          nullable: true
        group:
          $ref: '#/components/schemas/MarketGroupSlimDto'
      required:
        - id
        - slug
        - title
        - status
        - yesPositionId
        - noPositionId
    CreatedOrderOwner:
      type: object
      properties:
        id:
          type: integer
        account:
          type: string
          pattern: ^0x[a-fA-F0-9]{40}$
        client:
          type: string
        tradeWalletOption:
          type: string
          nullable: true
          enum:
            - eoa
            - smartWallet
        smartWallet:
          type: string
          nullable: true
        username:
          type: string
        displayName:
          type: string
        pfpUrl:
          type: string
          nullable: true
        socialUrl:
          type: string
          nullable: true
        rankName:
          type: string
        points:
          type: number
        isTop100:
          type: boolean
        leaderboardPosition:
          type: integer
        referredUsersCount:
          type: integer
      required:
        - id
        - account
        - client
        - tradeWalletOption
        - smartWallet
        - username
        - displayName
        - pfpUrl
        - socialUrl
        - rankName
        - points
        - referredUsersCount
    MakerMatchOrder:
      type: object
      properties:
        id:
          type: string
          format: uuid
        maker:
          type: string
          pattern: ^0x[a-fA-F0-9]{40}$
        price:
          type: string
          nullable: true
          example: '0.55'
        side:
          type: number
          enum:
            - 0
            - 1
        tokenId:
          type: string
        owner:
          $ref: '#/components/schemas/MakerMatchOwner'
      required:
        - id
        - maker
        - price
        - side
        - tokenId
        - owner
    OrderExecutionTotalsRawDto:
      type: object
      properties:
        contractsGross:
          type: string
          example: '1000000'
        contractsFee:
          type: string
          example: '1000'
        contractsNet:
          type: string
          example: '999000'
        usdGross:
          type: string
          example: '500000'
        usdFee:
          type: string
          example: '500'
        usdNet:
          type: string
          example: '499500'
      required:
        - contractsGross
        - contractsFee
        - contractsNet
        - usdGross
        - usdFee
        - usdNet
    MarketGroupSlimDto:
      type: object
      properties:
        id:
          type: integer
          example: 42
        slug:
          type: string
          example: btc-price-markets
        title:
          type: string
          example: BTC Price Markets
      required:
        - id
        - slug
        - title
    MakerMatchOwner:
      type: object
      properties:
        id:
          type: integer
        account:
          type: string
          pattern: ^0x[a-fA-F0-9]{40}$
        client:
          type: string
        tradeWalletOption:
          type: string
          nullable: true
          enum:
            - eoa
            - smartWallet
        smartWallet:
          type: string
          nullable: true
        username:
          type: string
        displayName:
          type: string
        pfpUrl:
          type: string
          nullable: true
        socialUrl:
          type: string
          nullable: true
        points:
          type: number
          enum:
            - 0
        referredUsersCount:
          type: number
          enum:
            - 0
      required:
        - id
        - account
        - client
        - tradeWalletOption
        - smartWallet
        - username
        - displayName
        - pfpUrl
        - socialUrl
        - points
        - referredUsersCount
  securitySchemes:
    HmacAuth:
      type: apiKey
      in: header
      name: lmts-api-key
      description: >-
        Scoped API token with HMAC-SHA256 signing. Requires three headers:
        lmts-api-key (token ID), lmts-timestamp (ISO-8601), lmts-signature
        (Base64-encoded HMAC). See Authentication docs for details.

````