So you want to automate your crypto trades, pull live market data into your own dashboard, or build an algo bot that doesn't sleep β and you've landed on OKX as your exchange of choice. Smart move. OKX exchange APIs are among the most feature-rich in the industry, and if you know how to use them, you can do a lot more than just place buy and sell orders.
This guide is for anyone who's already poked around OKX and is wondering: how do I actually connect to this thing programmatically? Whether you're a developer building a trading bot, a quant running backtests, or someone who just wants to automate a simple recurring buy, this breakdown will get you oriented fast.
Let's be honest β most people don't compare exchange APIs until they've already been burned by a bad one. Rate limits hit at the worst moment. WebSocket connections drop without warning. Documentation is three versions out of date. Sound familiar?
OKX's API ecosystem has matured significantly. They currently support three main protocol types: REST, WebSocket, and FIX. That's enterprise-level coverage that you typically only see at top-tier venues. The documentation is actively maintained, the SDK support is real (not just a half-broken Python library from 2019), and there's a proper demo environment where you can test with $100,000 in virtual funds before risking a single cent.
"Build it in demo, break it in demo. Only then should it touch real money."
That philosophy alone makes OKX a sensible choice for anyone serious about programmatic trading.
π Start with OKX and claim your sign-up bonus
The REST API is your bread-and-butter. It's synchronous β you send a request, you get a response β and it covers the full breadth of OKX functionality:
- Account management: balances, positions, leverage settings
- Order management: place, modify, cancel orders (spot, margin, futures, options)
- Market data: order books, candlesticks, ticker prices, funding rates
- Funding operations: deposits, withdrawals, internal transfers
- Sub-account management: useful for institutions running multiple strategies
Authentication uses four headers: OK-ACCESS-KEY, OK-ACCESS-SIGN, OK-ACCESS-TIMESTAMP, and OK-ACCESS-PASSPHRASE. The signature is HMAC-SHA256 β standard stuff, but you need to get the timestamp within 30 seconds of server time or requests will be rejected.
Rate limits for the REST API:
- Public endpoints: 20 requests per 2 seconds (IP-based)
- Private endpoints: vary by endpoint, generally User ID-based
- Sub-account trading: up to 1,000 order requests per 2 seconds
For real-time data, the WebSocket API is where you want to be. It maintains a persistent bidirectional connection, meaning you're not hammering the server with repeated HTTP requests β the data comes to you.
What you can subscribe to:
- Live order book updates
- Trade feed (every executed trade)
- Candlestick streams
- Account and position changes
- Order status updates
Key WebSocket limits:
- 480 subscription requests per hour
- Maximum 30 WebSocket connections per channel per sub-account
- Up to 100 connections per API key
If you're building a market-making bot or any strategy that needs sub-second data, WebSocket is non-negotiable.
The FIX API is for institutional players who need low-latency execution and already have FIX infrastructure. It's available via OKX's partnerships with platforms like Axon Trade. If you're at that level, you already know what FIX is β and OKX having it is a meaningful signal about where the exchange positions itself.
Before you write a single line of code, you need to create API keys. Here's the flow:
- Log in to your OKX account (or create one β use the invite code CASH20 for a 20% commission rebate)
- Navigate to Account β API Management
- Click Create API Key
- Set a name for the key and assign permissions:
- Read: market data, account info
- Trade: place and cancel orders
- Withdraw: initiate withdrawals (keep this off unless you specifically need it)
- Set an IP allowlist β this is not optional for production. Locking your key to specific IPs is the single most important security step you can take.
- Save your API key, secret key, and passphrase somewhere safe. The secret key is only shown once.
One thing worth noting: API keys with trade or withdrawal permissions that are not IP-bound will automatically expire after 14 days of inactivity. Set IP restrictions and you won't hit this problem.
π Create your OKX account and generate your first API key
Every private API request requires a signed header. Here's the signature logic:
signature = HMAC-SHA256(secret_key, timestamp + method + request_path + body)
Where:
timestampis the current UTC time in ISO 8601 format (e.g.,2026-04-20T12:00:00.000Z)methodisGETorPOST(uppercase)request_pathis the endpoint path including query parameters for GET requestsbodyis the JSON request body for POST requests (empty string for GET)
The result is base64-encoded and placed in the OK-ACCESS-SIGN header.
Most developers will just use an SDK and not think about this too hard, but understanding the signature logic helps when you're debugging a 403 error at 2 AM.
The most common use case. OKX supports a wide range of order types via API:
- Market orders: execute immediately at best available price
- Limit orders: set your price, wait for fill
- Post-only orders: maker-only, rejected if it would take
- IOC (Immediate or Cancel): fill what you can, cancel the rest
- FOK (Fill or Kill): fill everything or nothing
Beyond basic orders, OKX has API endpoints for algo orders β including TWAP, iceberg, and trailing stop strategies. These execute server-side, so your bot doesn't need to stay connected for the order logic to run.
OKX has a built-in grid trading engine accessible via API. You can programmatically create and manage grid strategies on spot and futures markets β useful if you want to layer grids across multiple pairs without manual setup.
Pull account balances, positions, P&L history, and transaction records programmatically. If you run multiple accounts or sub-accounts, the API lets you aggregate data across all of them into a single view.
OKX offers free access to historical candlestick data, live order books, trade history, and funding rate data via both REST and WebSocket. This is useful for:
- Backtesting strategies
- Building custom charting tools
- Running quantitative research
OKX's copy trading feature is accessible via API, letting developers build platforms that connect signal providers to followers programmatically β a whole product category built on top of OKX's infrastructure.
OKX provides official SDK support for:
| Language | Status |
|---|---|
| Python | Official SDK |
| JavaScript / Node.js | Official SDK |
| .NET (C#) | Official SDK |
| R | Official SDK |
Community SDKs also exist for Java, Go, and PHP β check the OKX GitHub organization for what's maintained.
For Python users, installation is straightforward:
bash pip install python-okx
The SDK handles authentication, signature generation, and request formatting, so you can focus on strategy logic rather than boilerplate.
This is underrated and underused. OKX's demo trading environment gives you:
- $100,000 in virtual USDT to simulate real trading
- Full API access mirroring the production environment
- Realistic market data and order execution
The API base URL for demo is https://www.okx.com but with a demo flag in the header (x-simulated-trading: 1). Your API keys from the main account work in demo with this flag β you don't need separate credentials.
Test your entire stack β authentication, order placement, WebSocket subscriptions β before going live. There's really no reason not to.
OKX uses a volume-based tiered fee system. Your tier is determined by whichever is higher: your total account assets or your 30-day trading volume in any single product line.
| Tier | 30-Day Volume / Assets | Maker Fee | Taker Fee | Get Started |
|---|---|---|---|---|
| Level 1 (Regular) | < $5M | 0.08% | 0.10% | Join OKX |
| VIP 1 | β₯ $5M volume or $3M assets | Lower | Lower | Join OKX |
| VIP 2 | β₯ $50M volume or $6M assets | Lower | Lower | Join OKX |
| VIP 3 | β₯ $200M volume or $12M assets | Lower | Lower | Join OKX |
| VIP 4+ | β₯ $2B+ volume or $60M+ assets | Negotiated | Negotiated | Join OKX |
| Tier | Maker Fee | Taker Fee | Get Started |
|---|---|---|---|
| Level 1 (Regular) | 0.02% | 0.05% | Join OKX |
| VIP 1 | Lower (can go negative) | Lower | Join OKX |
| VIP 2+ | Negative maker (OKX pays you) | Lower | Join OKX |
A few things worth knowing:
- OKB token holdings can further reduce your fees at all tiers
- Futures maker fees at high VIP levels go negative β meaning OKX pays you to provide liquidity
- Fee structures were updated in April 2026, with adjusted VIP tier thresholds for futures
- Regional frameworks (EEA, US) have their own specific fee schedules
For API-heavy algorithmic traders who are primarily making (not taking) liquidity, the futures fee structure is particularly attractive. Even at the base level, 0.02% maker on futures is competitive with any major exchange.
Getting rate-limited mid-strategy is painful. Here's what to keep in mind:
REST API:
- Public market data: 20 requests per 2 seconds (IP-level)
- Private account/trading: endpoint-specific, User ID-level tracking
- Order placement for sub-accounts: up to 1,000 requests per 2 seconds
WebSocket:
- 480 subscription operations per hour
- Max 30 connections per channel per sub-account
- Max 100 connections per API key
Best practices:
- Use WebSocket for anything real-time β don't poll REST for price data
- Batch order operations where possible
- Implement exponential backoff on 429 errors
- Use sub-accounts to get additional rate limit headroom for high-frequency strategies
- Monitor your request counts and add circuit breakers before you hit limits
OKX launched the Agent Trade Kit in 2026 β a notable development for anyone building AI-assisted trading applications. It allows AI assistants and agents to execute trades directly through OKX, with a key security design: API keys never leave your device.
This matters for AI trading applications because it addresses the trust problem of giving an external AI system your credentials. The Agent Trade Kit provides a structured interface that limits what an AI can do and how it can interact with your account.
If you're building LLM-based trading tools, this is worth looking into as an alternative to raw API key management.
If you're setting up a new OKX account to access the APIs, the current welcome offer is worth taking advantage of:
- 20% commission rebate on trading fees with invitation code CASH20
- New users can also qualify for up to $400 in free Bitcoin through OKX's tiered welcome bonus:
- Deposit and trade $200 within 30 days β earn $100 BTC
- Deposit $10,000 or more β earn an additional $300 BTC
- Bonuses are typically credited within 7β14 days of qualifying activity
For API traders who are going to be doing significant volume, the 20% fee rebate compounds meaningfully over time. If you're paying 0.08% maker fees and get 20% back, your effective rate is 0.064% β worth capturing.
π Register with code CASH20 and claim your bonus
Is OKX API free to use? Yes. API access is free for all OKX users. You only pay the standard trading fees when your bot places orders.
Can I run multiple bots on the same account? Yes. You can create multiple API keys with different permissions and scopes. Sub-accounts are also available for more complete isolation between strategies.
Does OKX have a sandbox/test environment?
Yes β the demo trading environment. Use the x-simulated-trading: 1 header with your normal API credentials.
What happens if my bot has a bug and places a large order? OKX has self-trade prevention settings and you can set order size limits at the API key level. Using IP allowlists and permission scoping also limits blast radius.
Is OKX API available in my country? OKX is restricted in some jurisdictions (including the United States for most products). Check OKX's terms of service for your specific region. The US has a separate OKX US framework with its own fee structure.
What version of the API is current? OKX API v5 is the current and only supported production version. Previous versions have been deprecated.
If you're starting from zero, here's your path:
- Create an OKX account (use code CASH20 for fee rebates)
- Complete KYC verification
- Generate API keys with appropriate permissions
- Set IP allowlist restrictions
- Install the OKX SDK for your language
- Test authentication in the demo environment
- Subscribe to a WebSocket channel and verify data flow
- Place a small test order in demo
- Build out your strategy logic
- Monitor rate limits and set up alerting
- Go live with small position sizes first
π Create your OKX account and start building
OKX exchange APIs offer a genuinely complete toolkit for programmatic trading β from simple REST calls to real-time WebSocket feeds to FIX for institutions. The demo environment makes testing friction-free, the SDK ecosystem covers the main languages, and the fee structure rewards high-volume API traders with lower maker fees (and eventually negative fees at VIP tiers).
The main things to get right from the start: lock down your API keys with IP allowlists, use WebSocket instead of polling REST for real-time data, and always test in demo before going live. Do those three things and you'll avoid the most common pain points.
Whether you're building a simple recurring buy script or a full algo strategy, OKX has the infrastructure to support it.
π Sign up for OKX with code CASH20 and start with a 20% commission rebate