Skip to main content
Authenticate to the Advanced Trade WebSocket with a JWT from a CDP API key. Public channels do not need one.

Sending Messages with API Keys

Making Requests

Use the code samples below to generate/export a JSON Web Token (JWT) and make an authenticated request.
WebSocket JWTs (vs those for REST API) are not built with a request method or request path.

Generating a JWT

Regardless of which code snippet you use, follow these steps:
  1. Replace key name and key secret with your key name and private key. key secret is a multi-line key and newlines must be preserved to properly parse the key. Do this on one line with \n escaped newlines, or with a multi-line string.
  2. Run the generation script that prints the command export JWT=....
  3. Run the generated command to save your JWT.
Your JWT expires after 2 minutes, after which all requests are unauthenticated.

Code samples

The easiest way to generate a JWT is to use the built-in functions in our Python SDK as described below. Otherwise, use the code samples below to generate/export a JWT and make an authenticated request.
  1. Install the SDK.
  2. In the console, run: python main.py (or whatever your file name is).
  3. Set the JWT to that output, or export the JWT to the environment with export JWT=$(python main.py).

Sending Messages without API Keys

Subscribing

Unsubscribing

Sequence numbers and how to handle gaps are on the WebSocket Overview. See Also: