When you search "crypto exchange API," you are usually after one of three things: hooking a trading bot into a real market, pulling live price and order-book data into your own app, or programmatically placing and managing orders without touching a web UI. The answer in every case is an exchange's REST and WebSocket API. This guide walks through what a modern crypto exchange API actually offers, then grounds the details in OKX's V5 API — endpoints, authentication, rate limits, sandbox, and the full fee tier schedule — so you can decide whether it fits your automation workflow.
👉 Open an OKX account and start using the API
A crypto exchange API is the programmatic interface between your code and the exchange's matching engine, account system, and market data feed. It exposes two complementary transports.
REST endpoints are request-response style. You call a URL, get a JSON reply, and the connection closes. They fit tasks where you only need the current state: fetch balance, place an order, query recent trades, list instruments. WebSocket is the better fit when you need a continuous stream — order book updates, tickers, private order fills, position changes — because the server pushes data over a single long-lived TCP connection instead of forcing you to poll.
A complete exchange API typically covers four functional areas: market data (public tickers, candles, order book depth, funding rates), account data (balances, positions, bills), trading (place, amend, cancel orders; batch operations; algo orders), and value-added services (Earn products, sub-account management, historical data downloads). The richer the coverage, the less you have to glue together from third-party sources.
OKX exposes a unified V5 API across spot, margin, perpetual and expiry futures, options, and spreads. The same key set works across instruments, which simplifies code that trades multiple products.
Production endpoints:
REST base URL: https://openapi.okx.com
Public WebSocket: wss://ws.okx.com:8443/ws/v5/public
Private WebSocket: wss://ws.okx.com:8443/ws/v5/private
Business WebSocket: wss://ws.okx.com:8443/ws/v5/business
Public channels — tickers, candlesticks, limit price, order book, mark price — need no authentication. Private channels — account, orders, positions, balance, risk warnings, greeks — require a WebSocket login step after connecting.
Official SDKs reduce boilerplate. OKX publishes a Python package (python-okx on PyPI) with classes for Account, Trade, MarketData, and others, plus sample market-maker code on GitHub. A community-maintained Node.js SDK (okx-api on npm) covers the REST and WebSocket surface with TypeScript types. You can still call the REST API directly from any language using curl, Postman, or fetch; the docs include Python and JavaScript signing examples.
👉 Create an OKX account to generate API keys
Every private REST request carries four headers:
OK-ACCESS-KEY — your API key string
OK-ACCESS-SIGN — Base64-encoded HMAC SHA256 signature
OK-ACCESS-TIMESTAMP — ISO 8601 UTC with millisecond precision, e.g. 2025-03-28T12:21:41.274Z
OK-ACCESS-PASSPHRASE — the passphrase you set when creating the key
The signature is built by concatenating timestamp + method + requestPath + body, then signing with the secret key using HMAC SHA256 and Base64-encoding the result. The server rejects requests whose timestamp drifts more than 30 seconds from server time (error 50102), so synchronizing with GET /api/v5/public/time before sending orders is standard practice.
WebSocket login uses the same idea: sign timestamp + GET + /users/self/verify with your secret key, Base64-encode, and send it in the login op along with your API key, passphrase, and Unix timestamp in seconds.
When you create a key on the OKX website (Account → API), you choose which permissions to attach. Three are available and can be combined:
Read — view bills, order history, balances, positions
Trade — place and cancel orders, transfer funds between accounts, change settings
Withdraw — initiate crypto withdrawals
The minimum-privilege rule applies. A market-data-only bot needs Read. A trading bot needs Read and Trade. Withdraw should stay off for any key used by third-party software; a trade-only key physically cannot move funds off the exchange.
Each API key can bind up to 20 IP addresses in IPv4, IPv6, or CIDR segment form. IP binding is strongly recommended for any key with Trade or Withdraw enabled — without it, a leaked key is immediately usable from anywhere. OKX also lets you review usage records of unbound trade/withdraw keys through the Security Center.
👉 Set up API keys after registering on OKX
Rate limits protect the matching engine and differ per endpoint. The general shape on the V5 API:
Public unauthenticated REST calls are throttled per IP address. A typical public endpoint such as /api/v5/account/instruments allows 20 requests per 2 seconds.
Private REST calls are throttled per User ID. Sub-accounts have their own User IDs, so spreading traffic across sub-accounts multiplies effective capacity.
WebSocket login and subscribe/unsubscribe are limited per connection: 480 subscribe/unsubscribe/login operations per hour, with a 3-connection-per-second handshake cap.
For private WebSocket channels (orders, account, positions, balance, risk warnings, greeks), the cap is 30 concurrent connections per channel per sub-account. The server pushes a channel-conn-count event so you can monitor usage.
Trading endpoints (place, amend, cancel) share limits across REST and WebSocket. Place, amend, and cancel each have independent budgets, and limits are defined per instrument ID (per instrument family for options).
A sub-account can submit up to 1,000 new and amendment order requests per 2 seconds in aggregate. Batch order requests count each leg individually.
A single order can have at most 3 concurrent amend requests in flight; a fourth returns error 51513.
Order-level caps apply on top of rate limits:
4,000 pending orders exchange-wide per account
500 pending orders per trading pair
500 pending spread orders across all spreads
Algo orders: 100 TP/SL per instrument, 500 trigger, 50 trailing, 100 iceberg, 20 TWAP
Grid bots: 100 spot grids, 100 contract grids
When a taker order would match more than 1,000 maker orders, the taker is canceled (FOK) or partially filled then canceled (limit), protecting the engine from pathological matching.
For VIP 5 and above, OKX adds a fill-ratio incentive. It computes the ratio of USDT trade volume to (request count × symbol multiplier) over the past 7 days, then assigns the sub-account to one of eight tiers. Tier 1 (ratio below 1) gives 1,000 order requests per 2 seconds; Tier 8 (ratio ≥ 50) gives 10,000. The system uses the higher of the sub-account's own ratio and the master account's aggregate ratio, updated daily at 08:00 UTC. If you run a high-frequency strategy, the practical takeaway is that efficient orders unlock higher throughput automatically.
OKX ships a demo-trading environment that mirrors production with virtual funds. The demo REST base URL is the same (https://openapi.okx.com), but you set the header x-simulated-trading: 1 on every request and use demo-specific WebSocket hosts:
Public: wss://wspap.okx.com:8443/ws/v5/public
Private: wss://wspap.okx.com:8443/ws/v5/private
Business: wss://wspap.okx.com:8443/ws/v5/business
Demo API keys do not expire, and you can hold up to 200 virtual positions. Some functions are unavailable in sandbox — withdraw, deposit, and certain purchase/redemption flows — but spot, futures, and options trading logic behaves the same as live. There is also a browser-based Demo Trading Explorer that lets you call endpoints from the docs page after signing in, useful for quick tests without standing up a script.
The recommended path is: sign in → Trade → Demo Trading → Personal Center → Demo Trading API → Create Demo Trading API Key. Develop and backtest there, then swap the host and remove the x-simulated-trading header when going live.
👉 Try the demo environment after signing up via OKX
The same API surface handles five instrument types: SPOT, MARGIN, SWAP (perpetual futures), FUTURES (expiry futures), and OPTION. Event contracts are exposed under EVENTS.
Account mode determines how margin and positions are handled. Four modes exist, and the first switch must be done on the web or app:
Spot mode — spot trading only
Futures mode — long/short futures with isolated or cross margin
Multi-currency margin mode — shared margin across spot, futures, and options in a unified account
Portfolio margin mode — risk-based margin for sophisticated derivative strategies
Your code should call GET /api/v5/account/instruments?instType=... to fetch the live instrument list, then GET /api/v5/account/fee-rate to read the fee group that applies to each symbol, since some pairs belong to special fee groups (zero-fee spot, stablecoin pairs, RWA groups, etc.).
Fee tiers are the closest thing an exchange has to "plans." OKX assigns your tier daily at 16:00 UTC based on the higher of your 30-day trading volume or your snapshot asset balance. Tier changes update again at 20:00–22:00 UTC. The rates below are the published US spot/stablecoin schedule; futures and options use the same tier ladder but different base rates described afterwards.
For users with assets under $100,000 and 30-day volume under $100,000:
Maker fee: 0.2000%
Taker fee: 0.3500%
24-hour crypto withdrawal limit: $10,000,000
This is the default tier every new account starts on. If you only place limit orders, the maker side is what you actually pay.
Threshold: assets $100,001–$200,000 or 30-day volume $100,001–$250,000.
Maker fee: 0.1000%
Taker fee: 0.2000%
24-hour crypto withdrawal limit: $24,000,000
The first VIP tier halves both maker and taker fees compared with the regular tier. Crossing $100k in 30-day volume is the typical trigger.
Threshold: assets $200,001–$2,000,000 or 30-day volume $250,001–$500,000.
Maker fee: 0.0750%
Taker fee: 0.1500%
24-hour crypto withdrawal limit: $32,000,000
Threshold: assets $2,000,001–$5,000,000 or 30-day volume $500,001–$1,000,000.
Maker fee: 0.0600%
Taker fee: 0.1250%
24-hour crypto withdrawal limit: $40,000,000
Threshold: assets $5,000,001–$20,000,000 or 30-day volume $1,000,001–$2,500,000.
Maker fee: 0.0500%
Taker fee: 0.1000%
24-hour crypto withdrawal limit: $48,000,000
Threshold: assets $20,000,001–$50,000,000 or 30-day volume $2,500,001–$5,000,000.
Maker fee: 0.0450%
Taker fee: 0.0800%
24-hour crypto withdrawal limit: $60,000,000
VIP 5 is also the entry point for the fill-ratio-based rate-limit boost described above.
Threshold: assets $50,000,001–$100,000,000 or 30-day volume $5,000,001–$50,000,000.
Maker fee: 0.0400%
Taker fee: 0.0700%
24-hour crypto withdrawal limit: $72,000,000
Threshold: assets $100,000,001–$250,000,000 or 30-day volume $50,000,001–$75,000,000.
Maker fee: -0.0020% (negative — you receive a rebate)
Taker fee: 0.0250%
24-hour crypto withdrawal limit: $80,000,000
From VIP 7 upward, maker fees go negative, meaning limit orders that provide liquidity earn a small rebate instead of paying a fee. OKX has posted advance notices adjusting VIP 7 and VIP 8 spot and futures fees effective September 9, 2026, so check the live fee schedule before relying on these exact rates if you trade at that volume.
Threshold: assets $250,000,001–$500,000,000 or 30-day volume $75,000,001–$125,000,000.
Maker fee: -0.0050%
Taker fee: 0.0200%
24-hour crypto withdrawal limit: $80,000,000
Threshold: assets $500,000,001+ or 30-day volume $125,000,001+.
Maker fee: -0.0050%
Taker fee: 0.0150%
24-hour crypto withdrawal limit: $80,000,000
The same tier ladder applies, but the base rates differ. For USDT-margined and USDC-margined perpetual and expiry futures, the regular user rate is 0.02% maker / 0.05% taker, scaling down through the VIP tiers alongside spot. Coin-margined contracts settle fees in the underlying coin. Options use 0.02% maker / 0.03% taker at regular tier in the docs' worked example, with an exercise fee of 0.02% (not charged on day options) and a forced liquidation fee set to your taker tier rate. Expiry settlement fee is 0.01% for all users regardless of tier. Spread trading enjoys a 50% discount on each leg's corresponding instrument fee. The Convert product charges zero trading fees.
Fee calculation is per-instrument: spot fee = fee rate × amount of crypto received; USDT-M futures fee = fee rate × (contracts × multiplier × face value × fill price); crypto-margined futures fee = fee rate × (contracts × multiplier × face value / fill price). Check GET /api/v5/account/fee-rate from your code to read the exact rate per symbol rather than hardcoding.
👉 View current fees and tiers on OKX
The shape of your integration depends on what you are building. A few patterns come up often.
Market-data apps only need public endpoints and the public WebSocket. Subscribe to tickers, candles, or order book channels, persist what you need, and serve it to your frontend. No API key required unless you also want private account data.
Trading bots typically use a private WebSocket for order and position updates and REST for order placement, with the balance channel keeping collateral in sync. Bind the key to the bot server's IP, enable only Read and Trade, and never store the secret key in a public repo.
Grid and algo strategies can use OKX's built-in Spot Grid, Contract Grid, TWAP, Iceberg, Trailing, and TP/SL endpoints instead of reimplementing them — the API exposes them as algo order types with their own limits (100 spot grids, 100 contract grids, 20 TWAP, 100 iceberg, 50 trailing).
Portfolio and treasury tools lean on the account and bill endpoints. Pull balance, fetch historical bills, compute cost basis. Read-only keys are sufficient and safer.
Market-making and institutional flow can apply to the OKX Market Maker Program (open to VIP 2 and above or qualified market makers on other venues) for fee arrangements, or to the Broker Program for platforms that bring their own users. The Broker API has separate rate limits (e.g. 40 requests per second on certain endpoints) and DMA sub-account key management.
Sub-account management is first-class. Master accounts can create and fund sub-accounts, and each sub-account inherits the master's fee tier at 16:00 UTC on creation. Spreading trading across sub-accounts is the documented way to multiply per-account rate limits when one account's throughput is insufficient.
A few habits prevent most API-related losses:
Bind every Trade or Withdraw key to specific IPs. The 20-IP ceiling is plenty for a typical deployment.
Default new keys to Read-only and add Trade only when the bot actually places orders.
Keep Withdraw off for any key shared with third-party software. A trade-only key cannot move funds.
Treat the secret key and passphrase like passwords — store them in a secrets manager, not in code or environment files checked into version control.
Use the demo environment for new strategies before going live. The same code path validates without risking capital.
Watch the channel-conn-count WebSocket events so you do not accidentally exceed the 30-connection cap per private channel.
Sync server time via GET /api/v5/public/time before placing orders to avoid 50102 timestamp rejections.
The OKX V5 docs include worked examples for every endpoint, a Python Spot Trading Tutorial using Jupyter Notebook, a Python Derivatives Trading Tutorial, sample market-maker code on GitHub, and a Demo Trading Explorer for in-browser testing. The Python SDK (python-okx) and Node.js SDK (okx-api) cover most use cases without manual signing.
If you want to test the API end-to-end, the fastest path is: register, complete identity verification, switch to Demo Trading, create a demo API key, install python-okx, and run the example code from the docs against the demo WebSocket host. Once your strategy is stable, swap to the production endpoints, create a production key with IP binding and Trade permission, and go live.
👉 Sign up on OKX and start building with the API