Skip to content

Public market data ​

Use RestClient without credentials for public data. An instrument ID includes separators: BTC-USDT is Spot and BTC-USDT-SWAP is a perpetual swap. Availability depends on region and instrument status.

Read instrument rules and market data ​

Install okx-api and save this example as market-data.ts. It reads the BTC-USDT Spot instrument rules, a five-level order book and perpetual-swap tickers.

ts
import { RestClient } from 'okx-api';

const client = new RestClient();

async function main() {
  const instruments = await client.getInstruments({ instType: 'SPOT', instId: 'BTC-USDT' });
  const book = await client.getOrderBook({ instId: 'BTC-USDT', sz: '5' });
  const swaps = await client.getTickers({ instType: 'SWAP' });
  console.log('Spot instrument rules:', instruments);
  console.log('Five book levels:', book);
  console.log('Swap tickers:', swaps);
}

main().catch((error) => {
  console.error('Market data request failed:', error);
  process.exitCode = 1;
});

Run it on Node.js 24, or compile it with your TypeScript project:

sh
node market-data.ts

The example prints each result with its label. Each method returns an array of records from the API's data field.

Check instrument rules ​

Inspect instrument metadata before choosing order values: tickSz is the price increment, lotSz the size increment, and minSz the minimum size. Also check the current instrument state and contract fields. Spot limit sizes are in base currency; derivative sizes generally represent contracts and must be interpreted using the instrument metadata.

Keep price and size values as decimal strings when sending requests. Do not assume JavaScript floating-point arithmetic preserves valid increments.

Read an order book ​

getOrderBook() is a REST snapshot. Book levels include price and size along with additional fields defined by OKX. A single snapshot is not a continuously maintained order book.

For ongoing data use WebSocket subscriptions. For a small order-book display, use a snapshot channel such as books5. For incremental books, apply the initial snapshot and subsequent updates, and check continuity with seqId and prevSeqId according to the order-book channel rules. The checksum field for books, books-l2-tbt and books50-l2-tbt is deprecated and fixed at 0; do not use it to validate these books. Recover after a sequence gap before applying further updates.

getInstruments reference · getOrderBook reference · OKX public data

Built by Siebly. Open source SDKs for exchange APIs.