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
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.

