Skip to content

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.

OKX account menu with API and connections.

Click Create API key.

OKX API page with No API keys yet and the Create API key button.

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.

OKX Basic info with the API key name, Main account and 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.

OKX Crypto dialog with every coin selected.

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.

OKX Permissions with Trade on Spot & Margin, Perpetual, Expiry and Options and Crypto set to All, then Security with trusted IP addresses and a passphrase.

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.

OKX API keys drafts with the HaasOnline API draft and the Submit all button.

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

OKX Verify with authenticator app, step 1 of 2.

OKX Verify with email, step 2 of 2.

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.

  1. Click the + button at the bottom of the accounts list (on an empty page it reads Add account)
  2. Select Exchange account
  3. In Connect an exchange account, click OKX
  4. 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.

    What should this account trade, with OKX under Spot and OKX Futures and OKX Swap under Derivatives.

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

    OKX account setup form with the IP whitelist, account name, public key, private key and passphrase fields.

    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.

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