> ## Documentation Index
> Fetch the complete documentation index at: https://pmxt-sync-hosted-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Cancel Order

> Start a cancel on an existing open order. Returns the cancel payload for the wallet to sign — you then submit the signature to `POST /v0/orders/cancel`.

The SDK's `cancelOrder()` chains both steps. Call this endpoint directly only if you need to show the cancel to a user before signing.

<Info>
  **Available on:** Polymarket, Opinion, Limitless. Other venues raise `NotSupported` in hosted mode — for those, run a [local PMXT service](/guides/self-hosted).
</Info>

<Note>
  **Before your first call:** deposit USDC on Polygon at [pmxt.dev/dashboard/wallet](https://pmxt.dev/dashboard/wallet) (one-time setup). For the programmatic flow, see [escrow lifecycle](/guides/escrow-lifecycle).
</Note>

<Tip>
  Use any EVM private key. Your USDC sits in a non-custodial PreFundedEscrow on Polygon — for Polymarket, Opinion, and Limitless. PMXT cannot move funds without your EIP-712 signature.
</Tip>


## OpenAPI

````yaml /api-reference/openapi-hosted-trading.json post /v0/orders/cancel/build
openapi: 3.0.0
info:
  title: PMXT Hosted Router API
  description: Hosted-only endpoints for cross-venue search, matching, arbitrage, and SQL.
  version: 49fbcd4
servers:
  - url: https://trade.pmxt.dev
    description: Hosted trading (v0)
security:
  - bearerAuth: []
tags:
  - name: Trading (Hosted)
    description: >-
      Hosted trading endpoints. Build / submit / cancel orders via
      `trade.pmxt.dev/v0/*`. Hosted-mode is the default when `pmxt_api_key` is
      set.
  - name: Orders & Positions (Hosted)
    description: >-
      Hosted account reads. Open orders, fills, balances, and positions via
      `trade.pmxt.dev/v0/*`. Requires `pmxt_api_key` + `wallet_address`.
  - name: MatchedMarkets
    description: Cross-venue matched market and event clusters.
  - name: SQL
    description: Direct read-only SQL access to the catalog (Enterprise).
paths:
  /v0/orders/cancel/build:
    post:
      tags:
        - Trading
      summary: Cancel Order
      description: >-
        Start a cancel on an existing open order. Returns the cancel payload for
        the wallet to sign — you then submit the signature to `POST
        /v0/orders/cancel`.


        The SDK's `cancelOrder()` chains both steps. Call this endpoint directly
        only if you need to show the cancel to a user before signing.
      operationId: cancelOrderHosted
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CancelBuildHostedRequest'
      responses:
        '200':
          description: Cancel build response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CancelBuildHostedResponse'
        '401':
          description: Invalid or missing PMXT API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HostedErrorResponse'
        '404':
          description: Order not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HostedErrorResponse'
        '422':
          description: Invalid order ID.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HostedErrorResponse'
      x-codeSamples:
        - lang: python
          label: Polymarket
          source: >
            # Current hosted venues are funded once on Polygon — see
            /guides/escrow-lifecycle.

            # Hosted writes need: pmxt_api_key + wallet_address + private_key
            (signs EIP-712 locally).

            import pmxt


            client = pmxt.Polymarket(
                pmxt_api_key="YOUR_PMXT_API_KEY",
                wallet_address="0xYourWallet",    # EVM address — its Polygon USDC funds the escrow
                private_key="0x...",    # any EVM key controlling that address
            )

            cancelled = client.cancel_order("order_abc123")

            print(cancelled.id, cancelled.status)
        - lang: javascript
          label: Polymarket
          source: >
            // Current hosted venues are funded once on Polygon — see
            /guides/escrow-lifecycle.

            // Hosted writes need: pmxtApiKey + walletAddress + privateKey
            (signs EIP-712 locally).

            import { Polymarket } from "pmxtjs";


            const client = new Polymarket({
              pmxtApiKey: "YOUR_PMXT_API_KEY",
              walletAddress: "0xYourWallet",  // EVM address — its Polygon USDC funds the escrow
              privateKey: "0x...",  // any EVM key controlling that address
            });


            const cancelled = await client.cancelOrder("order_abc123");

            console.log(cancelled.id, cancelled.status);
        - lang: python
          label: Opinion
          source: >
            # Current hosted venues are funded once on Polygon — see
            /guides/escrow-lifecycle.

            # Hosted writes need: pmxt_api_key + wallet_address + private_key
            (signs EIP-712 locally).

            import pmxt


            client = pmxt.Opinion(
                pmxt_api_key="YOUR_PMXT_API_KEY",
                wallet_address="0xYourWallet",    # EVM address — its Polygon USDC funds the escrow
                private_key="0x...",    # any EVM key controlling that address
            )

            cancelled = client.cancel_order("order_abc123")

            print(cancelled.id, cancelled.status)
        - lang: javascript
          label: Opinion
          source: >
            // Current hosted venues are funded once on Polygon — see
            /guides/escrow-lifecycle.

            // Hosted writes need: pmxtApiKey + walletAddress + privateKey
            (signs EIP-712 locally).

            import { Opinion } from "pmxtjs";


            const client = new Opinion({
              pmxtApiKey: "YOUR_PMXT_API_KEY",
              walletAddress: "0xYourWallet",  // EVM address — its Polygon USDC funds the escrow
              privateKey: "0x...",  // any EVM key controlling that address
            });


            const cancelled = await client.cancelOrder("order_abc123");

            console.log(cancelled.id, cancelled.status);
components:
  schemas:
    CancelBuildHostedRequest:
      type: object
      required:
        - order_id
        - user_address
      properties:
        order_id:
          type: string
          description: Unified order id, as returned by `fetchOpenOrdersHosted`.
        user_address:
          type: string
          description: >-
            EVM wallet address that owns the resting order and will sign the
            cancel typed data.
    CancelBuildHostedResponse:
      type: object
      required:
        - cancel_id
        - typed_data
        - deadline
      properties:
        cancel_id:
          type: string
          description: >-
            Opaque server-side key for this cancel build. Pass it to `POST
            /v0/orders/cancel` with the EIP-712 signature(s) before `deadline`.
        typed_data:
          type: object
          description: >-
            EIP-712 typed-data payload to sign locally with the wallet key
            matching `user_address`. Return the signature when submitting the
            cancel.
        pull_typed_data:
          type: object
          nullable: true
          description: >-
            Optional secondary EIP-712 payload for venues that require a
            pull-authorization cancel (Polymarket neg-risk markets). Sign with
            the same wallet and return as `pull_signature`. `null` when not
            required.
        deadline:
          type: integer
          description: >-
            Unix epoch (s) after which the cancel build expires. Submit the
            signed cancel before this time or call `cancelOrderHosted` again.
    HostedErrorResponse:
      type: object
      description: >-
        Error envelope returned by `trade.pmxt.dev/v0/*` endpoints. Mirrors the
        `ErrorDetail` shape used inside `BaseResponse.error` from the sidecar
        spec.
      required:
        - error
      properties:
        error:
          type: object
          description: Structured error envelope. Always present on non-2xx responses.
          properties:
            message:
              type: string
              description: Human-readable explanation safe to surface to end users.
            code:
              type: string
              description: >-
                Stable hosted-mode error code. Use this (not `message`) for
                branching in client code.
              enum:
                - HOSTED_TRADING_ERROR
                - INSUFFICIENT_ESCROW_BALANCE
                - ORDER_SIZE_TOO_SMALL
                - INVALID_API_KEY
                - OUTCOME_NOT_FOUND
                - CATALOG_UNAVAILABLE
                - BUILT_ORDER_EXPIRED
                - INVALID_SIGNATURE
                - NO_LIQUIDITY
                - MISSING_WALLET_ADDRESS
                - ORDER_NOT_FOUND
                - INVALID_ORDER
            retryable:
              type: boolean
              description: >-
                `true` when the same request may succeed if retried (e.g.
                transient catalog outage); `false` when the caller must change
                inputs first.
            exchange:
              type: string
              nullable: true
              description: >-
                Source venue that produced the error (e.g. `polymarket`,
                `opinion`, `limitless`), when the failure originated upstream of
                PMXT. `null` for PMXT-side errors.
            detail:
              type: object
              additionalProperties: {}
              nullable: true
              description: >-
                Free-form structured diagnostics (e.g. required minimum size,
                escrow balance available). Shape varies per `code`.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Required when calling the hosted API directly (curl, requests, fetch).
        SDK users pass credentials via constructor params instead.

````