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

# Kết nối WebSocket

> Thiết lập kết nối FastConnect WebSocket và quy tắc request tổng quát.

## Tổng quan

FastConnect WebSocket dùng để stream dữ liệu giao dịch và dữ liệu thị trường theo thời gian thực.

Trước khi kết nối, client cần lấy token từ API `getAccessToken`.

## Endpoint kết nối

```text theme={null}
wss://stream.ssi.com.vn
```

## Điều kiện sử dụng

* Access token còn hiệu lực.
* Client duy trì heartbeat trong suốt phiên kết nối.
* Sau khi reconnect, cần subscribe lại các topic cần theo dõi.

## Xác thực và kết nối

Tài liệu mô tả việc lấy token từ `client_id`, `api_key`, `api_secret` qua API auth. Sau đó dùng token để kết nối stream.

```json theme={null}
{
  "client_id": "666666",
  "api_key": "<api-key>",
  "api_secret": "<api-secret>",
  "access_token": "<access-token>"
}
```

## Cấu trúc request WebSocket tổng quát

Mỗi message gửi qua WebSocket đều theo cấu trúc chung:

```json theme={null}
{
  "method": "SUBSCRIBE|UNSUBSCRIBE|LIST_SUBSCRIPTION|PING|PONG",
  "channel": "TRADING|DATA|HEARTBEAT",
  "topics": ["trade.SSI@tick", "trade.SSI@1m", "room.*"]
}
```

## List subscription

Client có thể kiểm tra scope hiện tại bằng request:

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

Response trả về các quyền truy cập theo nhóm trading/data.

## Event type chính

* `connect`
* `heartbeat`
* `orderEvent`
* `orderMatchEvent`
* `clientPortfolioEvent`
* `fcoEvent` — sự kiện lệnh điều kiện (FCO)
* `trade`
* `quote`
* `room`
* `put`
* `oddlot`
* `market`


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