Every response from the Bybit REST API includes aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/bybit-api/llms.txt
Use this file to discover all available pages before exploring further.
retCode field. A value of 0 means the request succeeded. Any other value indicates an API-level error, with additional detail in the retMsg field. Network-level failures and HTTP errors (non-2xx status codes) are surfaced as rejected promises so you can handle both layers cleanly with try/catch.
REST Error Handling Pattern
The SDK wraps axios and normalises errors. By default, a successful HTTP response (status 200) with a non-zeroretCode is not thrown automatically — it is returned as a resolved value. This lets you inspect retCode on your own terms.
Automatic Exception Throwing
The API_ERROR_CODE Enum
The SDK exports API_ERROR_CODE, a typed constant map of known Bybit error codes. Using these constants prevents hard-coded magic numbers in your error handlers and enables IDE autocomplete.
Key Error Codes
| Constant | Value | Meaning |
|---|---|---|
SUCCESS | 0 | Request succeeded |
PARAMS_MISSING_OR_WRONG | 10001 | Bad request — wrong or missing parameter values; also reused for several unchanged-state errors |
INVALID_API_KEY_OR_PERMISSIONS | 10003 | API key is invalid or lacks required permissions |
SIGNATURE_NOT_VALID | 10004 | Request signature could not be verified |
INCORRECT_API_KEY_PERMISSIONS | 10005 | API key exists but does not have the required permission scope |
INCORRECT_API_REQUEST_IP | 10010 | Request IP is not in the API key’s IP whitelist |
ACCOUNT_NOT_UNIFIED | 10020 | Account must be upgraded to Unified Margin to use this endpoint |
COMPLIANCE_RULES_TRIGGERED | 10024 | Compliance rules prevented this action |
UNKNOWN_ERROR | 12000 | Unspecified server-side error |
V5_ORDER_NOT_FOUND | 110001 | The specified order does not exist (V5 API) |
V5_INSUFFICIENT_BALANCE | 110007 | Insufficient balance for the requested operation (V5 API) |
V5_API_KEY_PERMISSION_DENIED | 10005 | API key permission denied (V5 API) |
V5_CROSS_ISOLATED_MARGIN_NOT_CHANGED | 110026 | Margin mode was not changed because it is already set to the requested value |
V5_LEVERAGE_NOT_CHANGED | 110043 | Leverage was not changed because it already matches the requested value |
QTY_EXCEEDS_MAX_LIMIT | 130006 | Order quantity exceeds the maximum allowed for this contract |
ORDER_COST_NOT_AVAILABLE | 130021 | Insufficient available order cost (linear) |
TRANSFER_ID_EXISTS | 131214 | A transfer with this ID already exists |
NOT_SUPPORTED_FOR_SUBACCOUNTS | 131003 | Operation is not supported for sub-accounts |
Some error codes (such as
10001) are reused by Bybit across multiple scenarios — for example, unchanged-state errors for TP/SL, risk ID, and auto-add-margin all map to 10001. Always check retMsg alongside retCode for a precise diagnosis.Typed Error Handling by Code
CombiningAPI_ERROR_CODE with a switch statement keeps error handling readable and exhaustive:
WebSocket Error Events
TheWebsocketClient emits an exception event whenever a connection-level or subscription-level error occurs. Always register a listener for this event to prevent unhandled error crashes.
Debugging Raw HTTP Requests
Set theBYBITTRACE environment variable to any truthy value to log the full HTTP response — including request URL, method, headers, and body — to the console for every API call. This is useful when diagnosing signature failures or unexpected parameter serialisation.
BYBITTRACE is intended for local debugging only. Do not enable it in production — it will print API keys, signatures, and potentially sensitive response data to stdout.Common Errors and Fixes
Signature Not Valid (10004)
The HMAC or RSA signature could not be verified. Common causes:
- Wrong API secret — double-check you are using the secret that matches your key
- System clock skew — enable
enable_time_sync: trueor setsyncTimeBeforePrivateRequests: true - Proxy latency pushing timestamps outside the
recv_window— increaserecv_windowto10000or more
IP Not Whitelisted (10010)
Your API key has an IP restriction and the request is coming from an unlisted address. Either add your IP in the Bybit API management panel, or create a key without IP restriction for dynamic-IP environments.
Incorrect Permissions (10003 / 10005)
The API key does not have the required permission scope for the endpoint. Check the key’s read/trade/transfer permissions on the Bybit API management page and ensure they match what the endpoint requires.
Recv Window Too Small
The timestamp on the request arrived outside the acceptable window on the server. Increase
recv_window (e.g. 10000 ms) and consider enabling time synchronisation.Account Not Unified (10020)
The endpoint requires a Unified Margin or Unified Trading account. Upgrade your account in the Bybit dashboard before calling V5 endpoints that require unified margin.
Configuration
Set recv window, throwExceptions, and other client options
Logging
Enable trace logging and HTTP request debugging