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

# Đóng vị thế

> Gửi yêu cầu đóng vị thế đang mở của phái sinh theo `positionId`. Đóng vị thế là lệnh đặt ngược chiều với vị thế đang mở, loại lệnh LO, giá đặt là giá trần/sàn của mã phái sinh tương ứng, khối lượng đặt bằng khối lượng mở của vị thế.



## OpenAPI

````yaml https://cdn.entrade.com.vn/dnse-openapi/doc/dnse-openapi-2026-05-07.yaml post /accounts/positions/{positionId}/close
openapi: 3.0.0
info:
  title: DNSE-OpenAPI-V2
  version: 1.0.0
  description: DNSE OpenAPI spec and tests
servers:
  - url: https://openapi-uat.dnse.com.vn
security: []
paths:
  /accounts/positions/{positionId}/close:
    parameters:
      - name: positionId
        in: path
        required: true
        description: Id vị thế
        deprecated: false
        schema:
          type: string
        example: '177410795472387'
    post:
      tags:
        - trading
      summary: Đóng vị thế
      description: >-
        Gửi yêu cầu đóng vị thế đang mở của phái sinh theo `positionId`. Đóng vị
        thế là lệnh đặt ngược chiều với vị thế đang mở, loại lệnh LO, giá đặt là
        giá trần/sàn của mã phái sinh tương ứng, khối lượng đặt bằng khối lượng
        mở của vị thế.
      parameters:
        - name: marketType
          in: query
          required: true
          description: |-
            Loại thị trường 
            - STOCK: Danh sách Deal cơ sở
            - DERIVATIVE: Danh sách Deal phái sinh
            Hiện tại chỉ hỗ trợ phái sinh
          deprecated: false
          schema:
            type: string
          example: DERIVATIVE
        - name: X-API-Key
          in: header
          required: true
          description: API Key được cấp khi đăng ký dịch vụ
          deprecated: false
          schema:
            type: string
          example: '{{apiKey}}'
        - name: X-Signature
          in: header
          required: true
          description: Chữ ký xác thực yêu cầu
          deprecated: false
          schema:
            type: string
          example: '{{signature}}'
        - name: X-Aux-Date
          in: header
          required: true
          description: Thời gian thực hiện yêu cầu
          deprecated: false
          schema:
            type: string
          example: '{{date}}'
        - name: trading-token
          in: header
          required: true
          description: Token đặt lệnh
          deprecated: false
          schema:
            type: string
          example: '{{tradingToken}}'
        - name: version
          in: header
          description: 'Phiên bản API '
          schema:
            type: string
            format: date
          example: '2026-05-07'
      responses:
        '200':
          description: OK
          headers:
            Access-Control-Allow-Credentials:
              schema:
                type: boolean
              example: true
            Content-Encoding:
              schema:
                type: string
              example: br
            Content-Length:
              schema:
                type: integer
              example: 180
            Date:
              schema:
                type: string
              example: Tue, 24 Mar 2026 04:20:55 GMT
            Vary:
              schema:
                type: string
              example: Origin
            X-Ratelimit-Limit:
              schema:
                type: integer
              example: -1
            X-Ratelimit-Remaining:
              schema:
                type: integer
              example: 0
            X-Ratelimit-Reset:
              schema:
                type: integer
              example: 0
            X-Tyk-Api-Expires:
              schema:
                type: string
              example: Thu, 02 Jan 3000 15:04:00 UTC
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: integer
                    example: 1636
                    description: Id lệnh giao dịch
                    format: int32
                  side:
                    type: string
                    example: NS
                    description: |-
                      Chiều đặt lệnh
                      - NB: Mua
                      - NS: Bán
                  accountNo:
                    type: string
                    example: '0001179019'
                    description: Số tiểu khoản
                  symbol:
                    type: string
                    example: 41I1G4000
                    description: Mã chứng khoán
                  price:
                    type: number
                    example: 1618.2
                    description: Giá đặt
                    format: double
                  quantity:
                    type: integer
                    example: 1
                    description: Khối lượng đặt
                    format: int32
                  orderType:
                    type: string
                    example: LO
                    description: |-
                      Loại lệnh
                      - LO: Lệnh giới hạn
                      - MOK/MAK/MTL: Lệnh thị trường
                      - ATO/ATC: Lệnh phiên định kỳ mở cửa/đóng cửa
                      - PLO: Lệnh khớp lệnh sau giờ
                  fillQuantity:
                    type: integer
                    example: 0
                    description: Khối lượng khớp
                    format: int32
                  leaveQuantity:
                    type: integer
                    example: 0
                    description: Khối lượng còn lại
                    format: int32
                  canceledQuantity:
                    type: integer
                    example: 0
                    description: Khối lượng đã hủy
                    format: int32
                  loanPackageId:
                    type: integer
                    example: 2278
                    description: Mã gói vay
                    format: int32
                  createdDate:
                    type: string
                    example: '2026-03-24T04:20:55.63'
                    description: Thời điểm tạo
                    format: date-time
                  modifiedDate:
                    type: string
                    example: '2026-03-24T04:20:55.63'
                    description: Thời điểm cập nhật
                    format: date-time
              example:
                id: 1636
                side: NS
                accountNo: '0001179019'
                symbol: 41I1G4000
                price: 1618.2
                quantity: 1
                orderType: LO
                fillQuantity: 0
                leaveQuantity: 0
                canceledQuantity: 0
                loanPackageId: 2278
                createdDate: '2026-03-24T04:20:55.63'
                modifiedDate: '2026-03-24T04:20:55.63'
        '400':
          description: Yêu cầu không hợp lệ
          headers:
            Access-Control-Allow-Credentials:
              schema:
                type: boolean
              example: true
            Content-Length:
              schema:
                type: integer
              example: 88
            Date:
              schema:
                type: string
              example: Thu, 19 Mar 2026 04:32:21 GMT
            Vary:
              schema:
                type: string
              example: Origin
            X-Ratelimit-Limit:
              schema:
                type: integer
              example: -1
            X-Ratelimit-Remaining:
              schema:
                type: integer
              example: 0
            X-Ratelimit-Reset:
              schema:
                type: integer
              example: 0
            X-Tyk-Api-Expires:
              schema:
                type: string
              example: Thu, 02 Jan 3000 15:04:00 UTC
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: integer
                    example: 400
                    description: Mã HTTP
                    format: int32
                  code:
                    type: string
                    example: RESOURCE_NOT_FOUND
                    description: Mã lỗi
                  message:
                    type: string
                    example: Not found deal by id=177237715089
                    description: Thông điệp lỗi
              example:
                status: 400
                code: RESOURCE_NOT_FOUND
                message: Not found deal by id=177237715089
        '500':
          description: Lỗi hệ thống
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: integer
                    example: 500
                    description: Mã HTTP
                    format: int32
                  code:
                    type: string
                    example: OA-009
                    description: Mã lỗi
                  message:
                    type: string
                    example: Lỗi hệ thống
                    description: Thông điệp lỗi
              example:
                code: OA-009
                message: Lỗi hệ thống
                status: 500

````

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