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

# Close position

> Automatic full or partial close of an authorized position.

Send `login` and optionally `volume` and `comment`. Omit volume for a full close;
`5000` requests 0.5 lots. The API resolves symbol, direction, price and precision.
Keep one `Idempotency-Key` per intent and confirm execution.
See [the complete guide](/trading/close).


## OpenAPI

````yaml openapi.json POST /api/v1/positions/{position}/close
openapi: 3.1.0
info:
  title: MT5 API — Partner Portal
  description: >-
    Secure endpoints for account ownership verification, market data, and
    trading on previously verified accounts.
  version: 0.1.0
servers:
  - url: https://api-trading.vexprofx.com
    description: API Trading · Partners
security: []
paths:
  /api/v1/positions/{position}/close:
    post:
      tags:
        - Trading
      summary: Close an open position
      description: >-
        Provide the verified account login and optionally a volume. The API
        resolves the position, opposite side, price, precision and FOK/IOC. Omit
        volume to request the full current volume. IOC may leave a residual
        position; inspect the result. No automatic resubmission.
      operationId: close_position_api_v1_positions__position__close_post
      parameters:
        - name: position
          in: path
          required: true
          schema:
            type: integer
            title: Position
        - name: Idempotency-Key
          in: header
          required: true
          schema:
            type: string
            minLength: 16
            maxLength: 128
            pattern: ^[A-Za-z0-9._:-]{16,128}$
            example: 550e8400-e29b-41d4-a716-446655440000
          description: >-
            Persisted key for this intent. Reuse the same key and body when
            retrying; use a new key for another opening or closing order.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ClosePositionRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
                title: Response Close Position Api V1 Positions  Position  Close Post
        '400':
          description: Missing or invalid Idempotency-Key.
        '409':
          description: Key reused with different data or request still pending.
        '422':
          description: Invalid request or incompatible closing parameters.
          content:
            application/json:
              schema:
                type: object
                required:
                  - detail
                properties:
                  detail:
                    type: string
              example:
                detail: Invalid request
      security:
        - HTTPBearer: []
components:
  schemas:
    ClosePositionRequest:
      properties:
        login:
          type: integer
          exclusiveMinimum: 0
          title: Login
          description: Verified owner account login.
          example: 123456
        volume:
          anyOf:
            - type: integer
              exclusiveMinimum: 0
            - type: 'null'
          title: Volume
          description: >-
            Optional MT5 volume units (10000 = 1 lot). Omit for the full current
            position volume.
          example: 100
        comment:
          type: string
          maxLength: 31
          title: Comment
          default: REST API close
      additionalProperties: false
      type: object
      required:
        - login
      title: ClosePositionRequest
      examples:
        - login: 104205
        - comment: Partial close
          login: 104205
          volume: 5000
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer
      description: >-
        Send the provider-issued token in the Authorization header using Bearer
        authentication.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.