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

# Cancel Order

> Cancel an order. (Filled orders cannot be canceled.)

Use the Prime SDK or CLI to test this endpoint by following the [quickstart](/prime/introduction/quickstart) guide and running with the following examples

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    OrdersService ordersService = PrimeServiceFactory.cancelOrdersService(client);

    CancelOrderRequest request = new CancelOrderRequest.Builder()
        .portfolioId("PORTFOLIO_ID_HERE")
        .orderId("ORDER_ID_HERE")
        .build());

    CancelOrderResponse orderResponse = ordersService.cancelOrder(request);
    ```

    For more information, please visit the [Prime Java SDK](https://github.com/coinbase-samples/prime-sdk-java).
  </Tab>

  <Tab title=".NET">
    ```csharp wrap theme={null}
    var ordersService = new OrdersService(client);

    var request = new CancelOrderRequest("PORTFOLIO_ID_HERE", "ORDER_ID_HERE");

    var cancelOrderResponse = orderService.CancelOrder(request);
    ```

    For more information, please visit the [Prime .NET SDK](https://github.com/coinbase-samples/prime-sdk-dotnet).
  </Tab>

  <Tab title="Go">
    ```go wrap theme={null}
    ordersService := orders.NewOrdersService(client)

    request := &orders.CancelOrderRequest{
        PortfolioId: "PORTFOLIO_ID_HERE",
        OrderId: "ORDER_ID_HERE",
    }

    response, err := ordersService.CancelOrder(context.Background(), request)
    ```

    For more information, please visit the [Prime Go SDK](https://github.com/coinbase-samples/prime-sdk-go).
  </Tab>

  <Tab title="Python">
    ```python wrap theme={null}
    prime_client = PrimeClient(credentials)

    request = CancelOrderRequest(
        portfolio_id="PORTFOLIO_ID_HERE",
        order_id="ORDER_ID_HERE",
    )

    response = prime_client.cancel_order(request)
    ```

    For more information, please visit the [Prime Python SDK](https://github.com/coinbase-samples/prime-sdk-py).
  </Tab>

  <Tab title="CLI">
    ```bash wrap theme={null}
    primectl cancel-order --help
    ```

    For more information, please visit the [Prime CLI](https://github.com/coinbase-samples/prime-cli).
  </Tab>

  <Tab title="TS/JS">
    ```typescript wrap theme={null}
    const ordersService = new OrdersService(client);

    orderService.cancelOrder({
        portfolioId: 'PORTFOLIO_ID_HERE',
        orderId: 'ORDER_ID_HERE',
    }).then(async (response) => {
        console.log('Order canceled: ', response);
    })
    ```

    For more information, please visit the [Prime TS SDK](https://github.com/coinbase-samples/prime-sdk-ts).
  </Tab>
</Tabs>


## OpenAPI

````yaml POST /v1/portfolios/{portfolio_id}/orders/{order_id}/cancel
openapi: 3.0.1
info:
  title: REST API
  description: >-
    The Coinbase Prime REST API provides programmatic access to trading,
    custody, staking, market data, and account management functionality.
  version: '0.1'
servers:
  - url: https://api.prime.coinbase.com/
security: []
tags:
  - name: PrimeRESTAPI
paths:
  /v1/portfolios/{portfolio_id}/orders/{order_id}/cancel:
    post:
      tags:
        - Orders
      summary: Cancel Order
      description: Cancel an order. (Filled orders cannot be canceled.)
      operationId: PrimeRESTAPI_CancelOrder
      parameters:
        - name: portfolio_id
          in: path
          description: The ID of the portfolio under which the order was placed
          required: true
          schema:
            type: string
        - name: order_id
          in: path
          description: The order ID generated by Coinbase upon order submission
          required: true
          schema:
            type: string
      responses:
        '200':
          description: A successful response.
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/coinbase.public_rest_api.CancelOrderResponse
components:
  schemas:
    coinbase.public_rest_api.CancelOrderResponse:
      type: object
      properties:
        id:
          type: string
          description: The unique UUID for the order
          example: 82c879c1-84e1-44ed-a8c2-1ac239cf09ad

````