> ## 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ài đặt chốt lời, cắt lỗ cho tiểu khoản

> Cài đặt cấu hình chốt lời, cắt lỗ cho tiểu khoản giao dịch, chỉ áp dụng cho phái sinh và các vị thế mới mở sau khi cài đặt thành công.



## OpenAPI

````yaml /vi/openapi/dnse.openapi.yaml patch /accounts/{accountNo}/pnl-configs
openapi: 3.0.0
info:
  title: DNSE OpenAPI (2026-09-25)
  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:
  /accounts/{accountNo}/pnl-configs:
    patch:
      tags:
        - trading
      summary: Cài đặt chốt lời, cắt lỗ cho tiểu khoản
      description: >-
        Cài đặt cấu hình chốt lời, cắt lỗ cho tiểu khoản giao dịch, chỉ áp dụng
        cho phái sinh và các vị thế mới mở sau khi cài đặt thành công.
      operationId: account_patchPnlConfigs
      parameters:
        - $ref: '#/components/parameters/XApiKey'
        - $ref: '#/components/parameters/XAuxDate'
        - $ref: '#/components/parameters/XSignature'
        - $ref: '#/components/parameters/TradingToken'
        - name: accountNo
          in: path
          required: true
          description: Số tiểu khoản
          schema:
            type: string
          example: '0001179019'
        - name: marketType
          in: query
          required: true
          description: Loại thị trường, hiện chỉ hỗ trợ DERIVATIVE.
          schema:
            type: string
            enum:
              - DERIVATIVE
          example: DERIVATIVE
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PnlConfigsRequest'
            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
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountPnlConfigsResponse'
              example:
                accountNo: '0001179019'
                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-09-10T02:47:36.384761Z'
                modifiedDate: '2026-09-10T07: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
    TradingToken:
      name: trading-token
      in: header
      required: true
      description: >-
        Trading token dùng cho các operation đặt, sửa, hủy lệnh hoặc đóng vị
        thế.

        Ví dụ: `9ab81e9c-8a81-45aa-8190-b69a1c179d52`
      schema:
        type: string
  schemas:
    PnlConfigsRequest:
      type: object
      properties:
        takeProfit:
          $ref: '#/components/schemas/PnlConfig'
        stopLoss:
          $ref: '#/components/schemas/PnlConfig'
      description: Cấu hình chốt lời, cắt lỗ
    AccountPnlConfigsResponse:
      type: object
      description: Cấu hình chốt lời, cắt lỗ của tiểu khoản.
      properties:
        accountNo:
          type: string
          example: '0001179019'
          description: Số tiểu khoản chứng khoán.
        configs:
          type: object
          description: Cấu hình chốt lời và cắt lỗ của tiểu khoản.
          properties:
            takeProfit:
              $ref: '#/components/schemas/PnlConfig'
            stopLoss:
              $ref: '#/components/schemas/PnlConfig'
        createdDate:
          type: string
          format: date-time
          example: '2026-09-10T02:47:36.384761Z'
          description: Thời điểm cấu hình được tạo.
        modifiedDate:
          type: string
          format: date-time
          example: '2026-09-10T07:44:44.235941815Z'
          description: Thời điểm cập nhật cấu hình gần nhất.
    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)
    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ệ
    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
  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.