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

# Close part or all of a position

> Resolves the current position side, leverage, and margin mode on the server and submits a reduce-only market, limit, or conditional order. Omit size to close the complete current position.



## OpenAPI

````yaml /openapi.yaml post /v1/positions/{position_id}/close
openapi: 3.1.0
info:
  title: Funding Perpetuals API
  version: 1.0.0
  description: >-
    Programmatic access to Funding Perpetuals paper-trading challenge accounts.
    API trades use the same real order books and simulated execution engine as
    the web trading interface.
  contact:
    url: https://fundingperpetuals.com/support
servers:
  - url: https://developers.fundingperpetuals.com
    description: Production
security:
  - bearerAuth: []
tags:
  - name: General
  - name: Accounts
  - name: Markets
  - name: Positions
  - name: Orders
  - name: Fills
  - name: Strategy Orders
paths:
  /v1/positions/{position_id}/close:
    post:
      tags:
        - Positions
      summary: Close part or all of a position
      description: >-
        Resolves the current position side, leverage, and margin mode on the
        server and submits a reduce-only market, limit, or conditional order.
        Omit size to close the complete current position.
      operationId: closePosition
      parameters:
        - $ref: '#/components/parameters/PositionId'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ClosePositionRequest'
      responses:
        '200':
          description: Idempotent replay.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrderEnvelope'
        '201':
          description: Close order accepted.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrderEnvelope'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '422':
          $ref: '#/components/responses/TradeRejected'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  parameters:
    PositionId:
      name: position_id
      in: path
      required: true
      schema:
        type: string
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: true
      description: >-
        Unique printable key for this intended order. Reuse it only for an
        identical retry.
      schema:
        type: string
        minLength: 1
        maxLength: 128
  schemas:
    ClosePositionRequest:
      type: object
      additionalProperties: false
      properties:
        type:
          type: string
          enum:
            - market
            - limit
            - conditional
          default: market
        size:
          type: number
          exclusiveMinimum: 0
          description: Omit to close the complete current position.
        expected_price:
          type: number
          exclusiveMinimum: 0
        slippage_tolerance_bps:
          type: number
          exclusiveMinimum: 0
        limit_price:
          type: number
          exclusiveMinimum: 0
        trigger_price:
          type: number
          exclusiveMinimum: 0
        trigger_market_id:
          type: string
        trigger_direction:
          type: string
          enum:
            - above
            - below
        marketable_limit_acknowledged:
          type: boolean
    OrderEnvelope:
      type: object
      required:
        - data
      properties:
        data:
          $ref: '#/components/schemas/Order'
        queued:
          type: boolean
    Order:
      type: object
      required:
        - id
        - account_id
        - market_id
        - provider
        - symbol
        - coin
        - type
        - mode
        - side
        - size
        - expected_price
        - leverage
        - margin_mode
        - reduce_only
        - status
        - requested_at
      properties:
        id:
          type: string
        account_id:
          type: string
        market_id:
          type: string
        provider:
          type: string
        symbol:
          type: string
        coin:
          type: string
        type:
          type: string
          enum:
            - market
            - limit
            - stop_market
            - stop_limit
            - take_market
            - take_limit
            - take_profit
            - liquidation
            - close_out
        mode:
          type: string
          enum:
            - market
            - limit
            - chase
            - stop_market
            - stop_limit
            - take_market
            - take_limit
            - take_profit
            - conditional
            - liquidation
            - close_out
        side:
          type: string
          enum:
            - buy
            - sell
        size:
          type: number
        initial_size:
          type: number
        filled_size:
          type: number
        expected_price:
          type: number
        fill_price:
          type: number
        trigger_price:
          type: number
        limit_price:
          type: number
        notional:
          type: number
        fee:
          type: number
        realized_pnl:
          type: number
        leverage:
          type: number
        margin_mode:
          type: string
          enum:
            - cross
            - isolated
        reduce_only:
          type: boolean
        time_in_force:
          type: string
          enum:
            - gtc
            - ioc
            - fok
            - gtd
        gtd_expires_at:
          type: number
        attached_take_profit_price:
          type: number
        attached_stop_loss_price:
          type: number
        chase_offset:
          type: number
        chase_cap_price:
          type: number
        trigger_market_id:
          type: string
        trigger_direction:
          type: string
          enum:
            - above
            - below
        target_position_id:
          type: string
        liquidity_role:
          type: string
          enum:
            - maker
            - taker
        partial_of_order_id:
          type: string
        partial_fill_root_order_id:
          type: string
        twap_order_id:
          type: string
        scaled_order_id:
          type: string
        status:
          type: string
          enum:
            - pending
            - filled
            - rejected
            - expired
            - resting
            - canceled
        reject_reason:
          type: string
        reject_rule_id:
          type: string
        requested_at:
          type: number
        settled_at:
          type: number
        canceled_at:
          type: number
    ErrorEnvelope:
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/Error'
    TradeRejectionEnvelope:
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/TradeRejection'
    Error:
      type: object
      required:
        - code
        - message
        - request_id
      properties:
        code:
          type: string
        message:
          type: string
        request_id:
          type: string
          format: uuid
    TradeRejection:
      allOf:
        - $ref: '#/components/schemas/Error'
        - type: object
          properties:
            order_id:
              type: string
            rule_id:
              type: string
            details:
              type: object
              additionalProperties: true
  responses:
    BadRequest:
      description: Invalid request.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    Unauthorized:
      description: Missing, invalid, or revoked API key.
      headers:
        WWW-Authenticate:
          schema:
            type: string
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    NotFound:
      description: Resource not found or not owned by the authenticated user.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    Conflict:
      description: The request conflicts with current state or an idempotency record.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    TradeRejected:
      description: The trading engine rejected the requested operation.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/TradeRejectionEnvelope'
    RateLimited:
      description: A per-key, per-IP, or deployment request budget is exhausted.
      headers:
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
  headers:
    RetryAfter:
      description: Seconds to wait before retrying.
      schema:
        type: integer
        minimum: 1
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Funding Perpetuals API key
      description: API key beginning with `fp_live_`.

````