OKX API errors: fix 50101, 50102 and 50113

Diagnose environment, timestamp and signature failures in order. Check the exact path, query string and JSON bytes before recreating your API key.

Questions on this page

Start with the error code and request time. Keep credentials out of bug reports. If an order request timed out, look up its client order ID before submitting a replacement: the exchange may already have accepted it.

Use the error to choose the next check

ErrorFirst checkA useful confirmation
50101: environment mismatchDemo key paired with x-simulated-trading: 1A demo balance request succeeds
50102: expired timestampUTC clock, synchronization and request delayRegenerate both timestamp and signature after syncing
50113: invalid signatureSecret and the exact signed request bytesSign and send the same method, path and body

Do not remove the demo header as a random fix. Decide which environment you intend to use, then keep its key and request configuration together.

The clock can look right and still be wrong

A correct time-zone setting does not guarantee an accurate system clock. Compare the public /api/v5/public/time response with your clock, allowing for network round-trip time. Generate a fresh timestamp close to sending each request; a timestamp cached when the program started will expire. Changing it also requires a new signature.

Sign the request you actually send

For REST requests, concatenate the timestamp, uppercase method, request path and body. Apply HMAC-SHA256 with the Secret, then Base64-encode the result. GET query parameters belong in the signed path; a request without a body does not append the text null.

GET: /api/v5/account/balance?ccy=USDT
POST: /api/v5/trade/order

Serialize a JSON body once. Use that same string for signing and transmission. Signing one string and asking a client library to serialize a different object afterward can change spacing, field order or numeric strings.

A successful HTTP response is not a filled order

Check the top-level code, then the per-order sCode and sMsg. Order acceptance, resting, partial fill, fill and cancellation are separate states. After authentication works, size or account-mode errors require a different diagnosis; repeatedly replacing your API key will not fix them.

Share a useful, redacted bug report

Include the method, path, UTC timestamp, error code, SDK version and relevant order parameters. Remove keys, secrets, passphrases, signatures and balances. Never upload an entire environment file. For credential setup, return to the OKX API key guide.

OKX API FAQ
OKX official FAQ, captured 2026-10-16; current interface labels can vary. Open image at full size.
OKX referral offer Create an OKX account Check regional availability, complete verification, then start with a small deposit and withdrawal test. Get exclusive new-user welcome rewards and 20% off trading fees Open OKX