Websocket Authentication

Login and Private Channel Authentication

Private channels require a login message containing the API key, passphrase, timestamp, and HMAC signature. After a successful login response, the client can subscribe to private account-level channels.

Authentication flow:

  1. Establish connection
  2. Send login request
  3. Wait for response
  4. Subscribe to private channels

Login Request

{
  "op": "login",
  "args": [
    {
      "apiKey": "YOUR_API_KEY",
      "passphrase": "YOUR_PASSPHRASE",
      "timestamp": "1766124407915",
      "sign": "BASE64_ENCODED_SIGNATURE"
    }
  ]
}

Request Parameters

ParameterTypeDescription
apiKeyStringAPI Key
passphraseStringAPI passphrase
timestampStringCurrent timestamp, in milliseconds
signStringSignature, Base64 encoded

Signature Generation

Signature string: timestamp + "GET" + "/user/verify" + ""

  1. Use secretKey to perform HMAC SHA256 encryption on the signature string.
  2. Base64 encode the result.

JavaScript Example

const crypto = require('crypto');function generateSign(timestamp, secretKey) {const message = timestamp + 'GET' + '/user/verify' + '';return crypto.createHmac('sha256', secretKey).update(message).digest('base64');}

Python Example

import hmac, base64

def generate_sign(timestamp, secret_key):
    message = timestamp + 'GET' + '/user/verify' + ''
    signature = hmac.new(bytes(secret_key, 'utf8'), bytes(message, 'utf-8'), digestmod='sha256').digest()return base64.b64encode(signature).decode()

Login Response

{"event": "login","code": "0"}

Error Codes

Error CodeDescription
30001Channel does not exist
30002Invalid request
30003Invalid op
30004User login required
30005Login failed
30011Invalid ACCESS_KEY
30012Invalid ACCESS_PASSPHRASE
30013Invalid ACCESS_TIMESTAMP
30014Request timestamp expired
30015Invalid signature
30016Parameter error