Built into AlgoGP Pro

How to get a OKX API key

An OKX API key has three parts: key, secret and the passphrase you choose. Create one in Demo Trading first.

About 10 minutes 5 steps Checked October 2026

Before you start

  • A verified OKX account with 2FA
  • Your server’s IP address (recommended)

Create your OKX API key

  1. 1

    Open API management

    Log in and open Profile → API (okx.com/account/my-api). For a demo key, first switch to Demo Trading.

  2. 2

    Create a V5 API key

    Click Create API key, choose API trading, and set a name.

  3. 3

    Set a passphrase

    Choose a passphrase and save it; OKX cannot show it again.

  4. 4

    Choose permissions

    Tick Read and Trade. Never tick Withdraw for a bot.

  5. 5

    Bind IPs and confirm

    Add your server IP (keys without IPs may expire after inactivity), confirm with 2FA, then copy the key and secret.

Test the key

Before wiring the key into a strategy, make one request by hand. It separates “the key is wrong” from “my code is wrong”.

import base64, hashlib, hmac, os, urllib.request
from datetime import datetime, timezone
ts = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
path = "/api/v5/account/balance"
sign = base64.b64encode(hmac.new(os.environ["OKX_API_SECRET"].encode(), (ts + "GET" + path).encode(), hashlib.sha256).digest()).decode()
req = urllib.request.Request("https://www.okx.com" + path, headers={
    "OK-ACCESS-KEY": os.environ["OKX_API_KEY"], "OK-ACCESS-SIGN": sign, "OK-ACCESS-TIMESTAMP": ts,
    "OK-ACCESS-PASSPHRASE": os.environ["OKX_PASSPHRASE"], "x-simulated-trading": "1"})
print(urllib.request.urlopen(req).read().decode())
"code":"0" with balance details means the key works. Remove the simulated header for a live key.

Add the key to your AlgoGP project

  1. 1

    Open your project’s APIs & keys tab

    Open the strategy project, select APIs & keys, and under Platforms choose OKX (Pro).

  2. 2

    Paste each value

    Paste the values into OKX_API_KEY and OKX_API_SECRET and OKX_PASSPHRASE and click Save. Values are encrypted at rest, never shown again and never written into code or exports.

  3. 3

    Run locally with the same names

    Exported projects read the same names from .env (copy .env.example). Keep .env out of version control.

OKX_API_KEY=paste-your-value-here
OKX_API_SECRET=paste-your-value-here
OKX_PASSPHRASE=paste-your-value-here
.env for local runs

Frequently asked questions

Can I use a demo OKX key on live?

No. Demo and live keys are separate; demo keys need the x-simulated-trading: 1 header.

Build an OKX trading bot in minutes

Describe the strategy in plain English, backtest it on years of data, then export Python that already talks to OKX: paper, sandbox and live modes, keys handled for you.

  • Generated adapter for OKX orders and balances
  • Backtests with costs, slippage and walk-forward checks
  • Paper first; live trading only after you opt in

Free plan, no card required. OKX is included with Pro.

How the OKX API works

AlgoGP is not affiliated with OKX. Menus get renamed from time to time; if a label differs, the official documentation has the current path.