OKX¶
HaasOnline connects to OKX (spot), OKX Futures (dated futures) and OKX Swap (perpetual swaps). One OKX key covers all three if it is created with the Trade permission on those markets. HaasOnline asks for three values: the API key, the secret key and the passphrase you set when creating the key.
If you don't have an OKX account yet, sign up at OKX.
Obtaining the API Key¶
Log in to OKX, open the account menu at the top right and click API and connections.

Click Create API key.

Basic info¶
- API key name: any name that identifies the key (for example
HaasOnline API). - Account: Main account, or the sub-account HaasOnline should trade.
- Used for: API trading.

Permissions and security¶
Under Permissions, tick Trade (Read is always on). Leave Withdraw, Onchain, Earn, Loan and Transfer unticked.
Trade opens two more settings:
- Markets: tick Spot & Margin (OKX), Perpetual (OKX Swap) and Expiry (OKX Futures). Options is optional, since HaasOnline doesn't trade OKX options. Leave Events unticked.
- Crypto: click Edit and select all, so it reads All. OKX only lets a key trade the coins listed here, so a bot on a coin that isn't selected has its orders rejected.

Under Security:
- Trusted IP addresses: turn it on and add the IP addresses shown in HaasOnline (or your server's IP on a self-hosted license, see below), separated by commas or spaces.
- Passphrase: 8 to 32 characters, with at least one lowercase letter, one uppercase letter, one number and one special character. You will enter it in HaasOnline later, so note it down now.

Danger
Do not tick Withdraw or Transfer. HaasOnline never needs them to trade for you, and a trading-only key limits what a leaked key could do.
Info
For the trusted IP addresses:
- On HaasOnline TradeServer Cloud, paste the addresses shown under IP addresses to whitelist in the HaasOnline account setup form (use its copy icon).
- On a self-hosted TradeServer license, use the public IP address of your machine or server.
OKX lets a key with trade permission expire after 14 days without use when it isn't linked to an IP address. A linked key doesn't expire.
Submit and verify¶
The key appears under API keys drafts. Click Submit all.

Enter the 6-digit code from your authenticator app, click Continue, then enter the code OKX emails you and click Confirm.


Copy the keys¶
OKX then shows the new key:
- API key: goes in the HaasOnline Public key field.
- Secret key: goes in the HaasOnline Private key field.
- The passphrase you set goes in the HaasOnline Passphrase field.
Danger
Copy the secret key now and keep the passphrase. If you lose either, delete the key and create a new one.
Adding the API to HaasOnline TradeServer Cloud¶
Log in to HaasOnline TradeServer Cloud and open Exchange Accounts from the user menu in the top right. The Adding an API to the Platform guide shows these first steps with screenshots.
- Click the + button at the bottom of the accounts list (on an empty page it reads Add account)
- Select Exchange account
- In Connect an exchange account, click OKX
-
Under What should this account trade?, choose OKX for spot trading, or OKX Futures or OKX Swap under Derivatives, then click Continue with .... Each market is its own HaasOnline account, so repeat these steps with the same key to add another market.

-
Enter an Account name, then paste the values from OKX:
- Public key → the OKX
API key - Private key → the OKX
secret key - Passphrase → the passphrase you set when creating the key

Info
Check for spaces at the start and end of each value after you paste it. Stray spaces are a common cause of a failed key test.
- Public key → the OKX
-
Click Test keys. When the test passes, click Save account
If the test fails, check that Trade is ticked for the market you picked (Spot & Margin, Expiry or Perpetual), that Crypto is set to All, that the passphrase is exactly the one you set, and that the trusted IP addresses match the ones shown in HaasOnline. If it still fails, contact Support.