Error Codes
Overview
Every OKX v5 REST response — success or failure — uses the same JSON envelope:
code— a string status code."0"means the request succeeded; any other value is an error.msg— a human-readable explanation. Empty on success, populated on failure.data— an array of result objects.
Compare code as a string ("0"), not the integer 0. The msg / sMsg text is the authoritative, up-to-date explanation for any code — the tables below summarize the documented meaning, but always surface the returned message to callers.
Code "0" is the only success value. On batch endpoints the top-level code can be "0" while individual items still fail, so treat a top-level "0" as “the request was accepted”, not “every item succeeded”. Always inspect per-item sCode as well.
Per-item codes on batch endpoints
Batch endpoints — POST /api/v5/trade/batch-orders, POST /api/v5/trade/cancel-batch-orders, POST /api/v5/trade/amend-batch-orders, and others — can partially succeed. Each element of data carries its own status:
sCode— the status code for that individual item ("0"= that item succeeded).sMsg— the message for that individual item.
The top-level code is "1" (“Operation failed”) when any item fails, and "2" (“Bulk operation partially succeeded”) when some succeed and some fail. Read both levels.
Public / General (50000–50999)
General request, routing, and system-level errors that apply across all endpoints.
Rate limiting (50011, 50013, 50061)
Rate-limit responses arrive with HTTP 429. Back off using exponential delay, batch where possible, and prefer WebSocket streams over REST polling.
See Rate limits for per-endpoint budgets and the sub-account order-count limits.
API authentication & keys (50100–50119)
Authentication failures almost always trace back to the signature or the request headers. See REST authentication for how OK-ACCESS-SIGN is computed.
50113 (invalid signature) and 50102 (expired timestamp) are the two most common auth failures. 50113 means the pre-hash string, HTTP method, path, query string, or body you signed does not match what was sent — re-serialize the body exactly once and sign the raw string. 50102 means clock drift; run NTP so your timestamp is within 30 seconds of OKX server time.
Account (50000-range trade / 51000–51999 subset)
Errors returned when placing, amending, or cancelling orders — covering parameter validation, balance, leverage, and position-mode conflicts. These appear at the top level for single orders and as sCode on batch items.
Trade / order (51100–51999 subset)
Order-state and order-management errors — amend, cancel, close, and margin/leverage conflicts.
Funding & withdrawal (58000–58999 subset)
Errors from the asset/funding endpoints: transfers, deposits, and withdrawals.
WebSocket (60000–60999)
Returned on the WebSocket channel as event: "error" frames. Login, subscription, and channel errors dominate this range. See WebSocket for connection and subscription details.
The WebSocket also returns transport-level close events. 4004 (no data received in 30s — send a ping), 4005 (buffer full), and 4008 (too many requests) are connection-level codes, distinct from the application-level 600xx error frames above. Send a ping at least every 30 seconds to keep the socket alive.
Handling pattern
Handle top-level and per-item codes uniformly:
For a conceptual walkthrough of the envelope and a troubleshooting checklist, see Error handling.

