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

# Create Order

> Create an order.

<Info>
  **VWAP and TWAP**

  VWAP and TWAP orders must have a minimum notional of \$100/hr and also include these additional parameters: `limit_price`, `start_time` and `expiry_time`.
</Info>

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.createOrdersService(client);

    CreateOrderRequest request = new CreateOrderRequest.Builder()
        .portfolioId("PORTFOLIO_ID_HERE")
        .productId("ADA-USD")
        .side(OrderSide.BUY)
        .type(OrderType.MARKET)
        .baseQuantity("10.0")
        .clientOrderId(UUID.randomUUID().toString())
        .build());
    CreateOrderResponse orderResponse = ordersService.createOrder(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 CreateOrderRequest("PORTFOLIO_ID_HERE")
    {
        BaseQuantity = "5",
        LimitPrice = "0.32",
        Side = OrderSide.BUY,
        ProductId = "ADA-USD",
        Type = OrderType.LIMIT,
        ExpiryTime = new DateTimeOffset(DateTime.UtcNow.AddMinutes(5)).ToString("o"),
        ClientOrderId = Guid.NewGuid().ToString()
    };

    var createOrderResponse = orderService.CreateOrder(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.CreateOrderRequest{
        Order: &model.Order{
            PortfolioId:   "PORTFOLIO_ID_HERE",
            BaseQuantity:  "5",
            LimitPrice:    "0.32",
            Side:          "BUY",
            ProductId:     "ADA-USD",
            Type:          "LIMIT",
            ExpiryTime:    time.Now().UTC().Add(5 * time.Minute).Format(time.RFC3339),
            ClientOrderId: uuid.New().String(),
        },
    }

    response, err := ordersService.CreateOrder(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 = CreateOrderRequest(
        portfolio_id="PORTFOLIO_ID_HERE",
        base_quantity="5",
        limit_price="0.32",
        side="BUY",
        product_id="ADA-USD",
        type="LIMIT",
        expiry_time=(datetime.datetime.now() + datetime.timedelta(minutes=5)).isoformat() + "Z",
        client_order_id=str(uuid.uuid4()),
    )

    response = prime_client.create_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 create-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);
    const today = new Date();

    ordersService.createOrder({
        portfolioId: "PORTFOLIO_ID_HERE",
        baseQuantity: "5",
        limitPrice: "0.32",
        side: OrderSide.BUY,
        productId: "ADA-USD",
        type: OrderType.LIMIT,
        expiryTime: date.setDate(date.getDate() + 1),
        clientOrderId: uuidv4()
    }).then(async (response) => {
        console.log('Order: ', 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}/order
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}/order:
    post:
      tags:
        - Orders
      summary: Create Order
      description: Create an order.
      operationId: PrimeRESTAPI_CreateOrder
      parameters:
        - name: portfolio_id
          in: path
          description: The ID of the portfolio that owns the order
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              required:
                - client_order_id
                - product_id
                - side
                - type
              type: object
              properties:
                product_id:
                  title: >-
                    The ID of the product being traded for the order (e.g.
                    `BTC-USD`)
                  type: string
                side:
                  $ref: '#/components/schemas/coinbase.public_rest_api.OrderSide'
                client_order_id:
                  title: A client-generated order ID used for reference purposes
                  type: string
                type:
                  $ref: '#/components/schemas/coinbase.public_rest_api.OrderType'
                base_quantity:
                  title: >-
                    Order size in base asset units (either `base_quantity` or
                    `quote_value` is required)
                  type: string
                quote_value:
                  title: >-
                    Order size in quote asset units, i.e. the amount the user
                    wants to spend (when buying) or receive (when selling); the
                    quantity in base units will be determined based on the
                    market liquidity and indicated `quote_value` (either
                    `base_quantity` or `quote_value` is required)
                  type: string
                limit_price:
                  title: >-
                    The limit price (required for TWAP, VWAP, LIMIT, and
                    STOP_LIMIT orders)
                  type: string
                start_time:
                  title: The start time of the order in UTC (TWAP only)
                  type: string
                  format: date-time
                expiry_time:
                  title: >-
                    The expiry time of the order in UTC (TWAP, VWAP, LIMIT, and
                    STOP_LIMIT GTD only)
                  type: string
                  format: date-time
                time_in_force:
                  $ref: >-
                    #/components/schemas/coinbase.public_rest_api.TimeInForceType
                stp_id:
                  title: >-
                    An optional self trade prevention id (in the form of a
                    UUID). The value is only honored for certain clients who are
                    permitted to specify a custom self trade prevention id
                  type: string
                display_quote_size:
                  type: string
                  description: >-
                    Optionally specify a display size. This is the maximum order
                    size that will show up on venue order books. Specifying a
                    value here effectively makes a LIMIT order into an "iceberg"
                    style order. This property only applies to LIMIT orders and
                    will be ignored for other order types.
                display_base_size:
                  type: string
                is_raise_exact:
                  type: boolean
                historical_pov:
                  title: Historical percentage of volume
                  type: string
                stop_price:
                  title: >-
                    Specifies the stop price at which the order activates. The
                    order is activated if the last trade price on Coinbase
                    Exchange crosses the stop price specified on the order
                  type: string
                settl_currency:
                  title: The currency in which the settlement will be made
                  type: string
                post_only:
                  type: boolean
                  description: >-
                    Post-only flag - when true, the order will only be posted to
                    the order book and not immediately matched. Only applicable
                    to LIMIT orders with GTC or GTD time in force.
                peg_offset_type:
                  $ref: '#/components/schemas/coinbase.public_rest_api.PegOffsetType'
                offset:
                  title: >-
                    Offset value for PEG orders. 0 means peg to BBO. Only
                    non-negative values are allowed (PEG orders only)
                  type: string
                wig_level:
                  title: >-
                    WIG (Would if Good) level - the best price a pegged order
                    would be placed on venues, opposite to limit_price (PEG
                    orders only)
                  type: string
                  description: 'next: 23'
        required: true
      responses:
        '200':
          description: A successful response.
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/coinbase.public_rest_api.CreateOrderResponse
components:
  schemas:
    coinbase.public_rest_api.OrderSide:
      title: Order side
      type: string
      description: |-
        - UNKNOWN_ORDER_SIDE: nil value
         - BUY: Buy order
         - SELL: Sell order
      enum:
        - BUY
        - SELL
    coinbase.public_rest_api.OrderType:
      title: Strategy (execution algorithm)
      type: string
      description: |-
        - UNKNOWN_ORDER_TYPE: nil value
         - MARKET: A [market order](https://en.wikipedia.org/wiki/Order_(exchange)#Market_order)
         - LIMIT: A [limit order](https://en.wikipedia.org/wiki/Order_(exchange)#Limit_order)
         - TWAP: A [time-weighted average price order](https://en.wikipedia.org/wiki/Time-weighted_average_price)
         - BLOCK: A [block trade](https://en.wikipedia.org/wiki/Block_trade)
         - VWAP: A [volume-weighted average price order](https://en.wikipedia.org/wiki/Volume-weighted_average_price)
         - STOP_LIMIT: A [conditional order combined of stop order and limit order](https://en.wikipedia.org/wiki/Order_(exchange)#Stop-limit_order)
         - RFQ: A [request for quote](https://en.wikipedia.org/wiki/Request_for_quote)
         - PEG: A pegged order that dynamically adjust based on market conditions while maintaining execution discretion and avoiding adverse selection
      enum:
        - MARKET
        - LIMIT
        - TWAP
        - BLOCK
        - VWAP
        - STOP_LIMIT
        - RFQ
        - PEG
    coinbase.public_rest_api.TimeInForceType:
      title: Indicates the order time validity
      type: string
      description: |-
        - UNKNOWN_TIME_IN_FORCE: nil value
         - GOOD_UNTIL_DATE_TIME: Expires at a certain date/time
         - GOOD_UNTIL_CANCELLED: Order stays on the books until cancelled
         - IMMEDIATE_OR_CANCEL: Order is executed immediately at submission or is cancelled
         - FILL_OR_KILL: Order is executed immediately and fully at submission or is cancelled
      enum:
        - GOOD_UNTIL_DATE_TIME
        - GOOD_UNTIL_CANCELLED
        - IMMEDIATE_OR_CANCEL
        - FILL_OR_KILL
    coinbase.public_rest_api.PegOffsetType:
      title: Peg offset type for PEG orders
      type: string
      description: |-
        - UNKNOWN_PEG_OFFSET_TYPE: nil value
         - PEG_OFFSET_TYPE_PRICE: Offset specified in price units
         - PEG_OFFSET_TYPE_BPS: Offset specified in basis points (BPS)
         - PEG_OFFSET_TYPE_DEPTH: Offset specified in depth
      enum:
        - PEG_OFFSET_TYPE_PRICE
        - PEG_OFFSET_TYPE_BPS
        - PEG_OFFSET_TYPE_DEPTH
    coinbase.public_rest_api.CreateOrderResponse:
      type: object
      properties:
        order_id:
          type: string
          description: The order ID generated by Coinbase
          example: ba0eb21c-672b-44de-8342-d6363cef87f0

````