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

# Dữ liệu vĩ mô

> Chỉ số kinh tế vĩ mô của Việt Nam hoặc Mỹ. `type` và `country` là
bắt buộc.




## OpenAPI

````yaml /openapi.yaml get /market/financial-data/macro
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:
  /market/financial-data/macro:
    get:
      tags:
        - Kinh tế vĩ mô
      summary: Dữ liệu vĩ mô
      description: |
        Chỉ số kinh tế vĩ mô của Việt Nam hoặc Mỹ. `type` và `country` là
        bắt buộc.
      operationId: macroGetMacroData
      parameters:
        - name: type
          in: query
          required: true
          description: Loại chỉ số vĩ mô.
          schema:
            $ref: '#/components/schemas/MacroType'
        - name: country
          in: query
          required: true
          description: Mã quốc gia.
          schema:
            $ref: '#/components/schemas/Country'
        - name: period
          in: query
          required: false
          description: Khoảng thời gian lọc.
          schema:
            $ref: '#/components/schemas/Period'
      responses:
        '200':
          description: >-
            Trả về `data` mảng các điểm dữ liệu vĩ mô theo tháng cho `type` +
            `country` đã chọn.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MacroDataResponse'
              example:
                error_code: '0'
                message: success
                data:
                  - type: CPI
                    country: VN
                    month: 2024-02
                    value: 3.45
                    date: '2024-02-29'
                  - type: CPI
                    country: VN
                    month: 2024-03
                    value: 3.97
                    date: '2024-03-31'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
      x-codeSamples:
        - lang: bash
          label: cURL
          source: |
            curl -H "X-FH-APIKEY: $FINHAY_API_KEY" \
              "https://open-api.fhsc.com.vn/market/financial-data/macro?type=CPI&country=VN&period=ONE_YEAR"
components:
  schemas:
    MacroType:
      type: string
      description: |
        Mã chỉ số kinh tế vĩ mô.

        | Giá trị | Ý nghĩa |
        |---------|---------|
        | `IIP` | Chỉ số sản xuất công nghiệp |
        | `CPI` | Chỉ số giá tiêu dùng |
        | `PMI` | Chỉ số quản lý mua hàng |
        | `PCE` | Chi tiêu tiêu dùng cá nhân (Mỹ) |
        | `CORE_PCE` | PCE lõi (Mỹ) |
        | `NFP` | Bảng lương phi nông nghiệp (Mỹ) |
        | `GOODS_RETAIL` | Doanh thu bán lẻ — hàng hoá |
        | `SERVICE_RETAIL` | Doanh thu bán lẻ — dịch vụ |
        | `TOTAL_EXPORT` | Tổng xuất khẩu |
        | `FDI_EXPORT` | Xuất khẩu FDI |
        | `DOMESTIC_EXPORT` | Xuất khẩu nội địa |
        | `FED_FUNDS_RATE` | Lãi suất Fed Funds (Mỹ) |
        | `INTERBANK_RATE` | Lãi suất liên ngân hàng |
        | `GOVERNMENT_10Y_BOND_YIELD` | Lợi suất trái phiếu chính phủ 10 năm |
        | `UNEMPLOYMENT_RATE` | Tỷ lệ thất nghiệp |
      enum:
        - IIP
        - CPI
        - PMI
        - PCE
        - CORE_PCE
        - NFP
        - GOODS_RETAIL
        - SERVICE_RETAIL
        - TOTAL_EXPORT
        - FDI_EXPORT
        - DOMESTIC_EXPORT
        - FED_FUNDS_RATE
        - INTERBANK_RATE
        - GOVERNMENT_10Y_BOND_YIELD
        - UNEMPLOYMENT_RATE
      x-enum-varnames:
        - IIP
        - CPI
        - PMI
        - PCE
        - CORE_PCE
        - NFP
        - GOODS_RETAIL
        - SERVICE_RETAIL
        - TOTAL_EXPORT
        - FDI_EXPORT
        - DOMESTIC_EXPORT
        - FED_FUNDS_RATE
        - INTERBANK_RATE
        - GOVERNMENT_10Y_BOND_YIELD
        - UNEMPLOYMENT_RATE
    Country:
      type: string
      description: |
        Mã quốc gia cho dữ liệu vĩ mô.

        | Giá trị | Ý nghĩa |
        |---------|---------|
        | `VN` | Việt Nam |
        | `US` | Mỹ |
      enum:
        - VN
        - US
      x-enum-varnames:
        - VN
        - US
    Period:
      type: string
      description: |
        Khoảng thời gian lọc dữ liệu vĩ mô.

        | Giá trị | Ý nghĩa |
        |---------|---------|
        | `ONE_MONTH` | 1 tháng gần nhất |
        | `ONE_YEAR` | 1 năm gần nhất |
        | `YTD` | Từ đầu năm đến nay |
      enum:
        - ONE_MONTH
        - ONE_YEAR
        - YTD
      x-enum-varnames:
        - ONE_MONTH
        - ONE_YEAR
        - YTD
    MacroDataResponse:
      allOf:
        - $ref: '#/components/schemas/EnvelopeBase'
        - type: object
          required:
            - data
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/MacroData'
    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
    MacroData:
      type: object
      description: 1 điểm dữ liệu vĩ mô.
      properties:
        type:
          allOf:
            - $ref: '#/components/schemas/MacroType'
          description: Macro indicator code.
        country:
          allOf:
            - $ref: '#/components/schemas/Country'
          description: Country code.
        month:
          type: string
          description: Year-month in `YYYY-MM` format.
          example: 2024-03
        value:
          type: number
          description: Macro indicator value.
          example: 3.5
        date:
          type:
            - string
            - 'null'
          description: Exact date in `YYYY-MM-DD` format (if available in source data).
          example: '2024-03-15'
    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
  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.

````