OKX API Docs Explained: V5 Endpoints, API Key Setup, Signatures and Rate Limits (2026 Guide)
The short answer
The official OKX API documentation lives at okx.com/docs-v5 and covers the V5 API, which handles spot, margin, futures, perpetual swaps and options through one set of endpoints. To use it you need an API key, a secret key and a passphrase created in your OKX account; every private REST request is signed with HMAC SHA256 and sent to the production base URL https://openapi.okx.com with four OK-ACCESS headers. The docs also give WebSocket addresses, a demo trading environment, rate limits per endpoint and a Python SDK, so you can test a script end to end before it touches real funds.
Show less
What the OKX API docs cover
The V5 documentation is one long reference page organised into sections. The ones most people need first are:
Article table: scroll horizontally, or focus the table area and use the arrow keys.
| Section | What you find there |
|---|---|
| Overview | API key creation, permissions, IP binding, signing rules, base URLs |
| Trading Account | Balances, positions, leverage, account configuration, bills |
| Order Book Trading | Placing, amending and cancelling orders, algo orders, fills |
| Public Data and Market Data | Instruments, tickers, order books, candles, funding rates, server time |
| Funding Account | Deposits, withdrawals, transfers between accounts |
| Sub-account | Creating sub-accounts and their API keys |
| WebSocket channels | Public, private and business streams for live data |
| Error codes | Every numbered error with its HTTP status and meaning |
The page also links to a Python SDK, a market maker sample and step-by-step tutorials. Public market data endpoints work without any key; everything that touches your account needs authentication.
Step 1: Create an API key
Log in to OKX and open the API page in your account settings. When you create a key, OKX shows three things: the API key, the secret key and a passphrase that you choose. The docs are explicit that OKX stores only a salted hash of the passphrase and cannot recover it; if you lose it, you must create a new key.
Each key can have one or more of three permissions:
- Read: view balances, bills and order history.
- Trade: place and cancel orders, move funds between accounts and change settings.
- Withdraw: make withdrawals.
Start with Read only. Add Trade when your script is tested. Very few people ever need Withdraw on an automated key.
Two limits are worth knowing. Each account can create up to 50 API keys (error 59501), and each key can be bound to up to 20 IP addresses (error 59503), in IPv4, IPv6 or network-segment format.
Step 2: Bind an IP address
This is the rule that catches most new users. According to the docs, API keys that are not linked to an IP address and have Trade or Withdraw permission expire after 14 days of inactivity. Only calls that actually require authentication count as use. Demo trading keys do not expire.
Check regional eligibility and account terms
Open →If your bot runs on a server with a fixed IP, bind that IP when you create the key. It is safer and avoids a silent expiry over a quiet fortnight. Our earlier OKX API key IP allowlist and expiry checklist goes deeper into this rule.
Step 3: Sign your requests
Every private REST request must carry four headers:
Article table: scroll horizontally, or focus the table area and use the arrow keys.
| Header | Value |
|---|---|
| OK-ACCESS-KEY | Your API key |
| OK-ACCESS-SIGN | The Base64-encoded signature |
| OK-ACCESS-TIMESTAMP | Request time in UTC, ISO 8601 with milliseconds, for example 2020-12-08T09:08:57.715Z |
| OK-ACCESS-PASSPHRASE | The passphrase you set when creating the key |
To build the signature, join timestamp + method + requestPath + body into one string, sign it with your secret key using HMAC SHA256, then Base64-encode the result. For a GET request the query string is part of the request path, and the body is empty. Request bodies must be valid JSON with the content type application/json.
The most common error is 50102. The server rejects any request whose timestamp differs from server time by more than 30 seconds, and the docs note that a local time zone offset is the usual cause. Always generate the timestamp in UTC, and if in doubt, read the server clock from GET /api/v5/public/time, which needs no key.
Step 4: Know the base URLs
The production addresses listed in the docs are:
- REST: https://openapi.okx.com
- Public WebSocket: wss://ws.okx.com/ws/v5/public
- Private WebSocket: wss://ws.okx.com/ws/v5/private
- Business WebSocket: wss://ws.okx.com/ws/v5/business
For demo trading, REST stays on the same host but you add the header x-simulated-trading: 1, and WebSocket traffic goes to wspap.okx.com instead of ws.okx.com. Demo trading needs its own API key, created under Trade, Demo Trading, Personal Center, Demo Trading API. Some functions, such as deposits and withdrawals, are not available in demo mode.
Step 5: Respect the rate limits
OKX publishes a limit for each endpoint. A few examples from the docs:
Article table: scroll horizontally, or focus the table area and use the arrow keys.
| Endpoint | Limit | Counted per |
|---|---|---|
| POST /api/v5/trade/order (place order) | 60 requests per 2 seconds | User ID + instrument ID |
| GET /api/v5/market/tickers | 20 requests per 2 seconds | IP |
| GET /api/v5/account/instruments | 20 requests per 2 seconds | User ID + instrument type |
When you go over a limit the API returns error 50011. At the exchange level, an account can have at most 4,000 pending orders and 500 per trading symbol.
For WebSocket, OKX closes a connection if no data has been pushed for 30 seconds. The docs recommend a simple keep-alive: start a timer shorter than 30 seconds after each message, send the string "ping" if nothing arrives, and expect "pong" back. Each sub-account can hold up to 30 connections per private channel such as orders, account and positions, and each connection is limited to 480 subscribe, unsubscribe or login requests per hour.
A first test you can run
Before writing any trading logic, run two calls. First, GET /api/v5/public/time with no key: if you get a timestamp back, your network path to OKX works. Second, GET /api/v5/account/balance with a Read-only key: if it returns your balances, your signing code, timestamp and passphrase are all correct. Only then add order placement, and try it on demo trading first.
How to act on this
If you do not have an OKX account yet, you can open one with code nexu888 through our OKX page, then create a Read-only key and follow the steps above. The OKX exchange profile also lists the current spot and perpetual fees, which matter once your script starts trading, and our rates page compares them with other venues.
Quick answers
Where are the official OKX API docs? At okx.com/docs-v5, with English and Chinese versions. They cover REST, WebSocket, error codes and the Python SDK.
What is the OKX API base URL in 2026? The docs list https://openapi.okx.com for REST and wss://ws.okx.com/ws/v5/ for the public, private and business WebSocket channels.
Why does my OKX API key stop working? Keys with Trade or Withdraw permission and no bound IP expire after 14 days without authenticated use. Bind an IP to avoid this.
What does OKX error 50102 mean? Your request timestamp is more than 30 seconds away from server time. Use UTC and check GET /api/v5/public/time.
Can I test the OKX API without real money? Yes. Create a demo trading API key and add the header x-simulated-trading: 1 to REST requests.
How many API keys can I create on OKX? Up to 50 per account, each bound to at most 20 IP addresses.
Topic hubs & tools:Exchange API & market data controls
Check regional eligibility and account terms
Open →Sources
02- OKX API v5 documentation · okx.com
- GET /api/v5/public/time (live check) · openapi.okx.com