Authentication

To access private channels in the Paradex WebSocket API, you must authenticate your connection. This page explains how to authenticate your WebSocket connection using a JWT token.

Authentication Process

Authentication is required to subscribe to private channels. The JWT (bearer) token is obtained from the POST /auth endpoint of the REST API.

Important: After the initial authentication, you do not need to re-authenticate your WebSocket connection for the lifetime of the connection.

Authentication Request

To authenticate your WebSocket connection, send an authentication message with the following format:

1{
2 "jsonrpc": "2.0",
3 "method": "auth",
4 "params": {
5 "bearer": "YOUR_JWT_TOKEN"
6 },
7 "id": 0
8}

Authentication Parameters

ParameterTypeDescriptionRequired
bearerstringJWT tokenYes

Authentication Response

Upon successful authentication, you will receive a response similar to:

1{
2 "jsonrpc": "2.0",
3 "result": {},
4 "usIn": 1682556415569005368,
5 "usDiff": 1291796,
6 "id": 0
7}

Example: Authenticating a WebSocket Connection

Here’s a complete example of how to authenticate a WebSocket connection using Python:

1import websocket
2import json
3
4websocket_url = "wss://ws.api.testnet.paradex.trade/v1"
5
6# Define the message to send
7message = {
8 "jsonrpc": "2.0",
9 "method": "auth",
10 "params": {
11 "bearer": "JWcgwMbK0bx1uFFef0Lri35ZDwypmCG0isuBv"
12 },
13 "id": 0
14}
15
16# Define a callback to check connection success
17def on_open(ws):
18 # Send the message
19 ws.send(json.dumps(message))
20
21# Define a callback to handle the response
22def on_message(ws, message):
23 response = json.loads(message)
24 print(response)
25
26# Connect to the WebSocket server
27ws = websocket.WebSocketApp(websocket_url, on_open=on_open, on_message=on_message)
28
29# Wait for a response
30ws.run_forever()

Authentication Errors

If authentication fails, you will receive an error response. Common authentication errors include:

Error CodeDescription
40110Malformed Bearer Token
40111Invalid Bearer Token
40112Geo IP blocked

For more information on error handling, see the Error Handling section.