Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

OKX Public API: The Complete Developer's Guide to Automated Crypto Trading

If you've ever watched a trading bot execute 200 orders in the time it takes you to open your laptop, you've probably wondered: what API is that thing running on?

For a growing number of algorithmic traders and developers, the answer is the OKX public API — and honestly, once you dig into it, it's not hard to see why.

OKX is one of the world's largest cryptocurrency exchanges by trading volume, and its API infrastructure is built to match that scale. Whether you're building a simple price alert bot or a multi-strategy quant system pulling tick data across 50 instruments simultaneously, the OKX public API gives you the raw material to make it happen.

This guide walks you through everything — what's available without credentials, how authentication works when you need it, rate limits, SDKs, trading bot capabilities, and the fee tiers that matter when your bot starts printing real volume.


What Is the OKX Public API, and Why Does It Matter?

At its core, the OKX public API is a set of HTTP and WebSocket endpoints that expose market data, instrument information, and other exchange-level data — no account required.

That's the key distinction: public endpoints are open to anyone. You don't need an API key to pull the current orderbook for BTC/USDT, check available trading pairs, or stream real-time candlestick data. This makes the OKX public API particularly useful for:

  • Researchers and analysts building data pipelines for backtesting
  • Developers prototyping trading strategies before committing to a live account
  • Dashboard builders pulling live price feeds without user authentication overhead
  • Arbitrage scouts monitoring price discrepancies across multiple pairs in real time

The public API splits into two main channels: REST and WebSocket. Each serves a different use case, and most serious implementations use both.


REST API vs. WebSocket API: Choosing the Right Tool

REST API

The REST API is your standard request-response HTTP interface. You send a GET or POST request, you get a JSON response. Simple, predictable, and great for:

  • Fetching historical candlestick data
  • Querying available instruments (spot, futures, options, perpetuals)
  • Checking current orderbook snapshots
  • Pulling funding rates and mark prices

Public REST endpoints live under www.okx.com (or regional equivalents: us.okx.com for US/Australia, eea.okx.com for EU users).

A quick example — you can hit this directly in your browser right now:

https://www.okx.com/api/v5/public/instruments?instType=SPOT

That returns the full list of active spot trading pairs with their tick sizes, lot sizes, and trading status. Zero authentication required.

WebSocket API

For anything that needs to happen in real time — price feeds, orderbook updates, trade streams — WebSocket is the tool. Instead of polling a REST endpoint every second (and burning through rate limits), you open a persistent connection and OKX pushes updates to you as they happen.

The public WebSocket endpoint:

wss://ws.okx.com:8443/ws/v5/public

You subscribe to channels — say, the BTC-USDT 1-minute candle channel — and data flows in continuously. No repeated HTTP handshakes, no polling lag.

There's also a business channel WebSocket (wss://ws.okx.com:8443/ws/v5/business) for more specialized data streams like algo order updates.


Key Public API Endpoints You'll Actually Use

Here's a rundown of the public endpoints that developers reach for most often:

Market Data

  • GET /api/v5/market/tickers — snapshot of all tickers (last price, 24h volume, bid/ask)
  • GET /api/v5/market/ticker?instId=BTC-USDT — single ticker
  • GET /api/v5/market/candles — historical OHLCV candlestick data
  • GET /api/v5/market/books — full orderbook (up to 400 levels)
  • GET /api/v5/market/trades — recent trade history

Instrument Information

  • GET /api/v5/public/instruments?instType=SPOT — list all spot pairs
  • GET /api/v5/public/instruments?instType=FUTURES — futures contracts
  • GET /api/v5/public/instruments?instType=OPTION — options chain

Funding and Derivatives

  • GET /api/v5/public/funding-rate — current funding rate for perpetuals
  • GET /api/v5/public/mark-price — mark price for futures/options
  • GET /api/v5/public/open-interest — open interest across derivatives

All of these return clean JSON with consistent field naming. If you've worked with other exchange APIs and found them inconsistent or poorly documented, OKX's v5 API is a noticeable step up.


Authentication: Moving Beyond Public Endpoints

Once you're ready to place orders, access account data, or run algo strategies, you'll need to authenticate. OKX uses a four-header system:

Header Value
OK-ACCESS-KEY Your API key
OK-ACCESS-SIGN HMAC SHA256 signature, Base64-encoded
OK-ACCESS-TIMESTAMP ISO 8601 UTC timestamp
OK-ACCESS-PASSPHRASE The passphrase you set when creating the key

The signature is generated by concatenating timestamp + method + requestPath + body, then signing with your secret key using HMAC SHA256. Every major language has a library for this — it's about 10 lines of code once you understand the pattern.

For private WebSocket connections, authentication happens at the connection level: you send a login message with your credentials before subscribing to private channels.

Pro tip: OKX provides a full demo trading environment you can activate with a single header: x-simulated-trading: 1. All your logic runs against real market data, but orders never touch real funds. This is genuinely useful — most exchanges don't offer this level of sandbox fidelity.


Rate Limits: What You Need to Know Before Hitting Production

Rate limits are where a lot of algorithmic traders get tripped up, so let's be direct about how OKX structures them.

Public endpoints: Limited by IP address. You're typically allowed dozens of requests per second on market data endpoints, but it varies by endpoint.

Private endpoints: Limited by User ID. Trading endpoints are further scoped by instrument, so your BTC-USDT limit doesn't bleed into your ETH-USDT allocation.

WebSocket subscriptions: Maximum 30 connections per channel per sub-account, and 480 subscription requests per hour per connection.

Order limits: Up to 4,000 total pending orders exchange-wide, with 500 per individual trading pair.

Sub-accounts can handle a maximum of 1,000 order requests per 2 seconds — which is genuinely high throughput for most strategies. If you're building something that needs more, OKX's Market Maker Program (available at VIP 2+) comes with enhanced limits.


Trading Bot Capabilities: What You Can Actually Build

Here's where OKX separates itself from exchanges that just expose raw API access and leave you to figure out the rest.

OKX has over 840,000 active bot traders and reports nearly $430 million in cumulative bot earnings across its platform. They've built native bot infrastructure directly into the exchange — no third-party service required.

The supported bot types include:

  • Grid Trading: Places buy/sell orders at regular intervals within a price range. Ideal for sideways, volatile markets. Setup takes under 5 minutes.
  • DCA (Dollar-Cost Averaging): Automates periodic purchases to smooth out entry price over time. Good for accumulation strategies.
  • Buy the Dip: Triggers purchases on specified downward price moves. Useful during correction phases.
  • Signal Bots: Execute orders based on external signals — connect to services like TradingView webhooks.
  • Arbitrage Bots: Target price discrepancies between spot and derivatives.
  • Recurring Buy: Simple scheduled purchases, no strategy required.
  • Copy Trading: Mirror the positions of verified traders on the platform.

And if you want full custom control, the public and private API gives you the primitives to build whatever you want on top. The supported order types include limit, market, post-only, IOC, FOK, trailing stops, and TP/SL — so you're not working with a stripped-down interface.

If you're ready to start building or trading with the full suite of tools, 👉 sign up for OKX and get 20% fee rebate.


SDK Options: Don't Start From Scratch

OKX has first-party and community SDKs across multiple languages:

Python (official) bash pip install okx-sdk

Covers REST and WebSocket, handles authentication, and follows the v5 API structure closely.

Node.js / TypeScript (community) bash npm install okx-api

Well-maintained, full TypeScript types, supports both REST and WebSocket with reconnection logic built in.

R Available on CRAN as the okxAPI package — useful for quantitative analysis workflows where R is already in the stack.

Python (alternative) The python-okx package on GitHub from the OKX team themselves, if you want something closer to the official source.

All of these abstract away the signature generation and connection management, so you can focus on strategy logic instead of boilerplate.


OKX Fee Tiers: Why Your Bot's Volume Determines Your Edge

If you're running automated strategies, fees aren't a footnote — they're a core variable in your P&L calculation. OKX uses a VIP tier system based on 30-day trading volume or OKB holdings. Here's the full breakdown:

Tier 30D Volume (USD) Spot Maker Spot Taker Futures Maker Futures Taker Link
Regular < $1M 0.080% 0.100% 0.020% 0.050% Start Trading
VIP 1 ≥ $1M 0.070% 0.090% 0.018% 0.045% Apply VIP 1
VIP 2 ≥ $5M 0.060% 0.080% 0.015% 0.040% Apply VIP 2
VIP 3 ≥ $20M 0.050% 0.070% 0.010% 0.030% Apply VIP 3
VIP 4 ≥ $100M 0.030% 0.060% 0.005% 0.020% Apply VIP 4
VIP 5 ≥ $500M 0.020% 0.050% 0.002% 0.015% Apply VIP 5
VIP 6+ ≥ $1B+ Custom Custom Custom Custom Contact OKX

A few things worth noting here:

  1. Maker fees reward passive orders. If your strategy uses limit orders that sit in the book (maker), you pay significantly less than market takers. High-frequency strategies that cross the spread constantly will feel the taker fees more acutely.

  2. Futures fees are already quite low at Regular tier. 0.02% maker / 0.05% taker on futures is competitive with most major venues.

  3. VIP 2+ unlocks Market Maker benefits, including enhanced rate limits — relevant if your strategy involves continuous quoting.

  4. New users signing up via the referral link get an immediate 20% commission rebate, which effectively brings your fees down across the board from day one. 👉 Claim your 20% rebate here.


Recent API Updates Worth Knowing (2025)

OKX actively maintains and evolves the API. A few notable recent changes:

  • WebSocket disconnect notifications were updated in May 2025 (effective June 2025) — the behavior around connection drops and reconnection signaling changed, so update any reconnection logic if you built it before mid-2025.
  • Broker endpoint paths changed: the URL prefix shifted from /broker/nd to /broker/dma under the DMA Broker program. If you're a broker integrating OKX liquidity, verify your endpoints.
  • New instrument parameters: contTdSwitchTime and openType were added to instrument REST responses and WebSocket channels — useful for tracking contract transitions.
  • Quote currency fee charging for spot and margin went live in production — affects how fee deductions appear in your account statements.

The official API changelog lives at okx.com/help/section/announcements-api — worth bookmarking if you're running production systems.


Is the OKX Public API Right for Your Project?

Let's be honest about the tradeoffs:

It's a strong choice if:

  • You need deep liquidity across spot, futures, and options
  • Your strategy benefits from high-speed, high-frequency execution
  • You want native bot infrastructure alongside raw API access
  • You're building a multi-asset system and need consistent API design across all asset classes

Worth noting:

  • OKX is not available to users in the United States (US-based traders need to check access restrictions)
  • The v5 API is comprehensive but has a learning curve; budget time for the documentation
  • Rate limits are generous but need planning for high-frequency strategies

For most non-US developers building crypto trading infrastructure, OKX's API sits at the top of the list. The combination of low latency, broad instrument coverage, generous public endpoint access, and an active developer community makes it a serious choice.


Getting Started in 4 Steps

  1. Create an OKX account👉 Sign up and get 20% fee rebate. The referral code CASH20 is automatically applied.

  2. Explore the public API — Hit https://www.okx.com/api/v5/market/tickers?instType=SPOT in your browser. No credentials needed. Get a feel for the response structure.

  3. Install an SDK — Pick your language, install the package, and run through the authentication example in the README. Getting a private endpoint working (like fetching your account balance) confirms your keys are set up correctly.

  4. Test in demo mode — Add x-simulated-trading: 1 to your headers and run your strategy against live market data without real money on the line. OKX's demo environment is one of the most realistic in the industry.


Final Thoughts

The OKX public API is genuinely well-built infrastructure — not a bolted-on afterthought. Public endpoints give you a full market data pipeline with zero friction, the private API covers every trading operation you'd need, and the SDK ecosystem means you don't have to reinvent the wheel.

For developers building the next generation of algorithmic trading tools, OKX is worth serious evaluation. The combination of deep liquidity, a robust public API, and competitive fee tiers — especially with the 20% rebate for new users — makes the math work in your favor from the start.

👉 Open your OKX account and claim 20% fee rebate (code: CASH20)

About

OKX Public API: The Complete Developer's Guide to Automated Crypto Trading

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors