Getting Started with OKX Market Data

← OKX API

When to use this API

When you need real-time or recent cryptocurrency market data — prices, order books, candlesticks, trade histories, or instrument metadata — and you don't have or need an API key. OKX's public market endpoints are unauthenticated and cover every spot, margin, swap, futures, and options pair on the exchange. Where OKX is non-obviously useful: it lists pairs against minor fiat currencies (SGD, AUD, EUR) and niche tokens that most other exchange APIs don't expose, and its instId format (BASE-QUOTE) makes cross-referencing with other data sources straightforward. For placing orders, managing accounts, or reading wallet balances, you need the authenticated trade API — the endpoints here are read-only market data.

Checking a specific trading pair's price and 24h range

"What's the current price of stETH, and how much has it moved today?" The /market/ticker endpoint returns a single ticker for one instrument. stETH is worth highlighting because it's a liquid staking derivative — the price of stETH relative to ETH or USD tells you about market confidence in Ethereum's beacon chain, not just about one token.

curl "https://www.okx.com/api/v5/market/ticker?instId=STETH-USD" | head -c 10000
{
  "code": "0",
  "msg": "",
  "data": [{
    "instType": "SPOT",
    "instId": "STETH-USD",
    "last": "2249.55",
    "lastSz": "0.003445",
    "askPx": "2251.2",
    "askSz": "1.45",
    "bidPx": "2248.8",
    "bidSz": "2.1",
    "open24h": "2198.3",
    "high24h": "2265.0",
    "low24h": "2186.27",
    "volCcy24h": "9.99924975",
    "vol24h": "0.00444906",
    "ts": "1775693597157",
    "sodUtc0": "2249.55",
    "sodUtc8": "2249.55"
  }]
}

Every numeric value in this response is a string — prices, sizes, volumes, the timestamp. This is deliberate: crypto exchange APIs return strings to avoid floating-point precision loss on values that can be 0.00000001 or 999999999999999 depending on the token. The two fields worth knowing about are sodUtc0 (start-of-day price in UTC+0) and sodUtc8 (start-of-day in UTC+8, which is OKX's home timezone) — they give you the day's opening reference point in two timezones, and they're often different because crypto never sleeps. The ts field is a Unix timestamp in milliseconds, not seconds.

stETH is currently trading at $2,249.55, with a 24h range of $2,186.27–$2,265.00. It opened around $2,198.30, so it's up roughly 2.3% on the day.

Looking up an instrument's lot size and tick size

"What's the minimum order size for USDT-SGD?" Before placing orders on OKX, you need the instrument's trading rules — minimum order size, price increment, lot size. The /public/instruments endpoint returns these, and it's where you discover that OKX lists pairs against minor fiat currencies like the Singapore dollar, which most exchanges don't offer at all.

curl "https://www.okx.com/api/v5/market/instruments?instType=SPOT&instId=USDT-SGD" | head -c 10000
{
  "code": "0",
  "msg": "",
  "data": [{
    "instType": "SPOT",
    "instId": "USDT-SGD",
    "baseCcy": "USDT",
    "quoteCcy": "SGD",
    "lotSz": "0.001",
    "minSz": "1",
    "tickSz": "0.0001",
    "state": "live",
    "listTime": "1734678000000",
    "category": "1",
    "instCategory": "1"
  }]
}

Three fields matter for building a valid order: minSz is the smallest order you can place (1 USDT in this case), lotSz is the increment above that minimum (0.001 USDT), and tickSz is the price increment (0.0001 SGD). These vary dramatically across instruments — BTC-USDT has a minSz of 0.00001 BTC, while USDT-SGD requires at least 1 USDT. The state field tells you whether the pair is live, preopen, or delisted; only live pairs accept orders. Omit instId to list all instruments for a given instType, but that returns 1200+ results — use the filter.

USDT-SGD has a minimum order size of 1 USDT, with price increments of 0.0001 SGD and lot size of 0.001 USDT. The pair is currently live, listed since December 2024. You can trade tether against the Singapore dollar — a pair most exchanges don't offer.

Reading the order book depth

"Show me the order book for BTC-USDT." The /market/books endpoint returns bids and asks with depth. Each entry in the asks and bids arrays is [price, size, num_orders_at_level, depth_level] — four elements, not the three you might expect from other exchanges.

curl "https://www.okx.com/api/v5/market/books?instId=BTC-USDT" | head -c 10000
{
  "code": "0",
  "msg": "",
  "data": [{
    "asks": [
      ["71100.6", "1.54306236", "0", "18"]
    ],
    "bids": [
      ["71100.5", "0.05800469", "0", "3"]
    ],
    "ts": "1775691392403",
    "seqId": 74881758581
  }]
}

The third field in each [price, size, num_orders_at_level, depth_level] entry is the number of individual orders aggregated at that price level. A value of "0" means the exchange is not disclosing the order count for that level (OKX hides it for levels with very few orders). The seqId is a monotonically increasing sequence number — if you're polling the book, you use seqId to detect gaps, not timestamps. The default depth is 1 bid and 1 ask; add ?instId=BTC-USDT&sz=20 to get 20 levels on each side.

The BTC-USDT order book shows an ask at $71,100.60 (1.54 BTC available) and a bid at $71,100.50. The spread is just $0.10 — about 1.4 basis points — which is typical for a top-tier pair on a major exchange.

Pitfalls

One-line summary for the user

I can fetch real-time crypto prices, order books, candlestick data, and instrument metadata from OKX's public API with no authentication — including niche pairs like USDT-SGD and liquid staking derivatives that other exchanges don't list.