WebSocket API

query.orderBook

Lấy lịch sử sổ lệnh theo tài khoản và bộ lọc, có phân trang. Không yêu cầu chữ ký.

Scope bắt buộc: tradingws:orderBook:get.

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

bodyobjectrequired
idstringrequired
methodstringrequired
paramsobjectrequired
accountNostringrequired

Tài khoản giao dịch cần lấy lịch sử sổ lệnh.

fromstringrequired

Thời gian bắt đầu để lọc lịch sử sổ lệnh, định dạng `yyyy/MM/dd`.

tostringrequired

Thời gian kết thúc để lọc lịch sử sổ lệnh, định dạng `yyyy/MM/dd`. Phải >= `from`.

symbolstring | nulloptional

Mã chứng khoán cần lọc.

orderStatusstring | nulloptional

Trạng thái lệnh cần lọc. Tham khảo phụ lục Trạng thái lệnh & luồng trạng thái.

pageSizeintegeroptional

Số lượng bản ghi trên mỗi trang.

pageIndexintegeroptional

Chỉ số trang, bắt đầu từ 1.

timestampintegerrequired

Response Body

application/json

application/json

Sample Request

wscat -c wss://api.ssi.com.vn/ws/v3/trading -x '{
  "id": "req-0013",
  "method": "query.orderBook",
  "params": {
    "accountNo": "0901351",
    "from": "2026/09/01",
    "to": "2026/09/10",
    "pageIndex": 1,
    "pageSize": 10
  },
  "timestamp": 1755000012000
}'

Sample Response

{
  "id": "req-0013",
  "method": "query.orderBook",
  "status": 200,
  "result": {
    "accountNo": "0901351",
    "totalRecord": 1,
    "orderList": [
      {
        "clientRequestId": "req-0001",
        "orderId": "ORD123456",
        "symbol": "SSI",
        "side": "B",
        "orderType": "LO",
        "quantity": "1000",
        "price": "45.50",
        "filledQty": "1000",
        "cancelQty": "0",
        "avgPrice": "45.48",
        "inputTime": "2026/09/09 09:15:32",
        "modifiedTime": "2026/09/09 09:16:01",
        "orderStatus": "FF",
        "message": ""
      }
    ]
  },
  "rateLimit": {
    "limit": 100,
    "remaining": 92,
    "resetMs": 760
  }
}

query.ppmmrAccountWS

Lấy thông tin PP/MMR (Purchasing Power/Maintenance Margin Ratio) của tài khoản. Không yêu cầu chữ ký. Scope bắt buộc: `tradingws:ppmmrAccount:get`.

subscribe/unsubscribeWS

Đăng ký/hủy đăng ký nhận thông báo order/portfolio trên cùng kết nối — **bắt buộc** để nhận trạng thái lệnh thật sau khi `order.place`/`order.amend`/`order.cancel` đã phản hồi `PD` (xem mục "Đặt/sửa/hủy lệnh: xác nhận nhanh, kết quả đến sau" ở đầu tài liệu). Message này không cần chữ ký và không mang `id`. API này **chỉ hỗ trợ channel `TRADING`**, gồm 2 loại topic: - `order.{accountNo}` — thông báo khớp lệnh, khớp một phần. - `portfolio.{accountNo}` — thông báo thay đổi tài sản/danh mục, **chỉ áp dụng cho tài khoản phái sinh (đuôi 8)**. Cấu trúc dữ liệu thông báo giống với channel `TRADING` của FastConnect WebSocket API (dữ liệu thị trường) — xem chi tiết field tại [Sub/Unsub Trading Data](/docs/api-reference/subscribeUnsubscribeTradingData). **Lưu ý:** mỗi topic phải chỉ định `accountNo` cụ thể — **không hỗ trợ wildcard `*`**, và tài khoản đó phải thuộc quyền sở hữu của API Key đang dùng (không thể đăng ký nhận dữ liệu của tài khoản khách hàng khác). **Subscribe sample:** ```json { "method": "SUBSCRIBE", "channel": "TRADING", "topics": ["order.0901351", "portfolio.1231996"] } ``` **Ack:** ```json { "method": "SUBSCRIBE", "channel": "TRADING", "status": "ok", "message": "Subscribed to 2 topic(s)" } ``` Nếu `status: "error"`, `message` mô tả lý do (topic sai cú pháp, thiếu quyền, hoặc tài khoản không thuộc quyền sở hữu). **Ví dụ thông báo** (`order.{accountNo}`): ```json { "channel": "TRADING", "topic": "order.0901351", "data": { "eventType": "orderEvent", "clientRequestId": "req-0001", "orderId": "ORD123456", "orderStatus": "FF", "...": "..." } } ```