> ## 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.

# Cấu hình chốt lời, cắt lỗ của vị thế



## OpenAPI

````yaml /vi/openapi/dnse.2026-09-10.openapi.yaml get /positions/{positionId}/pnl-configs
openapi: 3.0.0
info:
  title: DNSE OpenAPI (2026-09-10)
  version: 2.0.0
  description: DNSE OpenAPI spec
servers:
  - url: https://openapi.dnse.com.vn
    description: Production
  - url: https://sb-openapi.dnse.com.vn
    description: Sanbox
security: []
tags:
  - name: trading
    description: Xác thực và các hoạt động đặt lệnh.
    x-group: Giao dịch
  - name: account
    description: Tài khoản, số dư, khoản vay, lệnh và vị thế.
    x-group: Tài khoản
  - name: market
    description: Thông tin mã chứng khoán, báo giá, OHLC và giao dịch.
    x-group: Dữ liệu thị trường
paths:
  /positions/{positionId}/pnl-configs:
    get:
      tags:
        - account
      summary: Cấu hình chốt lời, cắt lỗ của vị thế
      operationId: position_getPnlConfigs
      parameters:
        - $ref: '#/components/parameters/XApiKey'
        - $ref: '#/components/parameters/XAuxDate'
        - $ref: '#/components/parameters/XSignature'
        - name: positionId
          in: path
          required: true
          schema:
            type: string
        - name: marketType
          in: query
          required: true
          schema:
            allOf:
              - $ref: '#/components/schemas/MarketType'
            enum:
              - STOCK
              - DERIVATIVE
          description: |-
            Loại thị trường 
            - DERIVATIVE: Deal phái sinh
            Hiện tại chỉ hỗ trợ phái sinh
          example: DERIVATIVE
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PnlConfigsResponse'
              example:
                positionId: 177952229647243
                configs:
                  takeProfit:
                    enabled: true
                    strategy: DELTA_PRICE
                    rate: 0.52
                    deltaPrice: 162.8
                    orderMethod: FASTEST
                    orderDeltaPrice: 2
                  stopLoss:
                    enabled: true
                    strategy: PNL_RATE
                    rate: -0.34
                    deltaPrice: 50.3
                    orderMethod: DELTA_PRICE
                    orderDeltaPrice: 10.5
                    trailingEnabled: true
                createdDate: '2026-06-02T02:47:36.384761Z'
                modifiedDate: '2026-06-03T07:44:44.235941815Z'
        '400':
          $ref: '#/components/responses/BadRequest'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  parameters:
    XApiKey:
      name: X-Api-Key
      in: header
      required: true
      description: >-
        API key được cấp khi đăng ký dịch vụ DNSE OpenAPI.

        Ví dụ:
        `b3JnOmRuc2UgaWQ6MjdlZTc1MzcxZGFkNTY0NmYzYTM2NDk1ZGE3OGNiOGQgaDptdXJtdXIxMjg=`
      schema:
        type: string
    XAuxDate:
      name: X-Aux-Date
      in: header
      required: true
      description: |-
        Thời gian thực hiện request, dùng trong cơ chế ký request của DNSE.
        Ví dụ: `Sat, 01 May 2026 14:24:23 +0000`
      schema:
        type: string
    XSignature:
      name: X-Signature
      in: header
      required: true
      description: >-
        Chữ ký xác thực request được tạo từ API key secret và X-Aux-Date.

        Ví dụ: `Signature
        keyId="b3JnOmRuc2UgaWQ6MjdlZTc1MzcxZGFkNTY0NmYzYTM2NDk1ZGE3OGNiOGQgaDptdXJtdXIxMjg=",algorithm="hmac-sha256",headers="(request-target)
        x-aux-date",signature="rfbVXHDUi%2B%2FsOkLXle7O17Qm%2F05cbISSR%2BDcFrBHfqQ%3D",nonce="4add8c3264e4492b9f8ecde0cf26b523"`
      schema:
        type: string
  schemas:
    MarketType:
      type: string
      description: |-
        Loại thị trường.

        - `STOCK`: Giao dịch cơ sở
        - `DERIVATIVE`: Giao dịch phái sinh
        - `BOND`: Giao dịch trái phiếu
      enum:
        - STOCK
        - DERIVATIVE
        - BOND
      x-enum-descriptions:
        - Giao dịch cơ sở
        - Giao dịch phái sinh
        - Giao dịch trái phiếu
      x-enum-varnames:
        - STOCK
        - DERIVATIVE
        - BOND
      example: STOCK
    PnlConfigsResponse:
      type: object
      properties:
        accountNo:
          type: string
          example: '0001179019'
          description: Số tiểu khoản chứng khoán
        positionId:
          type: integer
          example: 177952229647243
          description: ID vị thế
          format: int64
        configs:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/PnlConfig'
          example:
            takeProfit:
              enabled: true
              strategy: DELTA_PRICE
              rate: 0.52
              deltaPrice: 162.8
              orderMethod: FASTEST
              orderDeltaPrice: 2
            stopLoss:
              enabled: true
              strategy: PNL_RATE
              rate: -0.34
              deltaPrice: 50.3
              orderMethod: DELTA_PRICE
              orderDeltaPrice: 10.5
              trailingEnabled: true
          description: Cấu hình chốt lời và cắt lỗ của vị thế
          properties:
            takeProfit:
              type: object
              example:
                enabled: true
                strategy: DELTA_PRICE
                rate: 0.52
                deltaPrice: 162.8
                orderMethod: FASTEST
                orderDeltaPrice: 2
              description: Cấu hình chốt lời (Take Profit)
              properties:
                enabled:
                  type: boolean
                  example: true
                  description: Bật/tắt chức năng chốt lời
                strategy:
                  allOf:
                    - $ref: '#/components/schemas/PnlStrategy'
                  example: DELTA_PRICE
                  description: |-
                    Chiến lược kích hoạt chốt lời
                    - PNL_RATE: Kích hoạt theo tỷ lệ %
                    - DELTA_PRICE: Kích hoạt theo mức chênh lệch giá
                rate:
                  type: number
                  example: 0.52
                  format: double
                  description: >-
                    Tỷ lệ % so với giá hòa vốn, dùng để kích hoạt chốt lời khi
                    strategy = PNL_RATE. Giá trị phải lớn hơn 0
                deltaPrice:
                  type: number
                  example: 162.8
                  format: double
                  description: >-
                    Mức chênh lệch giá so với giá hòa vốn, dùng để kích hoạt
                    chốt lời khi strategy = DELTA_PRICE. Giá trị phải lớn hơn 0
                orderMethod:
                  allOf:
                    - $ref: '#/components/schemas/PnlOrderMethod'
                  example: FASTEST
                  description: >-
                    Phương thức đặt lệnh khi điều kiện chốt lời được kích hoạt.

                    - FASTEST: Lệnh khớp ngay với giá đặt là giá trần/sàn tùy
                    theo chiều vị thế Bán/Mua

                    - DELTA_PRICE: Lệnh đặt theo biên độ giá so với giá kích
                    hoạt
                orderDeltaPrice:
                  type: integer
                  example: 2
                  description: >-
                    Biên độ giá đặt lệnh khi orderMethod = DELTA_PRICE. Bằng 0
                    khi orderMethod = FASTEST
                  format: int32
            stopLoss:
              type: object
              example:
                enabled: true
                strategy: PNL_RATE
                rate: -0.34
                deltaPrice: 50.3
                orderMethod: DELTA_PRICE
                orderDeltaPrice: 10.5
                trailingEnabled: true
              description: Cấu hình cắt lỗ (Stop Loss)
              properties:
                enabled:
                  type: boolean
                  example: true
                  description: Bật/tắt chức năng cắt lỗ
                strategy:
                  allOf:
                    - $ref: '#/components/schemas/PnlStrategy'
                  example: PNL_RATE
                  description: |-
                    Chiến lược kích hoạt cắt lỗ
                    - PNL_RATE: Kích hoạt theo tỷ lệ %
                    - DELTA_PRICE: Kích hoạt theo mức chênh lệch giá.
                rate:
                  type: number
                  example: -0.34
                  description: >-
                    Tỷ lệ % so với giá hòa vốn, dùng để kích hoạt chốt lời khi
                    strategy = PNL_RATE. Giá trị hợp lệ trong khoảng [-1.0, 0)
                  format: double
                deltaPrice:
                  type: number
                  example: 50.3
                  description: >-
                    Mức chênh lệch giá so với giá hòa vốn, dùng để kích hoạt
                    chốt lời khi strategy = DELTA_PRICE. Giá trị phải lớn hơn 0
                  format: double
                orderMethod:
                  allOf:
                    - $ref: '#/components/schemas/PnlOrderMethod'
                  example: DELTA_PRICE
                  description: >-
                    Phương thức đặt lệnh khi điều kiện chốt lời được kích hoạt.

                    - FASTEST: Lệnh khớp ngay với giá đặt là giá trần/sàn tùy
                    theo chiều vị thế Bán/Mua

                    - DELTA_PRICE: Lệnh đặt theo biên độ giá so với giá kích
                    hoạt
                orderDeltaPrice:
                  type: number
                  example: 10.5
                  description: >-
                    Biên độ giá đặt lệnh khi orderMethod = DELTA_PRICE. Bằng 0
                    khi orderMethod = FASTEST
                  format: float
                trailingEnabled:
                  type: boolean
                  example: true
                  description: >-
                    Bật/tắt cơ chế Trailing Stop. Lưu ý cơ chế này chỉ hoạt động
                    khi chức năng cắt lỗ được bật
        createdDate:
          type: string
          example: '2026-06-02T02:47:36.384761Z'
          description: Thời điểm cấu hình được tạo
          format: date-time
        modifiedDate:
          type: string
          example: '2026-06-03T07:52:08.00923505Z'
          description: Thời điểm cập nhật cấu hình gần nhất
          format: date-time
    PnlConfig:
      type: object
      properties:
        enabled:
          type: boolean
          example: true
          description: Bật/tắt chức năng chốt lời
        strategy:
          allOf:
            - $ref: '#/components/schemas/PnlStrategy'
          example: DELTA_PRICE
          description: |-
            Chiến lược kích hoạt chốt lời 
              - PNL_RATE: Kích hoạt theo tỷ lệ %
              - DELTA_PRICE: Kích hoạt theo mức chênh lệch giá                       
        rate:
          type: number
          example: 0.52
          format: double
          description: >-
            Tỷ lệ % so với giá hòa vốn, dùng để kích hoạt chốt lời khi strategy
            = PNL_RATE. Giá trị phải lớn hơn 0
        deltaPrice:
          type: number
          example: 162.8
          format: double
          description: >-
            Mức chênh lệch giá so với giá hòa vốn, dùng để kích hoạt chốt lời
            khi strategy = DELTA_PRICE. Giá trị phải lớn hơn 0
        orderMethod:
          allOf:
            - $ref: '#/components/schemas/PnlOrderMethod'
          example: FASTEST
          description: |-
            Phương thức đặt lệnh khi điều kiện chốt lời được kích hoạt.
              - FASTEST: Lệnh khớp ngay với giá đặt là giá trần/sàn tùy theo chiều vị thế Bán/Mua
              - DELTA_PRICE: Lệnh đặt theo biên độ giá so với giá kích hoạt 
        orderDeltaPrice:
          type: number
          format: double
          example: 2
          description: >-
            Biên độ giá đặt lệnh so với giá kích hoạt khi orderMethod =
            DELTA_PRICE. Có thể là số âm, số dương hoặc bằng 0
        trailingEnabled:
          type: boolean
          example: true
          description: >-
            Bật/tắt cơ chế Trailing Stop. Lưu ý cơ chế này chỉ hoạt động khi
            chức năng cắt lỗ được bật
      description: Cấu hình chốt lời (Take Profit)
    PnlStrategy:
      type: string
      description: |-
        Chiến lược kích hoạt chốt lời hoặc cắt lỗ.

        - `PNL_RATE`: Kích hoạt theo tỷ lệ phần trăm
        - `DELTA_PRICE`: Kích hoạt theo mức chênh lệch giá
      enum:
        - PNL_RATE
        - DELTA_PRICE
      x-enum-descriptions:
        - Kích hoạt theo tỷ lệ phần trăm
        - Kích hoạt theo mức chênh lệch giá
      x-enum-varnames:
        - PNL_RATE
        - DELTA_PRICE
      example: DELTA_PRICE
    PnlOrderMethod:
      type: string
      description: |-
        Phương thức đặt lệnh khi điều kiện chốt lời hoặc cắt lỗ được kích hoạt.

        - `FASTEST`: Đặt lệnh với giá trần hoặc sàn
        - `DELTA_PRICE`: Đặt lệnh theo biên độ giá so với giá kích hoạt
      enum:
        - FASTEST
        - DELTA_PRICE
      x-enum-descriptions:
        - Đặt lệnh với giá trần hoặc sàn
        - Đặt lệnh theo biên độ giá so với giá kích hoạt
      x-enum-varnames:
        - FASTEST
        - DELTA_PRICE
      example: FASTEST
    ErrorBody:
      type: object
      required:
        - status
        - code
        - message
      properties:
        status:
          type: integer
          format: int32
          description: Mã HTTP.
          example: 400
        code:
          type: string
          description: Mã lỗi DNSE.
          example: OA-003
        message:
          type: string
          description: Thông điệp lỗi.
          example: Thông tin nhập không hợp lệ
  responses:
    BadRequest:
      description: Yêu cầu không hợp lệ.
      headers:
        Content-Length:
          $ref: '#/components/headers/ContentLength'
        Date:
          $ref: '#/components/headers/Date'
        Vary:
          $ref: '#/components/headers/Vary'
        X-Ratelimit-Limit:
          $ref: '#/components/headers/XRateLimitLimit'
        X-Ratelimit-Remaining:
          $ref: '#/components/headers/XRateLimitRemaining'
        X-Ratelimit-Reset:
          $ref: '#/components/headers/XRateLimitReset'
        X-Request-Id:
          $ref: '#/components/headers/XRequestId'
        X-Tyk-Api-Expires:
          schema:
            type: string
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
          example:
            status: 400
            code: OA-003
            message: Thông tin nhập không hợp lệ
    InternalError:
      description: Lỗi hệ thống.
      headers:
        Content-Length:
          $ref: '#/components/headers/ContentLength'
        Date:
          $ref: '#/components/headers/Date'
        Vary:
          $ref: '#/components/headers/Vary'
        X-Ratelimit-Limit:
          $ref: '#/components/headers/XRateLimitLimit'
        X-Ratelimit-Remaining:
          $ref: '#/components/headers/XRateLimitRemaining'
        X-Ratelimit-Reset:
          $ref: '#/components/headers/XRateLimitReset'
        X-Request-Id:
          $ref: '#/components/headers/XRequestId'
        X-Tyk-Api-Expires:
          schema:
            type: string
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
          example:
            status: 500
            code: OA-009
            message: Lỗi hệ thống
  headers:
    ContentLength:
      description: Response body size in bytes.
      schema:
        type: integer
      example: 430
    Date:
      description: Response date from the DNSE gateway.
      schema:
        type: string
      example: Wed, 18 Mar 2026 16:17:35 GMT
    Vary:
      description: >-
        Response header indicating the request headers used for content
        negotiation.
      schema:
        type: string
      example: Origin
    XRateLimitLimit:
      description: Maximum number of requests allowed in the current rate-limit window.
      schema:
        type: integer
      example: 300
    XRateLimitRemaining:
      description: Number of requests remaining in the current rate-limit window.
      schema:
        type: integer
      example: 299
    XRateLimitReset:
      description: Unix timestamp at which the current rate-limit window resets.
      schema:
        type: integer
      example: 1773850655
    XRequestId:
      description: Unique identifier assigned to the request by the DNSE gateway.
      schema:
        type: string
      example: unknown

````

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