TradingView → OKX

TradingView to OKX: execute alerts on OKX swaps and spot

AlgoVesta turns each TradingView alert into an order on your OKX account through a trade-only API key with a passphrase. Perpetual swaps get algo stop-loss and take-profit orders; spot orders go out in cash mode, so a buy never borrows, and carry one OCO order with both levels. Funds stay in your OKX account.

How it works

1
Create an OKX API key

Name the key, set a passphrase and write it down, then enable the Trade permission only.

2
Add key, secret and passphrase

All three go into the AlgoVesta dashboard; the passphrase is encrypted like the secret.

3
Prepare the alert JSON

Use the signal designer or the template below, with stop_loss and take_profit from your indicator plots.

4
Attach the webhook

Paste your AlgoVesta webhook URL under Notifications in the TradingView alert and save it.

Cash mode on OKX spot, and why it matters

OKX accounts can trade spot in cash mode or in margin modes. A common general-purpose library quietly switches spot orders to cross margin, which can leave a trader with a borrowed balance they never asked for. AlgoVesta sends OKX spot orders through OKX's own API in cash mode instead, so a spot buy only spends what you hold.

Protection on OKX spot is a single OCO algo order that holds both the stop-loss and the take-profit; when one triggers, the other is withdrawn. On perpetual swaps the levels are conditional reduce-only orders. In both cases AlgoVesta reads them back from OKX, and OKX reports these orders in its algo order list rather than the normal open orders, which is where the check looks.

What the passphrase changes

OKX is one of three exchanges in this group, with KuCoin and Bitget, that add a passphrase to every API key. It is set by you when the key is created and cannot be recovered later, so if it is lost the key has to be recreated. AlgoVesta stores it encrypted next to the secret and uses it only to sign requests.

Swap sizing

On swaps OKX trades in contracts. AlgoVesta converts the margin and leverage in your alert into a contract count and picks the nearest size OKX accepts; if that is more than 20% off your amount, nothing is opened and the bot card shows what would work.

The alert message

Paste this into the alert's message box. The two plot values come from your indicator; leverage is ignored on spot.

{
  "symbol": "{{ticker}}",
  "action": "buy",
  "price": "{{close}}",
  "stop_loss": "{{plot_0}}",
  "take_profit": "{{plot_1}}",
  "leverage": 10
}

For a Pine strategy, use the strategy template so exits and reversals work. Do not send only {{strategy.order.action}}: on an exit it reads "sell" and would open a short instead of closing. The market_position fields tell AlgoVesta when the strategy is flat.

{
  "symbol": "{{ticker}}",
  "action": "{{strategy.order.action}}",
  "market_position": "{{strategy.market_position}}",
  "prev_market_position": "{{strategy.prev_market_position}}",
  "position_size": "{{strategy.position_size}}",
  "price": "{{close}}"
}

TradingView only shows the Webhook URL box when two-factor authentication is on in your TradingView account. TradingView cannot send custom headers, so AlgoVesta verifies the source from TradingView's own server addresses and auto-trades only alerts it can verify.

Connect your OKX API key

Create the key in OKX with these permissions: Trade. Withdrawal and transfer stay disabled, because AlgoVesta never needs them: it can place and close orders, but it cannot move funds out of your account. OKX keys also have a passphrase that you choose when you create the key. Enter it in AlgoVesta together with the key and secret; it is encrypted the same way.

If you restrict the key to IP addresses, the AlgoVesta connection wizard shows the two server addresses to add. The full click-by-click guide, with what each OKX screen looks like, is in the help center.

How to connect OKX to AlgoVesta →

Rules that apply to every order

  • A stop-loss on every order: from the signal, or from your own percentage or distance. No stop-loss source, no order.
  • A daily-loss limit that pauses new entries until the next UTC day.
  • Maximum open positions and maximum trades per day per bot.
  • A panic button that closes what AlgoVesta opened and leaves your own positions alone.

On crypto exchanges an order opens in about 4.1 seconds on average, from the signal arriving to a filled order with its protection attached, measured across AlgoVesta's own executions.

FAQ

OKX questions

The most common questions before you decide — if you still have doubts, start here.

No. Spot orders are sent in cash mode through OKX's own API, so a buy spends only the balance you hold and never creates a loan.
In the algo orders tab. OKX lists conditional and OCO orders there, not under the regular open orders.
Create a new API key with a new passphrase and replace the key in AlgoVesta. OKX cannot show the passphrase again.
Yes. Swaps get conditional reduce-only stop-loss and take-profit orders, read back from OKX after the entry fills.
Yes. With the strategy template, a reversal closes the current side and then opens the new one, in that order.

Try TradingView alerts on OKX in paper mode first

Every bot can start on a $5,000 virtual balance, so you see the fills before a real order is sent. 7-day free trial, no credit card required.

Start Free Trial

See plans and pricing

Last reviewed: 4 October 2026