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

# Close (or partially close) a perp position

> Build unsigned transaction(s) to close a position. Set `entire_position=true`
for a full close, otherwise pass `size_usd_delta_e6` for a partial close.

Idempotent on `client_order_id` (60s window).




## OpenAPI

````yaml openapi-spec/trading.yaml post /perp/sol/close
openapi: 3.0.3
info:
  title: Raze Trading API
  description: >
    Trading endpoints for Solana token swaps — quote, buy, sell, atomic

    round-trips and raw instructions. Perpetuals (Jupiter Perps + Phoenix) live

    here too.


    Quotes can also be **streamed**: `/swap/sol/quote/stream` is a WebSocket
    that

    pushes a fresh quote whenever the pools under your route move. It is not

    describable in OpenAPI — see

    [Streaming quotes](/api-reference/router/quote-stream).


    Write utilities (`/utils/sol/*` — launch, transfer, burn, consolidate, fees)

    moved to the History API on `https://api.raze.bot` (see `history.yaml`).


    Runs on port 8082.


    **Auth methods**: `Authorization: Bearer sk_...` header, `X-API-Key: sk_...`
    header, or `?apiKey=sk_...` query param.
  version: 2.1.0
servers:
  - url: https://router.raze.bot
    description: >-
      Raze global trading router — GeoDNS routes to the nearest region
      automatically
security: []
paths:
  /perp/sol/close:
    post:
      summary: Close (or partially close) a perp position
      description: >
        Build unsigned transaction(s) to close a position. Set
        `entire_position=true`

        for a full close, otherwise pass `size_usd_delta_e6` for a partial
        close.


        Idempotent on `client_order_id` (60s window).
      operationId: perpClose
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PerpCloseRequest'
            examples:
              fullClose:
                summary: Full close
                value:
                  wallet_addresses:
                    - 62ThHC1rs2GUfa8J4Qjcj5GD2MSL2d65pcJtenNieDnm
                  market_id: jup:SOL-PERP
                  position_pubkey: PoSLk3hQrTtUKn1ePNKczqJsZbftrxCzpEuhKdzS5sM
                  side: long
                  entire_position: true
                  slippage_bps: 50
                  client_order_id: ui-close-20260506-x1
              partial:
                summary: Partial close (50 USDC notional)
                value:
                  wallet_addresses:
                    - 62ThHC1rs2GUfa8J4Qjcj5GD2MSL2d65pcJtenNieDnm
                  market_id: jup:SOL-PERP
                  position_pubkey: PoSLk3hQrTtUKn1ePNKczqJsZbftrxCzpEuhKdzS5sM
                  side: long
                  size_usd_delta_e6: 50000000
                  slippage_bps: 50
                  client_order_id: ui-close-20260506-x2
      responses:
        '200':
          description: Transactions built
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PerpTxResponse'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Builder error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - ApiKeyAuth: []
        - BearerAuth: []
components:
  schemas:
    PerpCloseRequest:
      type: object
      required:
        - wallet_addresses
        - market_id
        - position_pubkey
        - side
        - slippage_bps
        - client_order_id
      properties:
        wallet_addresses:
          type: array
          items:
            type: string
          minItems: 1
        market_id:
          type: string
        position_pubkey:
          type: string
          description: Position PDA being closed.
        side:
          type: string
          enum:
            - long
            - short
          description: >-
            Side of the open position. Required so the builder picks the correct
            collateral custody account; without it a short close is rejected
            on-chain.
        entire_position:
          type: boolean
          default: false
          description: True = full close. When true, `size_usd_delta_e6` is ignored.
        size_usd_delta_e6:
          type: integer
          format: int64
          description: >-
            USD notional to close in USDC micros. Required when
            `entire_position=false` on a Jupiter market.
        close_pct_bps:
          type: integer
          nullable: true
          description: |
            **Phoenix only.** Percent of the position to close, in basis points
            (10000 = full) — Phoenix closes are base-unit/percent oriented, not
            USD-notional like Jupiter. Omitted, `entire_position` maps to 10000;
            a PARTIAL Phoenix close without this field is rejected. Ignored on
            Jupiter markets, which use `size_usd_delta_e6`.
        slippage_bps:
          type: integer
        client_order_id:
          type: string
    PerpTxResponse:
      type: object
      properties:
        success:
          type: boolean
        data:
          type: array
          items:
            $ref: '#/components/schemas/PerpTx'
        error:
          type: string
    ErrorResponse:
      type: object
      properties:
        success:
          type: boolean
          example: false
        error:
          type: string
        details:
          type: string
      required:
        - success
        - error
    PerpTx:
      type: object
      description: One unsigned transaction per wallet in the request.
      properties:
        wallet:
          type: string
        tx_b64:
          type: string
          description: Base64-encoded unsigned versioned transaction.
        status:
          type: string
          description: >-
            Builder-side hint (e.g. `created`, `funded_swap`,
            `phoenix-deposit`).
        position_request:
          type: string
          description: |
            `position_request` PDA this transaction creates or targets (Jupiter
            builds only). Lets a client cancel a stuck request without a History
            API round-trip. The PDA counter is derived deterministically from
            `client_order_id`, so the same request rebuilt on another edge lands
            on the same PDA — exactly-once on-chain.
        counter:
          type: integer
          format: int64
          description: PDA counter used to derive `position_request` (create paths only).
        position:
          type: string
          description: Position PDA the request acts on.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
    BearerAuth:
      type: http
      scheme: bearer

````