OKX API Manual

Manual: Connecting OKX API to AlgoWay (with IP allowlist)

Overview: Create an API key in OKX with Read and Trade → bind AlgoWay IP → add the key to the AlgoWay Dashboard → create a TradingView alert that routes to your webhook.

AlgoWay IP to allow:
103.241.67.174
API keys with IP allowlist are safer: OKX will accept requests only from AlgoWay.
1) Create API key on OKX
  1. Sign in to your OKX account → go to API (API Keys).
  2. Click Create API key.
  3. Fill the form:
    • API Name — any label you recognize, e.g. my_key.
    • PurposeAPI trading.
    • IP address allowlist (optional) — add 103.241.67.174.
    • Permissions — enable Read and Trade.
    • Passphrase — create a passphrase (you’ll also enter it in AlgoWay).
OKX create API key OKX API key card

Copy and store: API Key, Secret Key, and your Passphrase. OKX shows the Secret only once.

2) Add the webhook in AlgoWay
  1. Open Dashboard → Add Trial Webhook.
  2. Select:
    • Platform: OKX — this tells AlgoWay to send orders to OKX.
    • Quantity Multiplier: Absolute → 1 — your strategy’s quantity is used “as is”.
    • Market Type: Futures/Perpetual — perpetual swaps (no expiry) used by most algos.
    • Margin Mode: Cross or Isolated:
      • Cross — risk is shared across positions (simpler for beginners).
      • Isolated — margin per position; losses are contained to that position.
    • Trade Type: Hedge — allows holding long and short at the same time on one symbol.
  3. Paste your API Key, Secret Key, and Passphrase. Click Add Trial Webhook.
AlgoWay add webhook form Webhook list - UUID

After saving, you’ll see your webhook in the list. Click the purple copy icon to copy the unique Webhook URL (UUID) — you’ll paste it into TradingView.

3) Create the TradingView alert
  1. Open the OKX symbol on TradingView (e.g. BTCUSDT.P).
  2. Right-click the strategy on the chart → Add alert on strategy.
  3. On the Message tab paste this JSON:
    {
      "platform_name": "okx",
      "ticker": "{{ticker}}",
      "order_contracts": "{{strategy.order.contracts}}",
      "order_action": "{{strategy.market_position}}",
      "price": "{{close}}"
    }
  4. On the Notifications tab enable Webhook URL and paste your UUID link from AlgoWay.
TradingView alert message TradingView JSON message Tradingview webhook URL

platform_name must be exactly: okx. Otherwise the alert won’t be routed.

4) Add SL / TP / Trailing (optional)

AlgoWay for OKX supports absolute prices and offsets in pips (pip = tick size of the instrument). If both are provided, absolute prices win.

Absolute SL/TP (prices):

{
  "platform_name": "okx",
  "ticker": "ETHUSDT.P",
  "order_action": "buy",
  "order_contracts": 1,
  "sl_price": 1800,
  "tp_price": 1850
}

Offsets in pips (from last price):

{
  "platform_name": "okx",
  "ticker": "BTCUSDT.P",
  "order_action": "sell",
  "order_contracts": 0.5,
  "stop_loss": 50,
  "take_profit": 100
}

Trailing Stop (always in pips):

{
  "platform_name": "okx",
  "ticker": "ARBUSDT.P",
  "order_action": "buy",
  "order_contracts": 10,
  "trailing_pips": 50
}
When a trailing stop is used, AlgoWay still allows attaching a Take Profit. Stop Loss won’t be attached because the trailing stop handles exit protection dynamically.
5) Close positions with flat

Send "order_action": "flat" to close positions. In hedge mode, both long and short legs can be closed according to the size you send.

{
  "platform_name": "okx",
  "ticker": "BTCUSDT.P",
  "order_action": "flat",
  "order_contracts": 1
}
6) Verify on OKX

Executed orders and attached algos (TP / SL / trailing) appear in your OKX trading panel. Open positions are shown in the bottom panel.

OKX tradingview alert OKX positions panel
That’s it

AlgoWay is now connected to OKX. Your TradingView strategy alerts will place orders on OKX through your secured webhook.