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

# Heartbeat và Subscription

> Mô tả cơ chế ping pong, heartbeat và danh sách subscription của WebSocket FastConnect.

## Heartbeat

Server gửi heartbeat định kỳ để xác nhận client còn online. Client phải phản hồi đúng định dạng để session không bị đóng.

## Channel sử dụng

```text theme={null}
HEARTBEAT
```

## Ping từ server

```json theme={null}
{
  "method": "PING",
  "channel": "HEARTBEAT",
  "time": "dd-mm-yyyy hh-mm-ss"
}
```

## Pong từ client

```json theme={null}
{
  "method": "PONG",
  "channel": "HEARTBEAT",
  "time": "dd-mm-yyyy hh-mm-ss"
}
```

## LIST\_SUBSCRIPTION

Request:

```json theme={null}
{
  "method": "LIST_SUBSCRIPTION"
}
```

Response mẫu (tóm tắt scope):

```json theme={null}
{
  "trading": "order.*;portfolio.123456",
  "data": "trade.*;quote.*;room.*"
}
```

## Subscribe topic

```json theme={null}
{
  "method": "SUBSCRIBE",
  "channel": "DATA|TRADING",
  "topics": ["trade.SSI@tick", "quote.SSI@tick", "order.0901351"]
}
```

## Unsubscribe topic

```json theme={null}
{
  "method": "UNSUBSCRIBE",
  "channel": "DATA|TRADING",
  "topics": ["trade.SSI@tick", "order.0901351"]
}
```

## Liệt kê subscription hiện tại

```json theme={null}
{
  "method": "LIST_SUBSCRIPTION"
}
```

## Topic convention

* `order.<accountNo>`
* `portfolio.<accountNo>`
* `trade.<symbol>@tick|1m|3m`
* `quote.<symbol>@tick`
* `room.<symbol|*>`
* `put.<symbol|*>`
* `oddlot.<symbol>`
* `market.<group|exchange>`


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