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

# Vị thế

> ## Dữ liệu vị thế thời gian thực (Position Event)
Cung cấp thông tin chi tiết về vị thế giao dịch trên tài khoản người dùng theo thời gian thực.
Hệ thống sẽ đẩy dữ liệu ngay khi có sự thay đổi liên quan đến:
mở vị thế, đóng vị thế, thay đổi khối lượng, giá vốn, giá đóng, giá thị trường hoặc trạng thái vị thế.



## AsyncAPI

````yaml vi/asyncapi/dnse.2026-09-10.asyncapi.yaml positionStream
id: positionStream
title: Vị thế
description: >-
  ## Dữ liệu vị thế thời gian thực (Position Event)

  Cung cấp thông tin chi tiết về vị thế giao dịch trên tài khoản người dùng theo
  thời gian thực.

  Hệ thống sẽ đẩy dữ liệu ngay khi có sự thay đổi liên quan đến:

  mở vị thế, đóng vị thế, thay đổi khối lượng, giá vốn, giá đóng, giá thị trường
  hoặc trạng thái vị thế.
servers:
  - id: production
    protocol: wss
    host: ws-openapi.dnse.com.vn
    bindings: []
    variables: []
  - id: sanbox
    protocol: wss
    host: ws-sb-openapi.dnse.com.vn
    bindings: []
    variables: []
address: /v1/stream
parameters: []
bindings:
  - protocol: ws
    version: 0.1.0
    value:
      method: GET
      query:
        type: object
        additionalProperties: false
        required:
          - encoding
        properties:
          encoding:
            type: string
            const: json
            default: json
            description: Định dạng mã hóa dữ liệu WebSocket (`json`, `msgpack`).
    schemaProperties:
      - name: method
        type: string
        description: GET
        required: false
      - name: query
        type: object
        required: false
        properties:
          - name: encoding
            type: string
            description: Định dạng mã hóa dữ liệu WebSocket (`json`, `msgpack`).
            required: true
operations:
  - &ref_1
    id: onPositionSubscription
    title: Đăng ký luồng vị thế của nhà đầu tư
    type: receive
    messages:
      - &ref_3
        id: subscribeRequest
        contentType: application/json
        payload:
          - name: Đăng ký luồng vị thế của nhà đầu tư
            description: Đăng ký topic `position.{market_type}.{encoding}`.
            type: object
            properties:
              - name: action
                type: string
                description: subscribe
                required: true
              - name: channels
                type: array
                required: true
                properties:
                  - name: name
                    type: string
                    description: Topic vị thế của nhà đầu tư hiện tại theo loại thị trường.
                    required: true
        headers: []
        jsonPayloadSchema:
          type: object
          additionalProperties: false
          required:
            - action
            - channels
          properties:
            action:
              type: string
              const: subscribe
              x-parser-schema-id: <anonymous-schema-417>
            channels:
              type: array
              minItems: 1
              uniqueItems: true
              items:
                type: object
                additionalProperties: false
                required:
                  - name
                properties:
                  name:
                    type: string
                    description: Topic vị thế của nhà đầu tư hiện tại theo loại thị trường.
                    pattern: ^position\.(STOCK|DERIVATIVE)\.json$
                    x-parser-schema-id: <anonymous-schema-420>
                x-parser-schema-id: <anonymous-schema-419>
              x-parser-schema-id: <anonymous-schema-418>
          x-parser-schema-id: <anonymous-schema-416>
        title: Đăng ký luồng vị thế của nhà đầu tư
        description: Đăng ký topic `position.{market_type}.{encoding}`.
        example: |-
          {
            "action": "subscribe",
            "channels": [
              {
                "name": "position.STOCK.json"
              }
            ]
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: subscribeRequest
    bindings: []
    extensions: &ref_0
      - id: x-parser-unique-object-id
        value: positionStream
  - &ref_2
    id: onPositionUpdates
    title: Nhận cập nhật vị thế của nhà đầu tư
    type: send
    messages:
      - &ref_4
        id: update
        contentType: application/json
        payload:
          - name: Cập nhật vị thế của nhà đầu tư
            description: Bản cập nhật vị thế của nhà đầu tư hiện tại.
            type: object
            properties:
              - name: T
                type: string
                description: Mã loại message cập nhật vị thế.
                required: true
              - name: action
                type: string
                description: Loại hành động của message.
                required: true
              - name: event
                type: string
                description: Sự kiện làm phát sinh cập nhật vị thế.
                required: true
              - name: position
                type: object
                description: Thông tin vị thế được cập nhật.
                required: true
                properties:
                  - name: id
                    type: integer
                    description: Mã định danh vị thế.
                    required: true
                  - name: accountNo
                    type: string
                    description: Số tiểu khoản giao dịch.
                    required: true
                  - name: symbol
                    type: string
                    description: Mã chứng khoán.
                    required: true
                  - name: status
                    type: string
                    description: Trạng thái vị thế.
                    enumValues:
                      - OPEN
                      - PENDING_CLOSE
                      - CLOSED
                      - ODD_LOT
                    required: true
                  - name: side
                    type: string
                    description: Chiều vị thế, NB là mua và NS là bán.
                    enumValues:
                      - NB
                      - NS
                    required: true
                  - name: loanPackageId
                    type: integer
                    description: Mã gói vay.
                    required: true
                  - name: accumulateQuantity
                    type: integer
                    description: Tổng khối lượng đã mở được cộng dồn trong vị thế.
                    required: true
                  - name: tradeQuantity
                    type: integer
                    description: Khối lượng có thể bán; chỉ áp dụng cho thị trường cơ sở.
                    required: true
                  - name: marketType
                    type: string
                    description: Loại thị trường.
                    enumValues:
                      - STOCK
                      - DERIVATIVE
                    required: true
                  - name: openQuantity
                    type: integer
                    description: Tổng khối lượng mở trong vị thế.
                    required: true
                  - name: overNightQuantity
                    type: integer
                    description: >-
                      Khối lượng mở qua đêm; chỉ áp dụng cho thị trường phái
                      sinh.
                    required: true
                  - name: closedQuantity
                    type: integer
                    description: Khối lượng đã đóng.
                    required: true
                  - name: costPrice
                    type: number
                    description: Giá vốn trung bình của vị thế.
                    required: true
                  - name: marketPrice
                    type: number
                    description: Giá thị trường hiện tại.
                    required: true
                  - name: breakEvenPrice
                    type: number
                    description: Giá hòa vốn.
                    required: true
                  - name: averageClosePrice
                    type: number
                    description: Giá đóng trung bình tính trên khối lượng đã đóng.
                    required: true
                  - name: createdDate
                    type: string
                    description: Thời điểm mở vị thế (UTC).
                    required: true
                  - name: modifiedDate
                    type: string
                    description: Thời điểm cập nhật gần nhất (UTC).
                    required: true
              - name: sequence
                type: integer
                description: Số thứ tự của message trong luồng.
                required: true
              - name: timestamp
                type: integer
                description: >-
                  Thời điểm phát sinh message, Unix timestamp tính bằng
                  mili-giây.
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          description: Dữ liệu cập nhật vị thế của nhà đầu tư hiện tại.
          additionalProperties: false
          required:
            - T
            - action
            - event
            - position
            - sequence
            - timestamp
          properties:
            T:
              type: string
              const: dp
              description: Mã loại message cập nhật vị thế.
              x-parser-schema-id: <anonymous-schema-422>
            action:
              type: string
              const: position_update
              description: Loại hành động của message.
              x-parser-schema-id: <anonymous-schema-423>
            event:
              type: string
              description: Sự kiện làm phát sinh cập nhật vị thế.
              x-parser-schema-id: <anonymous-schema-424>
            position:
              type: object
              description: Thông tin vị thế được cập nhật.
              required:
                - id
                - accountNo
                - symbol
                - status
                - marketType
                - side
                - loanPackageId
                - accumulateQuantity
                - tradeQuantity
                - openQuantity
                - overNightQuantity
                - closedQuantity
                - costPrice
                - marketPrice
                - breakEvenPrice
                - averageClosePrice
                - createdDate
                - modifiedDate
              properties:
                id:
                  type: integer
                  format: int64
                  description: Mã định danh vị thế.
                  x-parser-schema-id: <anonymous-schema-426>
                accountNo:
                  type: string
                  description: Số tiểu khoản giao dịch.
                  x-parser-schema-id: <anonymous-schema-427>
                symbol:
                  type: string
                  description: Mã chứng khoán.
                  x-parser-schema-id: <anonymous-schema-428>
                status:
                  type: string
                  description: Trạng thái vị thế.
                  enum:
                    - OPEN
                    - PENDING_CLOSE
                    - CLOSED
                    - ODD_LOT
                  x-enum-descriptions:
                    - OPEN
                    - PENDING_CLOSE
                    - CLOSED
                    - ODD_LOT
                  x-enum-varnames:
                    - OPEN
                    - PENDING_CLOSE
                    - CLOSED
                    - ODD_LOT
                  x-parser-schema-id: <anonymous-schema-429>
                side:
                  type: string
                  description: Chiều vị thế, NB là mua và NS là bán.
                  enum:
                    - NB
                    - NS
                  x-enum-descriptions:
                    - NB
                    - NS
                  x-enum-varnames:
                    - NB
                    - NS
                  x-parser-schema-id: <anonymous-schema-430>
                loanPackageId:
                  type: integer
                  format: int64
                  description: Mã gói vay.
                  x-parser-schema-id: <anonymous-schema-431>
                accumulateQuantity:
                  type: integer
                  description: Tổng khối lượng đã mở được cộng dồn trong vị thế.
                  x-parser-schema-id: <anonymous-schema-432>
                tradeQuantity:
                  oneOf:
                    - type: integer
                      x-parser-schema-id: <anonymous-schema-434>
                    - type: 'null'
                      x-parser-schema-id: <anonymous-schema-435>
                  description: Khối lượng có thể bán; chỉ áp dụng cho thị trường cơ sở.
                  x-parser-schema-id: <anonymous-schema-433>
                marketType:
                  type: string
                  description: Loại thị trường.
                  enum:
                    - STOCK
                    - DERIVATIVE
                  x-enum-descriptions:
                    - STOCK
                    - DERIVATIVE
                  x-enum-varnames:
                    - STOCK
                    - DERIVATIVE
                  x-parser-schema-id: <anonymous-schema-436>
                openQuantity:
                  type: integer
                  description: Tổng khối lượng mở trong vị thế.
                  x-parser-schema-id: <anonymous-schema-437>
                overNightQuantity:
                  oneOf:
                    - type: integer
                      x-parser-schema-id: <anonymous-schema-439>
                    - type: 'null'
                      x-parser-schema-id: <anonymous-schema-440>
                  description: Khối lượng mở qua đêm; chỉ áp dụng cho thị trường phái sinh.
                  x-parser-schema-id: <anonymous-schema-438>
                closedQuantity:
                  type: integer
                  description: Khối lượng đã đóng.
                  x-parser-schema-id: <anonymous-schema-441>
                costPrice:
                  type: number
                  description: Giá vốn trung bình của vị thế.
                  x-parser-schema-id: <anonymous-schema-442>
                marketPrice:
                  type: number
                  description: Giá thị trường hiện tại.
                  x-parser-schema-id: <anonymous-schema-443>
                breakEvenPrice:
                  type: number
                  description: Giá hòa vốn.
                  x-parser-schema-id: <anonymous-schema-444>
                averageClosePrice:
                  type: number
                  description: Giá đóng trung bình tính trên khối lượng đã đóng.
                  x-parser-schema-id: <anonymous-schema-445>
                createdDate:
                  type: string
                  format: date-time
                  description: Thời điểm mở vị thế (UTC).
                  x-parser-schema-id: <anonymous-schema-446>
                modifiedDate:
                  type: string
                  format: date-time
                  description: Thời điểm cập nhật gần nhất (UTC).
                  x-parser-schema-id: <anonymous-schema-447>
              x-parser-schema-id: <anonymous-schema-425>
            sequence:
              type: integer
              format: int64
              description: Số thứ tự của message trong luồng.
              x-parser-schema-id: <anonymous-schema-448>
            timestamp:
              type: integer
              format: int64
              description: Thời điểm phát sinh message, Unix timestamp tính bằng mili-giây.
              x-parser-schema-id: <anonymous-schema-449>
          x-parser-schema-id: <anonymous-schema-421>
        title: Cập nhật vị thế của nhà đầu tư
        description: Bản cập nhật vị thế của nhà đầu tư hiện tại.
        example: |-
          {
            "T": "dp",
            "action": "position_update",
            "event": "pendingcancel",
            "position": {
              "id": 8426,
              "accountNo": "0001179019",
              "symbol": "ACB",
              "status": "OPEN",
              "loanPackageId": 5757,
              "side": "NB",
              "accumulateQuantity": 2400,
              "tradeQuantity": 2100,
              "closedQuantity": 300,
              "costPrice": 23125.21,
              "marketPrice": 23100,
              "breakEvenPrice": 23251.3689,
              "openQuantity": 2000,
              "overNightQuantity": null,
              "averageClosePrice": 23816.6667,
              "marketType": "STOCK",
              "createdDate": "2025-07-28T06:20:21.655809Z",
              "modifiedDate": "2026-05-07T11:10:08.787906Z"
            },
            "sequence": 1,
            "timestamp": 1776054245274
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: update
    bindings: []
    extensions: *ref_0
sendOperations:
  - *ref_1
receiveOperations:
  - *ref_2
sendMessages:
  - *ref_3
receiveMessages:
  - *ref_4
extensions:
  - id: x-parser-unique-object-id
    value: positionStream
securitySchemes: []

````

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