Overview
TheRestClient class maps every OKX REST API endpoint to a typed TypeScript method. Public endpoints work without credentials. Private endpoints require an API key, secret, and passphrase.
Installation
Instantiation
Constructor options
| Option | Type | Required | Description |
|---|---|---|---|
apiKey | string | No | API key from OKX. Required for private endpoints. |
apiSecret | string | No | API secret from OKX. Required for private endpoints. |
apiPass | string | No | API passphrase set when creating the key. Required for private endpoints. |
market | 'GLOBAL' | 'EEA' | 'US' | 'prod' | No | Regional endpoint to connect to. Defaults to 'GLOBAL' (www.okx.com). |
demoTrading | boolean | No | Set to true to use the OKX demo trading environment. |
baseUrl | string | No | Override the default REST base URL. |
keepAlive | boolean | No | Enable HTTP KeepAlive for REST requests via axios. |
strict_param_validation | boolean | No | Throw errors when true and any parameter is undefined. |
parse_exceptions | boolean | No | Whether to post-process request exceptions. Default: true. |
customSignMessageFn | function | No | Provide a custom HMAC signing function for higher performance (e.g. Node.js createHmac). |
Request and response pattern
All methods return aPromise that resolves to an array of typed response objects. The SDK automatically unwraps the OKX { code, msg, data } envelope — when code === '0' the promise resolves with data; any non-zero code causes the promise to reject with an error.
Error handling
When OKX returns a non-zero error code, or a network error occurs, the SDK throws. Wrap calls intry/catch:
The SDK never silently swallows errors. If
code !== '0' the returned data is thrown as the error, giving you the full OKX error object.Latency utility
The client exposes a helper to measure round-trip latency and clock skew between your machine and OKX servers:Available sections
Account
Balances, positions, leverage, fee rates, and account configuration.
Trading
Place, cancel, and amend orders. Query order history and fills.
Funding
Deposits, withdrawals, transfers, and currency conversion.
Market Data
Public tickers, candles, order books, and funding rates.
Sub-accounts
Manage sub-accounts, balances, and inter-account transfers.
Earn & Finance
Staking, savings, ETH staking, and fixed/flexible lending.
Copy Trading
Lead-trader and copy-trader management, positions, and profit sharing.
Grid Trading
Create and manage spot, futures, and contract grid bots.
Signal Bots
Create signal sources, deploy bots, and manage sub-orders.
Block Trading
RFQ creation, quote management, and block trade execution.
Spread Trading
Submit and manage spread orders and query spread market data.
Recurring Buy
Set up, amend, and track recurring DCA purchase orders.

