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

> Đóng deal Phái Sinh theo dealId.



## OpenAPI

````yaml /vi/openapi/entrade-v1.yaml post /derivative/deals/{dealId}/_close_deal
openapi: 3.1.0
info:
  title: Entrade Open API
  version: 1.0.0
  description: Đặc tả được trích xuất từ các request Bruno trong `collections/Entrade`.
servers:
  - url: https://services.entrade.com.vn/entrade-api
    description: Môi trường production
  - url: https://services-staging.entrade.com.vn/papertrade-entrade-api
    description: Môi trường staging
security:
  - BearerAuth: []
tags:
  - name: authentication
    description: API đăng nhập và cấp JWT token.
    x-group: Xác thực
  - name: account
    description: Thông tin tài khoản, tài sản và cấu hình rủi ro.
    x-group: Tài khoản
  - name: derivatives
    description: Giao dịch, sức mua, gói vay và vị thế phái sinh.
    x-group: Phái sinh
  - name: smart-order
    description: Lệnh điều kiện trên dịch vụ Smart Order.
    x-group: Smart Order
paths:
  /derivative/deals/{dealId}/_close_deal:
    post:
      tags:
        - derivatives
      summary: Đóng deal
      description: Đóng deal Phái Sinh theo dealId.
      operationId: closeDerivativeDeal
      parameters:
        - name: dealId
          in: path
          required: true
          description: Số hiệu deal
          schema:
            type: number
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                orderType:
                  type: string
                  description: Truyền vào "LO"
                triggeredBy:
                  type: string
                  description: Truyền vào "close-deal"
      responses:
        '200':
          description: Thành công
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/CloseDealResult'
                  - $ref: '#/components/schemas/DerivativeDealPage'
        '400':
          $ref: '#/components/responses/BadRequest'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    CloseDealResult:
      type: object
      properties:
        orderType:
          type: string
          description: Truyền vào "LO"
        triggeredBy:
          type: string
          description: Truyền vào "close-deal"
    DerivativeDealPage:
      type: object
      properties:
        data:
          type: array
          description: Danh sách Deal nắm giữ
          items:
            type: object
            properties:
              id:
                type: number
                description: Id deal
              bankId:
                type: number
              bankAccountId:
                type: number
              investorId:
                type: number
                description: Mã khách hàng
              investorAccountId:
                type: number
                description: Số tiểu khoản
              bankMarginPortfolioId:
                type: number
                description: Mã gói vay
              symbol:
                type: string
                description: Mã chứng khoán
              side:
                type: string
                description: 'Bên mua/bán: NB: mua; NS: bán'
              positionCostPrice:
                type: number
                description: Giá vốn toàn bộ open quantity
              stockClosePrice:
                type: number
              averageCostPrice:
                type: number
                description: Giá mở trung bình
              averageClosedPrice:
                type: number
              adjustedCostPrice:
                type: number
              openQuantity:
                type: number
                description: Khối lượng mở
              closedQuantity:
                type: number
                description: Khối lượng đã đóng
              initialQuantity:
                type: number
              type:
                type: string
              currentMarginRate:
                type: number
              cash:
                type: number
              cashSecure:
                type: number
              receivable:
                type: number
              loan:
                type: number
              secure:
                type: number
                description: Cọc hiện tại của deal
              additionalSecure:
                type: number
              interest:
                type: number
              totalDebt:
                type: number
              tradingFeeAmount:
                type: number
              marginExcessAmount:
                type: number
              marginCallAmount:
                type: number
              sellingTaxAmount:
                type: number
              moneyAdvanceFeeAmount:
                type: number
              moneyAdvanceAmount:
                type: number
              stockBorrowFee:
                type: number
              positionRealizedProfit:
                type: number
                description: Lãi đã đóng (chưa bao gồm phí thuế)
              lastRealizedProfit:
                type: number
              positionUnrealizedProfit:
                type: number
                description: Lãi mở (chưa bao gồm phí thuế)
              receivedQuantity:
                type: number
              positionType:
                type: number
              createdDate:
                type: string
                description: Giờ tạo
              modifiedDate:
                type: string
                description: Giờ cập nhật
              investorSettlementAmount:
                type: number
              bankSettlementAmount:
                type: number
              sourDebtPayment:
                type: number
              tradingTaxAmount:
                type: number
              closedPositionFeeAmount:
                type: number
              netProfit:
                type: number
                description: Lãi phần đóng (đã trừ thuế phí nếu có)
              unrealizedTotalTaxAndFee:
                type: number
                description: Phí thuế phần mở
              status:
                type: string
                description: >-
                  Trạng thái của deal, thuộc các giá trị sau: ACTIVE: đang mở;
                  CLOSED: đã đóng
              assetManagementOvernightFeeAmount:
                type: number
              unrealizedTradingTaxFactor:
                type: number
              accumulatedSecure:
                type: number
              breakEvenPrice:
                type: number
                description: Giá hoà vốn
              collectedInterestAndFee:
                type: number
                description: Phí thuế phần đã đóng
              releasedSecureAndProfit:
                type: number
              dailyReleasedSecureAndProfit:
                type: number
              dailyReleasedNetProfit:
                type: number
              totalInterestAndFeeWithoutClosingTax:
                type: number
              orderIds:
                type: array
                items:
                  type: number
              totalInterestAndFee:
                type: number
              coInvestTax:
                type: number
              fixedNetProfit:
                type: number
              overdueInterestRate:
                type: number
              dailyStockBorrowFee:
                type: number
              companySecureRate:
                type: number
              closedPositionFee:
                type: number
              moneyAdvanceRate:
                type: number
              assetManagementOvernightFee:
                type: number
              overnightRate:
                type: number
              sellingTaxRate:
                type: number
              bankSecureRate:
                type: number
              vsdSecureRate:
                type: number
              tradingTaxRate:
                type: number
              coInvestTaxRate:
                type: number
              settled:
                type: boolean
              remainingTradeableQuantity:
                type: number
              marginStatus:
                type: string
              totalFee:
                type: number
              netProfitRate:
                type: number
              initialMarginRate:
                type: number
              interestRate:
                type: number
              tradingFeeRate:
                type: number
              marginRate:
                type: number
              maintenanceRate:
                type: number
              additionalRate:
                type: number
              liquidateMarginRate:
                type: number
              closed:
                type: boolean
              state:
                type: string
        total:
          type: number
          description: Tổng số các deal
        start:
          type: number
          description: Số bắt đầu, nên để là 0
        end:
          type: number
          description: Số kết thúc, để start = 0 thì đây là số lượng deal muốn trả về
    Error:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
        status:
          type: number
  responses:
    BadRequest:
      description: Yêu cầu không hợp lệ
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InternalError:
      description: Lỗi máy chủ
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT token lấy từ API đăng nhập.

````

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