Cách lấy API Key / Access Token

Tạo, quản lý, và bảo mật API credentials

Tạo API Key

Bước 1: Đăng nhập Developer Portal

Truy cập https://developers.ssi.com.vn và đăng nhập bằng tài khoản SSI.

Bước 2: Tạo API Key mới

Vào Bảng điều khiển -> Quản lý API Key -> Tạo Key mới

Đặt tên cho API Key (ví dụ: "Trading Bot Production")

Click Tạo -> Lưu ngay API Key và API Secret

Quan trọng: API Secret chỉ hiển thị MỘT LẦN. Nếu mất, cần vào chi tiết API Key để xem lại.


Xác thực với API Key

FastConnect sử dụng cơ chế Bearer token. Flow xác thực:

1. Lấy Access Token

Gọi /api/v3/auth/token với API Key và API Secret:

curl -X POST "https://api.ssi.com.vn/api/v3/auth/token" \
  -H "Content-Type: application/json" \
  -d '{
    "apiKey": "your_api_key",
    "apiSecret": "your_api_secret"
  }'

Response:

{
  "tokenType": "Bearer",
  "accessToken": "eyJhbGciOiJIUzI1NiIs...",
  "refreshToken": "dGhpcyBpcyBhIHJlZnJl...",
  "expiresAt": 1779806203,
  "refreshExpiresAt": 1779892603
}

2. Sử dụng Access Token

Truyền token trong header Authorization cho tất cả API calls:

curl -X GET "https://api.ssi.com.vn/api/v3/data/securitiesByBoard?board=HOSE" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."

3. Làm mới Token

Khi access token hết hạn, dùng refresh token:

curl -X POST "https://api.ssi.com.vn/api/v3/auth/refresh" \
  -H "Content-Type: application/json" \
  -d '{
    "refreshToken": "dGhpcyBpcyBhIHJlZnJl..."
  }'

4. Token có quyền giao dịch

Để đặt/sửa/hủy lệnh, cần token có OTP:

# Bước 1: Yêu cầu OTP
curl -X POST "https://api.ssi.com.vn/api/v3/auth/requestOtp" \
  -H "Content-Type: application/json" \
  -d '{
    "apiKey": "your_api_key",
    "apiSecret": "your_api_secret"
  }'

# Bước 2: Lấy token kèm OTP
curl -X POST "https://api.ssi.com.vn/api/v3/auth/token" \
  -H "Content-Type: application/json" \
  -d '{
    "apiKey": "your_api_key",
    "apiSecret": "your_api_secret",
    "otp": "123456"
  }'

Quản lý API Key

Xem chi tiết Key

Đăng nhập Developer Portal -> Bảng điều khiển -> Quản lý API Key -> chọn key cần xem -> Chi tiết.

Rotate (xoay vòng) Key

Tạo API Key mới trên Developer Portal
Cập nhật key mới vào ứng dụng
Test kỹ với key mới
Xóa key cũ

Xóa Key

Xóa ngay nếu:

  • Key bị lộ ra ngoài
  • Không còn sử dụng
  • Cần thay thế bằng key mới

Best Practices bảo mật

NÊN

  • Lưu key trong environment variables hoặc secret manager
  • Sử dụng HTTPS cho mọi request
  • Rotate key định kỳ
  • Tạo key riêng cho từng ứng dụng
  • Monitor API usage để phát hiện bất thường

KHÔNG NÊN

  • Commit key vào Git/GitHub
  • Hardcode key trong source code
  • Share key qua email/chat
  • Dùng key Production cho testing
  • Dùng chung key giữa nhiều ứng dụng

Bước tiếp theo

Đã có API Key? Tiếp tục với API Call đầu tiên!

Trên trang này