Error Handling

The Paradex WebSocket API uses JSON-RPC 2.0 for communication, which includes standardized error handling. This page explains the error format and common error codes.

Error Message Format

When an error occurs, the WebSocket API returns an error message with the following format:

1{
2 "jsonrpc": "2.0",
3 "error": {
4 "code": -32601,
5 "message": "method does not exist"
6 },
7 "usIn": 1710522972729581,
8 "usOut": 1710522972729618,
9 "usDiff": 37,
10 "id": 4
11}

Error Object Properties

PropertyTypeDescriptionRequired
codenumberError codeYes
messagestringShort explanationYes
datastringExtra detailsNo

Error Codes

The Paradex WebSocket API uses standard JSON-RPC error codes as well as custom error codes.

Standard JSON-RPC Error Codes

Error codes from -32768 to -32000 are pre-defined errors per the JSON-RPC specification:

CodeDescription
-32700Parse error
-32600Invalid request
-32601Method not found
-32602Invalid parameters
-32603Internal error

Paradex-Specific Error Codes

Other errors are specific to the Paradex WebSocket API:

CodeDescription
100Method error
40110Malformed Bearer Token
40111Invalid Bearer Token
40112Geo IP blocked

Common Error Scenarios

Authentication Errors

Authentication errors occur when there are issues with the JWT token:

1{
2 "jsonrpc": "2.0",
3 "error": {
4 "code": 40111,
5 "message": "Invalid Bearer Token"
6 },
7 "usIn": 1710522972729581,
8 "usOut": 1710522972729618,
9 "usDiff": 37,
10 "id": 0
11}

Subscription Errors

Subscription errors occur when there are issues with channel subscriptions:

1{
2 "jsonrpc": "2.0",
3 "error": {
4 "code": -32602,
5 "message": "Invalid parameters"
6 },
7 "usIn": 1710522972729581,
8 "usOut": 1710522972729618,
9 "usDiff": 37,
10 "id": 1
11}

Method Errors

Method errors occur when an invalid method is called:

1{
2 "jsonrpc": "2.0",
3 "error": {
4 "code": -32601,
5 "message": "method does not exist"
6 },
7 "usIn": 1710522972729581,
8 "usOut": 1710522972729618,
9 "usDiff": 37,
10 "id": 4
11}

Best Practices for Error Handling

  1. Check Error Codes: Always check the error code to understand the type of error
  2. Log Errors: Log all errors for debugging purposes
  3. Implement Retry Logic: For transient errors, implement retry logic with exponential backoff
  4. Handle Authentication Errors: If you receive an authentication error, regenerate your JWT token and reconnect
  5. Validate Parameters: Ensure all parameters are valid before sending requests