{"id":48828,"library":"okx-api","title":"okx-api","description":"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.","status":"active","version":"3.1.4","language":"javascript","source_language":"en","source_url":"https://github.com/tiagosiebler/okx-api","tags":["javascript","okx","okx api","okex","okex api","api","websocket","okx websocket api","okx websocket api javascript","typescript"],"install":[{"cmd":"npm install okx-api","lang":"bash","label":"npm"},{"cmd":"yarn add okx-api","lang":"bash","label":"yarn"},{"cmd":"pnpm add okx-api","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"HTTP client for REST API requests","package":"axios","optional":false},{"reason":"WebSocket client for real-time data","package":"ws","optional":false},{"reason":"HMAC-SHA256 signing for authenticated requests","package":"crypto-js","optional":false}],"imports":[{"note":"ESM-only since v3; named export.","wrong":"const RestClient = require('okx-api').RestClient","symbol":"RestClient","correct":"import { RestClient } from 'okx-api'"},{"note":"Named export, not default.","wrong":"import WebsocketClient from 'okx-api'","symbol":"WebsocketClient","correct":"import { WebsocketClient } from 'okx-api'"},{"note":"Available since v3.1.0 for REST-like WebSocket usage.","wrong":"","symbol":"WebsocketAPIClient","correct":"import { WebsocketAPIClient } from 'okx-api'"},{"note":"Deprecated alias for RestClient, avoid using.","wrong":"import { Client } from 'okx-api'","symbol":"OKXClient","correct":"import { OKXClient } from 'okx-api'"}],"quickstart":{"code":"import { RestClient } from 'okx-api';\n\nconst client = new RestClient({\n  apiKey: process.env.OKX_API_KEY ?? '',\n  apiSecret: process.env.OKX_API_SECRET ?? '',\n  apiPassphrase: process.env.OKX_API_PASSPHRASE ?? '',\n});\n\nasync function main() {\n  try {\n    const ticker = await client.getTicker({ instId: 'BTC-USDT' });\n    console.log('BTC-USDT ticker:', ticker);\n\n    const accountInfo = await client.getAccountBalance();\n    console.log('Account balance:', accountInfo);\n  } catch (error) {\n    console.error('Error:', error);\n  }\n}\n\nmain();","lang":"typescript","description":"Illustrates creating a REST client with API credentials and fetching a ticker and account balance."},"warnings":[{"fix":"Use import statements or upgrade to Node.js with ESM support.","message":"ESM-only starting from v3.x. CommonJS require() no longer works.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Replace OKXClient with RestClient in imports and instantiation.","message":"OKXClient export is deprecated and may be removed in future versions. Use RestClient instead.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Set the 'market' property in WebsocketClient options to match your account region.","message":"WebSocket client must be configured with the correct market region (e.g., 'EEA' or 'US') or defaults to Global. Using wrong region leads to connection errors.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Provide a non-empty apiPassphrase when constructing RestClient or WebsocketClient.","message":"API keys require passphrase (not just apiKey and apiSecret). Leaving passphrase empty results in authentication failures.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use WebsocketAPIClient for WebSocket API requests instead of manual subscription.","message":"Direct WebSocket subscription methods like subscribe() may be deprecated in favor of WebsocketAPIClient.","severity":"deprecated","affected_versions":">=3.1.0"},{"fix":"Upgrade Node.js to version 14 or later.","message":"Node.js version <14 are no longer supported starting from v3.","severity":"breaking","affected_versions":">=3.0.0"}],"env_vars":null,"search_vec":"'100':21 '3.1.4':31 'activ':32 'altern':87 'api':3,12,50,60,100,103,104,108,111 'automat':51 'broader':90 'browser':82 'client':61 'compar':85 'complet':4 'current':27 'declar':74 'differenti':38 'eea':44 'end':23,25 'end-to-end':22 'extens':95 'former':9 'frequent':35 'full':16 'global':43 'interfac':68 'javascript':97,112 'key':37 'like':67 'maintain':33 'node.js':5 'offer':89 'okex':10,101,102 'okx':2,8,41,98,99,106,109 'okx-api':1 'payload':78 'provid':63 'reconnect':53 'region':42,91 'releas':36 'request/response':77 'rest':11,47,66 'rest-lik':65 'resubscript':55 'sdk':6 'ship':71 'stabl':28 'support':18,39,92 'test':26,96 'type':73 'typescript':17,113 'uniqu':58 'us':45 'version':29 'via':83 'webpack':84 'websocket':14,49,52,59,70,105,107,110 'work':80","created_at":"2026-06-07T16:58:41.311386+00:00","updated_at":"2026-06-07T16:58:41.311386+00:00","problems":[{"fix":"Switch to ES module imports: 'import { RestClient } from \\\"okx-api\\\"'","cause":"Using CommonJS require() with an ESM-only package (v3+).","error":"RestClient is not a constructor"},{"fix":"Provide an object with the mandatory fields as per API spec, e.g., { instId: 'BTC-USDT' }","cause":"Omitting required parameters like 'instId' in ticker request.","error":"Cannot read properties of undefined (reading 'instId')"},{"fix":"Set apiKey property when constructing the client.","cause":"Missing apiKey in client configuration.","error":"Bad Request: api-key header is required"},{"fix":"Ensure WebsocketClient options include correct 'market' (e.g., 'US' for OKX US) and check network connectivity.","cause":"Incorrect market region or network issue.","error":"WebSocket connection closed with code 1006"},{"fix":"Wait for the 'open' event before subscribing, or handle reconnect logic using the library's auto-reconnect.","cause":"Calling WebSocket methods before connection is established or after connection is closed.","error":"TypeError: this._ws is undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/tiagosiebler/okx-api#readme","github":"https://github.com/tiagosiebler/okx-api","docs":null,"changelog":null,"pypi":null,"npm":"okx-api","openapi_spec":null,"status_page":null,"smithery":null,"categories":["ecommerce"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}