Connecting

EnvironmentURL
Productionwss://ws.templedigitalgroup.com/v1/stream
Developmentwss://ws-dev.templedigitalgroup.com/v1/stream

Pass your API key in the X-API-Key header when connecting. Authentication happens automatically on the WebSocket handshake.

X-API-Key: your-api-key-here

Connections without a valid API key are rejected with HTTP 401.

API key rules

API keys follow the same rules as the REST API. A valid key is still refused when:

  • the account is locked or suspended (ACCOUNT_LOCKED)
  • the account is restricted to withdraw-only access (ACCOUNT_WITHDRAW_ONLY)
  • the account has an IP allowlist and your IP is not on it (IP_ALLOWLIST_DENIED)
  • trading is halted for maintenance (MAINTENANCE_MODE)
  • the key lacks the read scope (INSUFFICIENT_SCOPE). A key with no scopes stored has read and write; write includes read.

These apply to streaming as well as to orders: if you use an IP allowlist, every system that connects must be on it. A refusal at connect is remembered for 5 seconds per key and IP address, so a retry within that time gets the same answer, even if the account was just unlocked.

Placing and cancelling orders also needs the write scope. See Placing and cancelling orders.

Handshake errors

Rejections during the handshake are plain-text HTTP responses:

StatusBodyWhat to do
401Authentication requiredCheck your API key. Repeated 401s lead to 429.
403<CODE>: <message>, for example ACCOUNT_LOCKED: Account is locked or suspendedThe key is valid but not allowed (see API key rules). Does not count as a failed attempt.
403ForbiddenAn Origin header that is not one of ours, sent by a browser page on another site. Clients that send no Origin (bots, servers) are not affected. Counts as a failed attempt.
503MAINTENANCE_MODE: ...Trading is halted. Retry after the Retry-After seconds.
429Too many connections from this IPClose connections you do not need, then retry.
429Too many failed connection attemptsWait for the Retry-After seconds before trying again.

After 5 failed attempts from one IP address, only one attempt is allowed every 30 seconds. See Rate limits.

Credential expiry and revocation

Open connections are re-checked against their credential about once a minute, and the API key rules above are applied again each time. When the credential is no longer valid or allowed (API key revoked or regenerated, account locked, and so on), the server sends an auth_expired message with a reason, then closes the connection with close code 4008 and the reason as close text. Reconnect with a valid credential. Private user events stop at that point.

{"type":"auth_expired","reason":"api_key_revoked","message":"API key revoked or regenerated, please re-authenticate"}
reasonMeaning
api_key_revokedThe API key was revoked or regenerated.
credential_check_failedThe credential could not be verified for three consecutive checks.
account_lockedThe account was locked or suspended.
withdraw_onlyThe account was restricted to withdraw-only access.
ip_allowlistThe account's IP allowlist no longer includes you.
maintenance_modeTrading was halted.
insufficient_scopeThe key no longer has the scope the connection needs.

Connections authenticated with a web-app login (JWT) can also get token_expired and session_revoked.

Re-authenticating on an open connection

This is usually not needed, because the X-API-Key header authenticates the connection. To re-authenticate an existing connection, send:

{"type":"auth","api_key":"your-api-key-here"}

If the key is valid but not allowed, the server sends an error with the refusal code (for example ACCOUNT_LOCKED), then closes the connection with close code 1008.


Did this page help you?