> ## Documentation Index
> Fetch the complete documentation index at: https://developers.fhsc.com.vn/llms.txt
> Use this file to discover all available pages before exploring further.

# Tổng quan tài sản của user

> Tổng quan số dư và tài sản của user: tài sản ròng, chi tiết từng loại
sản phẩm (stock / fund / bond / hay0), tiền mặt, dư nợ và PnL.

Với user Level 0 / 1, các field `products.stock`, `products.fund`,
`products.bond` và các entry trong `pnl` đều trả về `0`.
`products.saving` có thể `null`.

Để có giá trị NAV / tổng tài sản chính xác nhất, gọi endpoint này KÈM
`GET /trading/accounts/{subAccountId}/summary` rồi reconcile field
`net_asset_value` — endpoint này tổng hợp cross-product cấp user,
còn `accounts/summary` chi tiết theo từng tiểu khoản.




## OpenAPI

````yaml /openapi.yaml get /users/v3/users/{userId}/assets/summary
openapi: 3.1.0
info:
  title: Finhay Securities Open API
  version: 0.2.0-preview.2
  description: |
    Đặc tả chính thức của Finhay Securities Open API, dùng chung cho SDK
    codegen, Redoc docs, và (sau này) mock server / contract test.

    ## Authentication — 2 tier

    - **Tier 1 — chỉ cần API key**: các endpoint đọc dữ liệu thị trường
      (`GET /market/**`, `GET /trading/market/**`). Gửi kèm header
      `X-FH-APIKEY` là đủ.
    - **Tier 2 — HMAC signing**: các endpoint liên quan đến account /
      trading / user. Gửi kèm 4 header `X-FH-APIKEY` + `X-FH-TIMESTAMP` +
      `X-FH-NONCE` + `X-FH-SIGNATURE`; thêm `X-FH-BODYHASH` khi request có
      body. Chi tiết thuật toán xem extension `x-finhay-signing` ở root
      spec hoặc phần README.

    ## Bootstrap flow

    Gọi 2 endpoint tag **Khởi tạo** (`GET /users/v1/users/me` và
    `GET /users/v1/users/{userId}/sub-accounts`) **1 lần khi khởi tạo
    client** để lấy thông tin `user_id` và `subAccountId`. Mọi endpoint thuộc
    tag **Tổng tài sản / Tiểu khoản / Danh mục đầu tư / Sổ lệnh / Lãi-lỗ /
    Quyền cổ đông** đều cần 2 giá trị này để truyền vào path parameter.
  contact: {}
servers:
  - url: https://open-api.fhsc.com.vn
    description: Production
security:
  - FinhayApiKey: []
tags:
  - name: Khởi tạo
    description: >-
      Khởi tạo client — lấy `user_id` và `subAccountId`. Gọi 1 lần khi khởi tạo
      SDK rồi cache lại.
  - name: Dữ liệu giao dịch
    description: >-
      Giá stock realtime và lịch sử OHLCV (dạng columnar, phục vụ charting /
      time-series).
  - name: Phân tích cơ bản
    description: >-
      Chỉ số tài chính cơ bản của doanh nghiệp — chỉ số tổng quan, phân tích
      theo kỳ và báo cáo tài chính chuẩn (income statement / balance sheet /
      cash flow).
  - name: Tin tức-sự kiện
    description: >-
      Sự kiện doanh nghiệp (cổ tức, quyền mua, ĐHCĐ, …), tin tức stock, tin tức
      tài chính toàn cầu (forex / commodities / economic-indicators /
      stock-market / cryptocurrency) và báo cáo khuyến nghị từ analyst.
  - name: Kinh tế vĩ mô
    description: >-
      Chỉ số kinh tế vĩ mô (CPI, PMI, PCE, GDP, …) và lãi suất tiền gửi ngân
      hàng.
  - name: Hàng hoá
    description: >-
      Hàng hoá và tài sản thay thế — vàng, bạc (spot / chart / theo nhà cung
      cấp) và crypto trending.
  - name: Tổng hợp đa loại
    description: >-
      Endpoint composite tổng hợp cross-domain (vàng / bạc / crypto / FX / lãi
      suất / US index) trong 1 call. Nên dùng endpoint chuyên biệt nếu chỉ cần 1
      loại.
  - name: Quỹ mở
    description: >-
      Quỹ mở (open-ended funds) — danh sách quỹ, công ty quản lý, NAV history,
      holdings, ranking và benchmark cross-fund.
  - name: Tổng tài sản
    description: >-
      Tổng quan tài sản cấp user — cross-product (stock, fund, bond, hay0) kèm
      cash, debt, PnL.
  - name: Tiểu khoản
    description: Thông tin tiểu khoản — số dư, margin, dư nợ và ngân hàng liên kết.
  - name: Danh mục đầu tư
    description: Danh mục stock đang nắm giữ kèm giá realtime và PnL theo vị thế.
  - name: Sổ lệnh
    description: >-
      Quản lý lệnh — sổ lệnh trong ngày, danh sách đầy đủ hoặc chi tiết theo
      `orderId`.
  - name: Lãi-lỗ
    description: PnL và analytics cá nhân — lãi / lỗ trong ngày tổng hợp theo user.
  - name: Quyền cổ đông
    description: Quyền cổ đông (cổ tức, quyền mua, bỏ phiếu, …) của tiểu khoản.
  - name: Phiên giao dịch
    description: >-
      Hạ tầng trading — trạng thái phiên giao dịch và order type khả dụng của
      mỗi exchange.
  - name: Thực thi lệnh
    description: |
      ⚠️ Nhóm endpoint này đang ở giai đoạn **preview**.

      Đặt / sửa / huỷ lệnh trên sàn — write operation nhạy cảm, yêu cầu
      Tier 2 HMAC đầy đủ + `X-FH-BODYHASH` + `X-FH-2FA-TOKEN` (daily 2FA
      session).
paths:
  /users/v3/users/{userId}/assets/summary:
    get:
      tags:
        - Tổng tài sản
      summary: Tổng quan tài sản của user
      description: |
        Tổng quan số dư và tài sản của user: tài sản ròng, chi tiết từng loại
        sản phẩm (stock / fund / bond / hay0), tiền mặt, dư nợ và PnL.

        Với user Level 0 / 1, các field `products.stock`, `products.fund`,
        `products.bond` và các entry trong `pnl` đều trả về `0`.
        `products.saving` có thể `null`.

        Để có giá trị NAV / tổng tài sản chính xác nhất, gọi endpoint này KÈM
        `GET /trading/accounts/{subAccountId}/summary` rồi reconcile field
        `net_asset_value` — endpoint này tổng hợp cross-product cấp user,
        còn `accounts/summary` chi tiết theo từng tiểu khoản.
      operationId: assetGetSummary
      parameters:
        - $ref: '#/components/parameters/UserId'
      responses:
        '200':
          description: >-
            Trả về `data` chứa `net_asset_value`, breakdown theo `products`
            (stock/fund/bond/hay0), `money` (cash), `debt`, và `pnl` cho từng
            loại sản phẩm.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserAssetsSummaryResponse'
              example:
                error_code: '0'
                message: success
                data:
                  net_asset_value: 162500000
                  products:
                    total: 150000000
                    stock: 120000000
                    fund: 20000000
                    saving: null
                    bond: 10000000
                    hay0: 0
                    hay0_interest: 0
                    hay0_depositing: 0
                    hay0_withdrawing: 0
                  money:
                    total: 12500000
                    ci_balance: 10000000
                    ca_receiving: 0
                    emk_amt: 0
                    receiving_amt: 0
                    baldefovd: 12500000
                  debt:
                    total: 0
                    secure_amount: 0
                    advance_amt: 0
                    sms_fee_amt: 0
                    cidepo_fee_acr: 0
                    owe_deposit: 0
                  pnl:
                    stock:
                      pnl: 4500000
                      pnl_rate: 3.9
                    fund:
                      pnl: 500000
                      pnl_rate: 2.56
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
      security:
        - FinhayApiKey: []
          FinhayTimestamp: []
          FinhayNonce: []
          FinhaySignature: []
      x-codeSamples:
        - lang: bash
          label: cURL
          source: |
            curl \
              -H "X-FH-APIKEY: $FINHAY_API_KEY" \
              -H "X-FH-TIMESTAMP: $TIMESTAMP_MS" \
              -H "X-FH-NONCE: $NONCE_UUID" \
              -H "X-FH-SIGNATURE: $SIGNATURE_HEX" \
              "https://open-api.fhsc.com.vn/users/v3/users/$USER_ID/assets/summary"
components:
  parameters:
    UserId:
      name: userId
      in: path
      required: true
      description: |
        User ID. Được lấy từ bootstrap flow (`GET /users/v1/users/me`).
      schema:
        type: integer
        format: int64
        example: 123456
  schemas:
    UserAssetsSummaryResponse:
      allOf:
        - $ref: '#/components/schemas/EnvelopeBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/UserAssetsSummary'
    EnvelopeBase:
      type: object
      description: |
        Các field chung của envelope trong mọi response của Finhay API.

        - `error_code` là `"0"` (string) khi thành công, mã khác `"0"` khi lỗi.
        - `message` là thông điệp ngắn từ server.
      properties:
        error_code:
          type: string
          description: '`"0"` khi thành công, khác `"0"` khi lỗi.'
          example: '0'
        message:
          type: string
          description: Thông điệp trạng thái dễ đọc.
          example: success
    UserAssetsSummary:
      type: object
      description: >
        Tổng quan tài sản / số dư của user qua mọi loại sản phẩm (stock, fund,

        bond, hay0), kèm tiền mặt, dư nợ và PnL.


        Với user Level 0 / 1, `products.stock`, `products.fund`, `products.bond`

        và các entry trong `pnl` đều trả về `0`. `products.saving` có thể
        `null`.
      properties:
        net_asset_value:
          type: number
          description: Total net asset value.
        products:
          $ref: '#/components/schemas/ProductsSummary'
        money:
          $ref: '#/components/schemas/MoneySummary'
        debt:
          $ref: '#/components/schemas/DebtSummary'
        pnl:
          $ref: '#/components/schemas/PnlSummary'
    ErrorBody:
      type: object
      description: Body của response khi 4xx / 5xx.
      properties:
        error_code:
          type: string
          description: >-
            Mã lỗi khác `"0"` (ví dụ `AUTH_SIGNATURE_INVALID`,
            `RATE_LIMIT_EXCEEDED`, …).
          example: '400'
        message:
          type: string
          description: Thông điệp lỗi (tiếng Anh, từ server).
          example: Invalid parameter
      required:
        - error_code
        - message
    ProductsSummary:
      type: object
      description: Giá trị tài sản chia theo loại sản phẩm.
      properties:
        total:
          type: number
          description: Total product value.
        stock:
          type: number
          description: Stock value.
        fund:
          type: number
          description: Fund value.
        saving:
          type:
            - number
            - 'null'
          description: Saving amount (may be null).
        bond:
          type: number
          description: >
            HayBond product value. **Lưu ý**: field này chỉ đại diện cho sản
            phẩm

            HayBond — KHÔNG phải trái phiếu doanh nghiệp / chính phủ thông
            thường.
        hay0:
          type: number
          description: Hay0 NAV.
        hay0_interest:
          type: number
          description: Hay0 interest.
        hay0_depositing:
          type: number
          description: Hay0 amount being deposited.
        hay0_withdrawing:
          type: number
          description: Hay0 amount being withdrawn.
    MoneySummary:
      type: object
      description: Số dư tiền mặt.
      properties:
        total:
          type: number
          description: Total cash.
        ci_balance:
          type: number
          description: Cash balance in account.
        ca_receiving:
          type: number
          description: Dividend cash pending.
        emk_amt:
          type: number
          description: Other blocked funds.
        receiving_amt:
          type: number
          description: Cash to receive.
        baldefovd:
          type: number
          description: Available withdrawable amount.
    DebtSummary:
      type: object
      description: Chi tiết dư nợ.
      properties:
        total:
          type: number
          description: Total debt.
        secure_amount:
          type: number
          description: Secured loan amount.
        advance_amt:
          type: number
          description: Advanced amount.
        sms_fee_amt:
          type: number
          description: SMS fee amount.
        cidepo_fee_acr:
          type: number
          description: CIDEPO fee accrual.
        owe_deposit:
          type: number
          description: Deposit owed.
    PnlSummary:
      type: object
      description: PnL chia theo loại tài sản.
      properties:
        stock:
          $ref: '#/components/schemas/PnlEntry'
        fund:
          $ref: '#/components/schemas/PnlEntry'
    PnlEntry:
      type: object
      description: Số tiền PnL và tỷ lệ PnL cho 1 loại tài sản.
      properties:
        pnl:
          type: number
          description: Profit/loss amount.
        pnl_rate:
          type: number
          description: Profit/loss rate (percentage).
  responses:
    BadRequest:
      description: Request không hợp lệ — thiếu hoặc sai tham số.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
          example:
            error_code: '400'
            message: Invalid parameter
    Unauthorized:
      description: Không xác thực — thiếu, sai hoặc không hợp lệ chữ ký / API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
          example:
            error_code: '401'
            message: Invalid signature
    RateLimited:
      description: >-
        Vượt giới hạn rate limit. Chờ đến thời điểm `X-RateLimit-Reset` rồi thử
        lại.
      headers:
        X-RateLimit-Reset:
          $ref: '#/components/headers/XRateLimitReset'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
          example:
            error_code: '429'
            message: Too many requests
    InternalError:
      description: Lỗi server nội bộ.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
          example:
            error_code: '500'
            message: Internal server error
  headers:
    XRateLimitReset:
      description: |
        Unix timestamp (giây) — thời điểm window rate limit reset. Client nhận
        `429 Too Many Requests` nên chờ đến thời điểm này rồi retry.
      schema:
        type: integer
        format: int64
        example: 1713441600
  securitySchemes:
    FinhayApiKey:
      type: apiKey
      in: header
      name: X-FH-APIKEY
      description: >
        API key dài hạn của client. Cấu hình 1 lần lúc khởi tạo; có thể wire
        thẳng

        vào static setter của SDK tự-gen. Đi kèm với `FINHAY_API_SECRET` —
        secret

        này chỉ dùng ở phía client để tính `X-FH-SIGNATURE`, **không** bao giờ

        gửi qua mạng.
    FinhayTimestamp:
      type: apiKey
      in: header
      name: X-FH-TIMESTAMP
      description: >
        Unix time hiện tại tính bằng **milliseconds**, đưới dạng chuỗi số thập
        phân.


        Được tính per-request bởi signing middleware. **Không** set thủ công —
        dùng

        middleware mẫu trong README.
    FinhayNonce:
      type: apiKey
      in: header
      name: X-FH-NONCE
      description: |
        UUIDv4 duy nhất per-request (ví dụ `crypto.randomUUID()`). Server cache
        cặp `(apiKey, nonce)` trong 5 phút; nếu nonce được reuse với cùng apiKey
        trong window này, request sẽ bị từ chối với `AUTH_NONCE_REUSED` (401).

        Server chấp nhận chuỗi opaque bất kỳ về mặt kỹ thuật, nhưng nên dùng
        UUIDv4 để đảm bảo tính unique.

        Được tính per-request bởi signing middleware. **Không** set thủ công —
        xem middleware mẫu trong tài liệu Authentication.
    FinhaySignature:
      type: apiKey
      in: header
      name: X-FH-SIGNATURE
      description: >
        HMAC-SHA256 của canonical signing payload, encode hex (lowercase).


        Signing payload:

        ```

        {X-FH-TIMESTAMP}\n{METHOD}\n{REQUEST_PATH}[?{QUERY}]\n{BODYHASH}

        ```

        - `?{QUERY}` chỉ nối vào path khi request có query string.

        - `{BODYHASH}` là chuỗi rỗng khi body rỗng (vẫn không có newline sau
        đó).


        Được tính per-request bởi signing middleware. **Không** set thủ công —
        dùng

        middleware mẫu trong README.

````