Skip to main content

Prerequisites

You need a Node.js project with TypeScript support (recommended) or plain JavaScript. The SDK is published to npm as okx-api.
1

Install the SDK

2

Make your first public REST call

No API credentials are required for public endpoints. The example below fetches all SPOT instruments and filters for SUI pairs — a useful sanity check that the SDK is installed correctly.
Responses are automatically unwrapped. When OKX returns { code: '0', data: [...] }, the SDK returns only the data array — no extra nesting to handle.
3

Authenticate and check your balance

For private endpoints you must supply apiKey, apiSecret, and apiPass. Load them from environment variables — never hardcode credentials.
OKX credentials are region-specific. Keys created on www.okx.com (Global) will not work with my.okx.com (EEA) or app.okx.com (US). See Authentication for how to set the market option.
4

Place an order

Once you have a funded account, you can submit orders with client.submitOrder(). The example below places a market buy for BTC-USDT.
These examples place real orders on your live account. Use demoTrading: true in your client options while testing. See Authentication for details.
5

Subscribe to real-time data via WebSocket

WebsocketClient handles connection management, heartbeats, automatic reconnection, and resubscription for you. Public channels require no credentials.
The client will open a connection automatically when you call subscribe(). If the connection drops, it will reconnect and resubscribe without any extra code on your side.
6

Subscribe to private WebSocket channels

Pass your credentials in the accounts array to enable private channels such as account, positions, and orders.

Next steps

Authentication

Learn how to create OKX API keys, pass credentials, and configure region and demo trading mode.

REST Client

Browse every available method, request type, and response shape.

WebSocket Client

Understand WebSocket events, reconnection behavior, and private channel authentication.

WebSocket API Client

Place orders and manage positions over a persistent WebSocket connection using a REST-like interface.