OKX Guide
Connect TradingView to OKX (Spot, Futures, and Swap) using TradeAdapter’s direct API integration. This guide covers strategy-based alerts with the Message Generator.
Video walkthrough #
OKX + TradingView setup
1 — Create OKX API keys #
OKX uses V5 API keys. Create a key with Trade permission and add the TradeAdapter IP to the whitelist.
-
Open API Keys
Log in to OKX, go to the API Keys menu (or Account → API).
-
Create V5 API key
Click Create V5 API key and fill the form: choose API Trading, set any name for the API, create a Passphrase (you will need it with the key and secret), add the TradeAdapter IP
35.75.198.16to the whitelist, and allow the Trade function. -
Save your credentials
Copy and store your API Key, Secret, and Passphrase. The Secret is shown only once. You will paste them into the alert message as
okx_api_key,okx_secret, andokx_passphrase.
2 — Select the OKX symbol in TradingView #
Open TradingView and search for the symbol using the OKX prefix. Match the symbol to the market you will use in your message: Spot, Futures, or Swap.
Search OKX:BTCUSDT, OKX:ETHUSD, OKX:SOL-USDT, etc. Use the symbol format that matches OKX Spot (e.g. BTC-USDT, ETH-USD).
For Futures or Swap, select the corresponding OKX symbol on TradingView. The order_market in your message must be "Futures" or "Swap" and the symbol must exist in that market.
Important
The {{ticker}} placeholder sends this exact symbol to OKX. The symbol must exist in the chosen market (Spot, Futures, or Swap) and match the supported symbols. Check the symbol lists for Lot Size, Min Order Size, and Price Tick Size.
3 — Add your strategy #
This guide covers strategy alerts only. Load your Pine Script strategy onto the chart so it generates the trading signals.
Open Pine Editor, paste your strategy code, and click “Add to chart”. Open the Strategy Tester tab to confirm backtest results and that orders are generated.
Not sure if you have a strategy or an indicator? See Indicator vs Strategy.
4 — Configure order size #
OKX enforces symbol-specific rules (Lot Size, Min Order Size, Price Tick Size). Configure your strategy’s position size so that {{strategy.order.contracts}} meets the symbol’s minimum and step. For Limit orders, ensure {{strategy.order.price}} respects the price tick size.
OKX Spot •
OKX Futures •
OKX Swap — check min size and precision per symbol.
5 — Create the TradingView alert #
Press Alt + A (or the alarm clock icon) to create a new alert on your strategy.
Strategy → one alert
Under Condition, select your strategy and set trigger to “Order fills only”. TradingView fills action, size, and price via {{strategy.order.action}}, {{strategy.order.contracts}}, and {{strategy.order.price}}.
Required: Webhook URL + Message
In Notifications, enable Webhook URL and paste your personal webhook from your TradeAdapter profile. Paste the JSON message (below) in the Message field. You can build it with the OKX Message Generator.
Alert message (Strategy) #
Use this template for strategy-based alerts. Replace the placeholder values with your API key, secret, and passphrase; set order_market to Spot, Futures, or Swap to match your symbol. Keep the TradingView placeholders as-is.
{
"okx_api_key": "PUT YOUR OKX API KEY HERE",
"okx_secret": "PUT YOUR OKX SECRET HERE",
"okx_passphrase": "PUT YOUR OKX PASSPHRASE HERE",
"real_order": "No",
"order_market": "Spot",
"order_type": "Market",
"exchange": "okx",
"ticker": "{{ticker}}",
"time": "{{timenow}}",
"order_contracts": "{{strategy.order.contracts}}",
"order_action": "{{strategy.order.action}}",
"order_price": "{{strategy.order.price}}"
}
Message fields explained #
| Field | Description |
|---|---|
okx_api_key |
Your OKX API Key from the V5 API creation step. |
okx_secret |
Your OKX Secret. Store it securely and never share it. |
okx_passphrase |
The passphrase you set when creating the V5 API key. |
real_order |
"Yes" sends real orders to OKX. "No" sends test orders via TradeAdapter only (no live trades). |
order_market |
"Spot", "Futures", or "Swap". Must match the TradingView symbol and the market you trade. |
order_type |
"Market" or "Limit". For Limit orders, order_price is used as the limit price. |
exchange |
Must be "okx" so TradeAdapter routes the order to OKX. |
ticker |
The TradingView symbol from {{ticker}} (e.g. OKX:BTCUSDT). |
time |
Alert time from TradingView ({{timenow}}). |
order_contracts |
Position size from your strategy ({{strategy.order.contracts}}). |
order_action |
"BUY" or "SELL". Use {{strategy.order.action}} for strategies. |
order_price |
Price from the strategy ({{strategy.order.price}}), used for Limit orders. |
6 — Execute & monitor #
-
Start with test orders
Set
"real_order": "No"and trigger a few alerts. Check MyTrades to see how TradeAdapter interprets your signals. -
Verify on OKX
When you set
"real_order": "Yes", monitor your OKX account (Spot, Futures, or Swap) to confirm orders execute as expected. -
Recreate alerts after changes
If you change strategy parameters or the message, delete and recreate the TradingView alert so the new values are applied.
Important notes #
API security — Never share your Secret or Passphrase. Use a key with Trade permission only. Add IP
35.75.198.16 to the whitelist so only TradeAdapter can use the key.
order_market must match — Use
"Spot", "Futures", or "Swap" according to the symbol you selected on TradingView. Wrong market will cause order failures.
Respect symbol specs — Check Spot, Futures, and Swap symbol lists for min size and precision; test with small orders before scaling.
Recreate alerts after changes — If you change strategy parameters or message fields, delete and recreate the TradingView alert.
All setup guides