Complete Node.js SDK for OKX (formerly OKEx) REST APIs and WebSockets, with full TypeScript support and over 100 end-to-end tests. Current stable version is 3.1.4, actively maintained with frequent releases. Key differentiators: supports all OKX regions (Global, EEA, US), both REST and WebSocket APIs, automatic WebSocket reconnection and resubscription, and a unique WebSocket API client that provides a REST-like interface over WebSockets. Ships with type declarations for most request/response payloads and works in browsers via webpack. Compared to alternatives, it offers broader regional support and more extensive testing.
npm install okx-apiNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Illustrates creating a REST client with API credentials and fetching a ticker and account balance.
Use import statements or upgrade to Node.js with ESM support.
Replace OKXClient with RestClient in imports and instantiation.
Set the 'market' property in WebsocketClient options to match your account region.
Provide a non-empty apiPassphrase when constructing RestClient or WebsocketClient.
Use WebsocketAPIClient for WebSocket API requests instead of manual subscription.
Upgrade Node.js to version 14 or later.
Switch to ES module imports: 'import { RestClient } from \"okx-api\"'Provide an object with the mandatory fields as per API spec, e.g., { instId: 'BTC-USDT' }Set apiKey property when constructing the client.
Ensure WebsocketClient options include correct 'market' (e.g., 'US' for OKX US) and check network connectivity.
Wait for the 'open' event before subscribing, or handle reconnect logic using the library's auto-reconnect.