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

# Get Order Preview

> Retrieve an order preview.

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);

    GetOrderPreviewRequest request = new GetOrderPreviewRequest.Builder()
        .portfolioId("PORTFOLIO_ID_HERE")
        .productId("ADA-USD")
        .side(OrderSide.BUY)
        .type(OrderType.MARKET)
        .baseQuantity("10.0")
        .build();

    GetOrderPreviewResponse orderResponse = ordersService.getOrderPreview(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 GetOrderPreviewRequest("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"),
    };

    var getOrderPreviewResponse = orderService.GetOrderPreview(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.GetOrderPreviewRequest{
        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),
        },
    }

    response, err := ordersService.GetOrderPreviewRequest(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 = GetOrderPreviewRequest(
        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",
    )

    response = prime_client.get_order_preview(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-preview --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.createOrderPreview({
        portfolioId: "PORTFOLIO_ID_HERE",
        baseQuantity: "5",
        limitPrice: "0.32",
        side: OrderSide.BUY,
        productId: "ADA-USD",
        type: OrderType.LIMIT,
        expiryTime: date.setDate(date.getDate() + 1),
    }).then(async (response) => {
        console.log('Order Preview: ', 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_preview
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_preview:
    post:
      tags:
        - Orders
      summary: Get Order Preview
      description: Retrieve an order preview.
      operationId: PrimeRESTAPI_OrderPreview
      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:
                - 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'
                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, VWAP 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
                is_raise_exact:
                  title: Raise Exact order flag
                  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
                postOnly:
                  type: boolean
                  description: Specifies whether the order is treated as a post only order.
                display_quote_size:
                  type: string
                  description: >-
                    The maximum order size that will show up on venue order
                    books (in quote currency).
                  example: '100.50'
                display_base_size:
                  type: string
                  description: >-
                    The maximum order size that will show up on venue order
                    books (in base currency).
                  example: '10.5'
                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: 21'
        required: true
      responses:
        '200':
          description: A successful response.
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/coinbase.public_rest_api.PostOrderPreviewResponse
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.PostOrderPreviewResponse:
      type: object
      properties:
        portfolio_id:
          type: string
          description: The ID of the portfolio that owns the order
          example: 3e1fe27e-26fe-46d8-b118-c752a2ae6b47
        product_id:
          type: string
          description: The ID of the product being traded by the order
          example: BTC-USD
        side:
          $ref: '#/components/schemas/coinbase.public_rest_api.OrderSide'
        type:
          $ref: '#/components/schemas/coinbase.public_rest_api.OrderType'
        base_quantity:
          type: string
          description: >-
            Order size in base asset units (either `base_quantity` or
            `quote_value` is required)
          example: '50'
        quote_value:
          type: string
          description: >-
            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
          example: '100'
        limit_price:
          type: string
          description: >-
            The limit price (required for TWAP, VWAP, LIMIT, and STOP_LIMIT
            orders)
          example: '50.12'
        start_time:
          type: string
          description: The start time of the order in UTC (only applies to TWAP orders.)
          format: date-time
          example: '2021-05-31T09:59:59.000Z'
        expiry_time:
          type: string
          description: >-
            The expiry time of the order in UTC (TWAP, VWAP, LIMIT and
            STOP_LIMIT GTD only). Required for TWAP and VWAP orders if
            historical_pov is unspecified
          format: date-time
          example: '2021-05-31T10:59:59.000Z'
        time_in_force:
          $ref: '#/components/schemas/coinbase.public_rest_api.TimeInForceType'
        commission:
          type: string
          description: >-
            Indicate the total commission paid on this order in quote currency -
            only applicable if the order has any fills
          example: '4.99'
        slippage:
          type: string
          description: How much slippage is expected
          example: '0.05'
        best_bid:
          type: string
          description: Current best bid for order book
          example: '10'
        best_ask:
          type: string
          description: Current best ask for order book
          example: '10'
        average_filled_price:
          type: string
          description: >-
            Indicate expected average filled price based on the current order
            book
          example: '50.19'
        order_total:
          type: string
          description: Order quantity + fees
          example: '123'
        historical_pov:
          type: string
          description: >-
            The estimated participation rate for a TWAP/VWAP order. This field
            can be specified instead of expiry time, and will be used to compute
            the expiry time of the order based on historical participation rate.
          example: '0.5'
        is_raise_exact:
          type: boolean
          description: Raise Exact order flag
          example: false
        stop_price:
          type: string
          description: Stop price for the order
          example: '50000.00'
        display_size:
          type: string
          description: The maximum order size that will show up on venue order books.
          example: '10.5'
        display_quote_size:
          type: string
          description: >-
            The maximum order size that will show up on venue order books (in
            quote currency).
          example: '100.50'
        display_base_size:
          type: string
          description: >-
            The maximum order size that will show up on venue order books (in
            base currency).
          example: '10.5'

````