> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tickdb.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 港股全量行情

> 獲取港股市場當前全量行情快照。

## 套餐權限

| 套餐 | 可用 |
| - | :-: |
| 免費版 | ❌ |
| 基礎版 | ❌ |
| 專業版 | ❌ |
| A 股全量 | ❌ |
| 港股全量 | ✅ |
| 美股全量 | ❌ |
| 企業版 | ✅ |

## 注意事項

* 無需傳入請求參數，一次返回當前可用的全部行情記錄，不分頁。
* 返回范圍以港股為主，并包含當前可用的港股市場指數，可通過 `type` 判斷產品類型。
* 響應數據量較大，客戶端必須啟用 HTTP 響應壓縮，并聲明支持 `gzip`、`br` 或 `zstd` 中的至少一種格式；未啟用壓縮時可能返回 `406`。
* `timestamp` 為每條行情的數據時間，使用 Unix 毫秒時間戳。
* `open`、`prev_close` 在對應數據不可用時不會返回。

## 支持的市場

| 市場 | 示例 |
| - | - |
| 港股 | 700.HK, 9988.HK, 3690.HK |

## 請求參數

無。

## 請求示例

```bash theme={null}
curl --compressed \
  -H "X-API-Key: YOUR_API_KEY" \
  "https://api.tickdb.ai/v1/market/ticker/hk-stock"
```

## 代碼示例

以下 Node.js 22+ 示例聲明支持三種壓縮格式，并根據響應中的 `Content-Encoding` 自動選擇解壓方式。

```javascript theme={null}
const https = require("node:https");
const zlib = require("node:zlib");

const decompressors = {
  gzip: zlib.gunzipSync,
  br: zlib.brotliDecompressSync,
  zstd: zlib.zstdDecompressSync,
};

const request = https.get("https://api.tickdb.ai/v1/market/ticker/hk-stock", {
  headers: {
    "X-API-Key": process.env.TICKDB_API_KEY,
    "Accept-Encoding": "gzip, br, zstd",
  },
}, (response) => {
  const chunks = [];
  response.on("data", (chunk) => chunks.push(chunk));
  response.on("end", () => {
    if (response.statusCode !== 200) {
      throw new Error(`請求失敗：${response.statusCode}`);
    }

    const encoding = response.headers["content-encoding"];
    const decompress = decompressors[encoding];
    if (!decompress) {
      throw new Error(`不支持的壓縮格式：${encoding}`);
    }

    const body = decompress(Buffer.concat(chunks));
    const result = JSON.parse(body.toString("utf8"));
    console.log(`返回 ${result.data.length} 條行情`);
    console.log(result.data[0]);
  });
});

request.on("error", console.error);
```

## 返回字段說明

| 字段 | 說明 |
| - | - |
| code | 響應碼，`0` 表示成功。 |
| message | 響應消息。 |
| data | 港股市場全量行情數組。 |
| └─ symbol | 港股市場代碼，例如 `700`。 |
| └─ name | 產品名稱。 |
| └─ type | 產品類型：`stock` 股票類產品、`indices` 指數。 |
| └─ last\_price | 最新成交價。 |
| └─ open | 當日開盤價；數據不可用時不返回。 |
| └─ prev\_close | 上一交易日收盤價；數據不可用時不返回。 |
| └─ volume\_24h | 當日累計成交量。 |
| └─ quote\_volume\_24h | 當日累計成交額。 |
| └─ high\_24h | 當日最高價。 |
| └─ low\_24h | 當日最低價。 |
| └─ price\_change\_24h | 相對昨收的價格變化。 |
| └─ price\_change\_percent\_24h | 相對昨收的價格變化百分比。 |
| └─ timestamp | Unix 時間戳，單位為毫秒。 |


## OpenAPI

````yaml openapi.zh-Hant.yaml GET /v1/market/ticker/hk-stock
openapi: 3.1.0
info:
  title: TickDB API
  description: TickDB 統一即時行情數據 API，提供 REST 和 WebSocket 接入。
  version: 1.0.3
  contact:
    email: support@tickdb.ai
servers:
  - url: https://api.tickdb.ai
    description: 正式環境
security:
  - ApiKeyAuth: []
paths:
  /v1/market/ticker/hk-stock:
    get:
      summary: 港股全量行情
      description: 獲取港股市場當前全量行情快照。
      parameters:
        - $ref: '#/components/parameters/FullMarketCompressionHeader'
      responses:
        '200':
          description: 請求成功。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FullMarketTickerResponse'
        '406':
          description: 請求成功。
        '503':
          description: 請求成功。
components:
  parameters:
    FullMarketCompressionHeader:
      name: Accept-Encoding
      in: header
      required: true
      description: 全量行情回應必須啟用壓縮，支援 gzip、br 和 zstd，至少選擇一種；預設使用相容性較好的 gzip。
      schema:
        type: string
        enum:
          - gzip
          - br
          - zstd
        default: gzip
  schemas:
    FullMarketTickerResponse:
      type: object
      required:
        - code
        - message
        - data
      additionalProperties: false
      properties:
        code:
          type: integer
          example: 0
        message:
          type: string
          example: success
        data:
          type: array
          items:
            $ref: '#/components/schemas/FullMarketTicker'
    FullMarketTicker:
      type: object
      required:
        - symbol
        - last_price
        - timestamp
      additionalProperties: false
      properties:
        symbol:
          type: string
          description: 交易產品代碼。
        name:
          type: string
          description: 產品名稱。
        type:
          type: string
          enum:
            - stock
            - indices
          description: 產品類型：`stock` 股票類產品、`indices` 指數。
        category:
          type: string
          enum:
            - sh_stock
            - sz_stock
            - bj_stock
            - etf
            - cn_index
            - cn_bond
          description: A 股產品細分類別；僅 A 股全量行情返回。
        last_price:
          type: string
          description: 最新成交價。
        open:
          type: string
          description: 當日開盤價；數據不可用時不返回。
        prev_close:
          type: string
          description: 上一交易日收盤價；數據不可用時不返回。
        volume_24h:
          type: string
          description: 當日累計成交量。
        quote_volume_24h:
          type: string
          description: 當日累計成交額。
        high_24h:
          type: string
          description: 當日最高價。
        low_24h:
          type: string
          description: 當日最低價。
        price_change_24h:
          type: string
          description: 相對昨收的價格變化。
        price_change_percent_24h:
          type: string
          description: 相對昨收的價格變化百分比。
        timestamp:
          type: integer
          format: int64
          description: Unix 時間戳，單位為毫秒。
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key

````

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