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

# Lịch sử giá crypto

> Lịch sử giá OHLCV của 1 crypto — chuỗi nến `{t, o, h, l, c, v}`. **Chỉ hỗ trợ `resolution=1D`**. `from`/`to` là Unix timestamp tính bằng **giây**.



## OpenAPI

````yaml /openapi.yaml get /market/quotes/cryptos/{symbol}/history
openapi: 3.1.0
info:
  title: Finhay Securities Open API
  version: 0.2.0-preview.3
  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: Bảng giá thị trường
    description: >-
      Giá realtime, lịch sử và sổ lệnh thống nhất cho stocks / indices / forex /
      crypto / hàng hoá / quỹ mở / trái phiếu / ETF.
  - 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, …), lãi suất tiền gửi ngân hàng
      và lịch sự kiện kinh tế.
  - 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/quotes/cryptos/{symbol}/history:
    get:
      tags:
        - Bảng giá thị trường
      summary: Lịch sử giá crypto
      description: >-
        Lịch sử giá OHLCV của 1 crypto — chuỗi nến `{t, o, h, l, c, v}`. **Chỉ
        hỗ trợ `resolution=1D`**. `from`/`to` là Unix timestamp tính bằng
        **giây**.
      operationId: quotesGetCryptoHistory
      parameters:
        - name: symbol
          in: path
          required: true
          description: 'Mã crypto (ticker). VD: BTC, ETH, SOL.'
          schema:
            type: string
            example: BTC
        - name: resolution
          in: query
          required: false
          description: Chỉ hỗ trợ `1D` (mặc định).
          schema:
            $ref: '#/components/schemas/ResolutionDaily'
        - name: from
          in: query
          required: true
          description: Thời điểm bắt đầu, Unix timestamp tính bằng **giây**.
          schema:
            type: integer
            minimum: 0
            example: 1717200000
        - name: to
          in: query
          required: true
          description: Thời điểm kết thúc, Unix timestamp tính bằng **giây**.
          schema:
            type: integer
            minimum: 0
            example: 1717545600
      responses:
        '200':
          description: '`data.series` là mảng nến `{t, o, h, l, c, v}`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QuoteOhlcvHistoryResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '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/quotes/cryptos/BTC/history?resolution=1D&from=1717200000&to=1717545600"
components:
  schemas:
    ResolutionDaily:
      type: string
      description: >-
        Độ phân giải nến — các endpoint này **chỉ hỗ trợ `1D`**; truyền giá trị
        khác trả `400 INVALID_PARAMETER`.
      default: 1D
      enum:
        - 1D
    QuoteOhlcvHistoryResponse:
      allOf:
        - $ref: '#/components/schemas/EnvelopeBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/QuoteOhlcvSeries'
    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
    QuoteOhlcvSeries:
      type: object
      description: Chuỗi giá OHLCV theo thời gian.
      required:
        - symbol
        - series
      properties:
        symbol:
          type: string
          description: Mã định danh (canonical, viết hoa).
          example: VNM
        currency:
          type: string
          description: Đơn vị tiền tệ (bỏ qua với chỉ số).
          example: USD
        resolution:
          type: string
          description: Độ phân giải nến.
          example: 1D
        series:
          type: array
          items:
            $ref: '#/components/schemas/QuoteOhlcvBar'
    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
    QuoteOhlcvBar:
      type: object
      description: >-
        1 cây nến OHLCV. Với trái phiếu Chính phủ, nến chỉ có `{t, yield}` — `c`
        là `null`.
      required:
        - t
      properties:
        t:
          type: integer
          description: Unix timestamp (giây) mốc bắt đầu nến.
          example: 1717200000
        o:
          type:
            - number
            - 'null'
          description: Giá mở cửa. `null` với chuỗi close-only.
          example: 192.9
        h:
          type:
            - number
            - 'null'
          description: Giá cao nhất. `null` với chuỗi close-only.
          example: 194.35
        l:
          type:
            - number
            - 'null'
          description: Giá thấp nhất. `null` với chuỗi close-only.
          example: 191.1
        c:
          type:
            - number
            - 'null'
          description: Giá đóng cửa. `null` với nến yield-only (trái phiếu Chính phủ).
          example: 193.42
        v:
          type:
            - number
            - 'null'
          description: Khối lượng. `null` với chuỗi close-only.
          example: 51824100
        yield:
          type:
            - number
            - 'null'
          description: >-
            Lợi suất (%). Chỉ xuất hiện với lịch sử trái phiếu Chính phủ; các
            nến khác không có trường này.
          example: 3.85
  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
    NotFound:
      description: >-
        Tài nguyên không tồn tại — `error_code` mô tả cụ thể loại tài nguyên
        không tìm thấy.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
          example:
            error_code: '404'
            message: Not found
    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.

````