Create API keys
Generate your API key on OKX
Visit OKX API Management and create a new API key. OKX will generate three values that you need:
| Credential | Description |
|---|---|
apiKey | Public identifier for your key |
apiSecret | Secret used to sign requests — treat this like a password |
apiPass | Passphrase you chose when creating the key |
Store credentials in environment variables
Never hardcode credentials in source code. Use environment variables instead:Or pass them inline when running a script:
Use single quotes in the shell to prevent special characters like
$ from being incorrectly interpolated.Region selection
OKX operates three separate regional platforms, each with its own domain and API endpoint. API keys are created per platform and are not interchangeable between regions.| Region | Domain | market value |
|---|---|---|
| OKX Global (default) | www.okx.com | 'GLOBAL' or omit |
| OKX EEA | my.okx.com | 'EEA' |
| OKX US | app.okx.com | 'US' |
market option on either client to connect to the correct regional endpoint:
Global is the default. If you are on
www.okx.com, you do not need to set market at all.Demo trading mode
OKX provides a paper trading environment (“demo trading”) that uses separate demo keys but does not require real funds. This is the recommended way to test your integration before going live. Enable it by settingdemoTrading: true on either client. Use your demo API keys — not your live keys.
Client options reference
TheRestClientOptions interface (from src/types/rest/client.ts) and WSClientConfigurableOptions interface (from src/types/websockets/ws-general.ts) accept the following credential and authentication options:
RestClientOptions
| Option | Type | Description |
|---|---|---|
apiKey | string | Your OKX API key |
apiSecret | string | Your OKX API secret |
apiPass | string | Your OKX API passphrase |
market | 'GLOBAL' | 'EEA' | 'US' | 'prod' | Regional endpoint to connect to. Defaults to 'GLOBAL' (www.okx.com) |
demoTrading | boolean | Set to true to use OKX’s demo trading environment |
baseUrl | string | Override the API base URL entirely (advanced use) |
keepAlive | boolean | Enable HTTP KeepAlive for REST requests |
strict_param_validation | boolean | Throw errors on undefined parameters when true |
WSClientConfigurableOptions
| Option | Type | Description |
|---|---|---|
accounts | APICredentials[] | One or more { apiKey, apiSecret, apiPass } objects for private channel authentication |
market | 'GLOBAL' | 'EEA' | 'US' | 'prod' | Regional endpoint to connect to |
demoTrading | boolean | Set to true to use OKX’s demo trading environment |
pingInterval | number | How often (ms) to check if the connection is alive |
pongTimeout | number | How long (ms) to wait for a heartbeat reply before treating the connection as dead |
reconnectTimeout | number | Delay (ms) before respawning a dropped connection |
Security best practices
- Use environment variables — load credentials with
process.envand never commit them to version control. - Restrict API key permissions — create read-only keys for market data, and only grant trade/withdrawal permissions to keys that require them.
- Rotate keys regularly — if a key is compromised, revoke it immediately from the OKX API Management page.
- Use IP allowlisting — OKX lets you bind an API key to specific IP addresses, limiting exposure if a key is leaked.
- Separate demo and live keys — keep demo trading keys distinct from production keys to avoid accidentally trading on a live account.

