Prerequisites
You need a Node.js project with TypeScript support (recommended) or plain JavaScript. The SDK is published to npm asokx-api.
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.
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.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.Subscribe to real-time data via WebSocket
WebsocketClient handles connection management, heartbeats, automatic reconnection, and resubscription for you. Public channels require no credentials.subscribe(). If the connection drops, it will reconnect and resubscribe without any extra code on your side.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.

