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:

{
"jsonrpc": "2.0",
"method": "auth",
"params": {
"bearer": "YOUR_JWT_TOKEN"
},
"id": 0
}

Authentication Parameters

ParameterTypeDescriptionRequired
bearerstringJWT tokenYes

Authentication Response

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

{
"jsonrpc": "2.0",
"result": {
"node_id": "a1b2c3d4e5f6g7h8"
},
"usIn": 1682556415569005368,
"usDiff": 1291796,
"id": 0
}

Example: Authenticating a WebSocket Connection

The auth request and its response are JSON-RPC text frames in both encodings. The SDK sends them for you and negotiates SBE for any public channels the same connection subscribes to:

import asyncio
from paradex_py import Paradex
from paradex_py.api.ws_client import ParadexWebsocketClient
from paradex_py.environment import TESTNET
async def main():
paradex = Paradex(
env=TESTNET,
l1_address="0xYOUR_L1_ADDRESS",
l2_private_key="0xYOUR_L2_PRIVATE_KEY",
)
ws_client = ParadexWebsocketClient(env=TESTNET, sbe_enabled=True)
ws_client.init_account(paradex.account)
await ws_client.connect()
print("Authenticated")
asyncio.run(main())

If you implement the handshake yourself, send the auth request shown above as a text frame, and remember to append the SBE parameters to the connection URL so public channels are not silently delivered as JSON.

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.