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

# Creates a market order to close a position or partially close it by specifying the number of units to deduct.

> This endpoint allows traders to close an entire position or a portion of it at the current market rate. If `UnitsToDeduct` is provided, only the specified portion will be closed. If `UnitsToDeduct` is omitted or set to null, the full position will be closed.



## OpenAPI

````yaml /api-reference/openapi.json post /api/v1/trading/execution/demo/market-close-orders/positions/{positionId}
openapi: 3.0.1
info:
  title: eToro Api
  version: v1.206.0
  description: >-
    eToro’s public API provides access to real-time financial data, trading
    insights, and account management features, allowing developers to integrate
    eToro’s services into their applications. With access to market prices,
    historical data, and social trading information, the API empowers users to
    enhance their trading strategies. Designed for security and scalability, the
    eToro API ensures smooth and reliable integration for a variety of financial
    applications.


    For more details on integrating with eToro's public WebSocket service,
    please refer to the dedicated [WebSocket
    documentation](./websocket/websocket-doc.html).
servers:
  - url: https://public-api.etoro.com
    description: eToro Public API
security: []
tags:
  - name: Agent Portfolios
  - name: Watchlists
  - name: Feeds
  - name: Asset Explorer
  - name: Market Data
  - name: Identity
  - name: Notifications
  - name: PI Data
  - name: Comments
  - name: Trading Demo
  - name: Trading Real
  - name: Users Info
  - name: Deprecated
paths:
  /api/v1/trading/execution/demo/market-close-orders/positions/{positionId}:
    post:
      tags:
        - Trading Demo
      summary: >-
        Creates a market order to close a position or partially close it by
        specifying the number of units to deduct.
      description: >-
        This endpoint allows traders to close an entire position or a portion of
        it at the current market rate. If `UnitsToDeduct` is provided, only the
        specified portion will be closed. If `UnitsToDeduct` is omitted or set
        to null, the full position will be closed.
      operationId: closePositionByMarketRateDemo
      parameters:
        - name: x-request-id
          in: header
          required: true
          schema:
            type: string
            format: uuid
            example: a2ec60fe-3a92-4d7d-8a2c-da7f266c118a
          description: A unique request identifier.
        - name: x-api-key
          in: header
          required: true
          schema:
            type: string
            format: password
            example: lhgfaslk21490FAScVPkdsb53F9dNkfHG4faZSG5vfjndfcfgdssdgsdHF4663
          description: API key for authentication.
        - name: x-user-key
          in: header
          required: true
          schema:
            type: string
            format: password
            example: >-
              eyJlYW4iOiJVbnJlZ2lzdGVyZWRBcHBsaWNhdGlvbiIsImVrIjoiOE5sZ2cwcW5EUVdROUFNWGpXT2lmOWktZnpidG5KcUlqWGJ3WHJZZkpZcldrbG90ZEhvLVBjSWhQaU8xU1ZtMW84aU1WZGZqN2xWNzFjLXFxLmcybXE1dnh4Q1hUT25xaWRUaTFlcEhmVk1fIn0_
          description: User-specific authentication key.
        - name: positionId
          in: path
          description: The unique identifier of the position to close.
          required: true
          schema:
            type: integer
            format: int64
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                InstrumentID:
                  type: integer
                  format: int32
                  description: >-
                    The ID of the financial instrument associated with the
                    position.
                UnitsToDeduct:
                  type: number
                  format: double
                  nullable: true
                  description: >-
                    The number of units to close. If omitted or null, the entire
                    position will be closed.
              required:
                - InstrumentID
      responses:
        '200':
          description: Successfully closed a position or a part of it.
          content:
            application/json:
              schema:
                type: object
                properties:
                  orderForClose:
                    type: object
                    properties:
                      positionID:
                        type: integer
                        description: The ID of the closed position.
                      instrumentID:
                        type: integer
                        description: The ID of the instrument traded.
                      unitsToDeduct:
                        type: number
                        format: double
                        description: The number of units closed in this order.
                      orderID:
                        type: integer
                        description: The unique identifier of the closing order.
                      orderType:
                        type: integer
                        description: The type of order executed.
                      statusID:
                        type: integer
                        description: The status of the closing order.
                      CID:
                        type: integer
                        description: Customer Account ID associated with the order.
                      openDateTime:
                        type: string
                        format: date-time
                        description: The timestamp when the order was placed.
                      lastUpdate:
                        type: string
                        format: date-time
                        description: The timestamp of the last update to this order.
                  token:
                    type: string
                    format: uuid
                    description: A unique confirmation token for the closing order.
              example:
                orderForClose:
                  positionID: 2150941015
                  instrumentID: 1111
                  unitsToDeduct: 2
                  orderID: 13904638
                  orderType: 19
                  statusID: 1
                  CID: 7765437
                  openDateTime: '2025-04-02T16:07:54.0880338Z'
                  lastUpdate: '2025-04-02T16:07:54.0880338Z'
                token: 5fe065bc-f6f9-4897-a2ce-c4fccef73ff8

````