🏠 Home 📱 Download 🔑 Sign Up
中文English한국어日本語EspañolРусскийTürkçeTiếng Việt

Binance TradingView Webhook Auto Trading Complete Guide 2026

From Pine alerts to live Binance orders — master 3 mainstream approaches, full setup, and risk control to run your strategy 24/7.

📅 2026⏱ ~25 min📈 Intermediate

1. What is TradingView Webhook auto-trading

TradingView is the world's largest charting and strategy community. When you write a Pine script and want it to auto-trade on Binance, Webhook is the bridge — TradingView POSTs a JSON message to a URL when your alert fires, and a server picks it up and calls Binance API to buy or sell.

The full path: TradingView alert → Webhook URL (your server or third-party) → Binance API → live order.

Pros: visual strategy logic, rich Pine ecosystem. Cons: you need to handle signing, risk control, reconnection, or pay for a ready-made platform.

2. Why Binance for auto-trading

  • Stable API: mature REST and WebSocket, low global latency
  • Deep liquidity: low slippage on majors like BTC/ETH, market orders are safe
  • Spot + Futures: unified docs for USDT-M, COIN-M, spot
  • Sub-accounts: isolate risk per strategy
  • Low fees: register with code BNAPP for lifetime rebate, saving a lot on high-frequency auto trades
💡 Tip
Beginners should start with spot auto-trading, then move to futures. Run small size for 1-2 weeks first to confirm logic.

3. Three approaches compared

ApproachDifficultyCostLatencyBest for
Self-hosted VPS bridgeMid-High$5-10/mo500ms-1.5sCoders who want control
Third-party platform (3Commas, etc.)Low$15-50/mo800ms-2sUsers who want zero-ops
Binance API + local scriptLowPower billLocal network dependentUsers with always-on PC

3.1 Self-hosted bridge

Run a small Node.js / Python / Go service on a VPS, listen on a public URL, sign and call Binance API on receive. Most flexible, supports any custom risk logic.

3.2 Third-party automation platforms

3Commas, Cryptohopper, Wundertrading, Aleeert.com etc. They give you a ready Webhook URL — bind your Binance API and go. Easy but monthly fee + platform risk + custodial API.

3.3 Local script + TradingView desktop

The TradingView desktop client can play sound and run external scripts, triggering a local Python script that calls Binance API. No monthly fee but PC must stay on.

4. Pine script with Webhook alert

Below is a minimal EMA crossover long-only strategy in Pine v5, using alert_message to send JSON:

//@version=5
strategy("EMA Cross Webhook", overlay=true)
fast = ta.ema(close, 12)
slow = ta.ema(close, 26)
longCond  = ta.crossover(fast, slow)
shortCond = ta.crossunder(fast, slow)

if longCond
    strategy.entry("L", strategy.long, alert_message='{"passphrase":"YOUR_SECRET","action":"buy","symbol":"BTCUSDT","qty":0.01,"type":"MARKET"}')
if shortCond
    strategy.close("L", alert_message='{"passphrase":"YOUR_SECRET","action":"close","symbol":"BTCUSDT"}')

Key points:

  • alert_message must be valid JSON for easy parsing
  • passphrase is a shared secret to block strangers who guess your URL
  • When creating the alert, pick this strategy as Condition and put {{strategy.order.alert_message}} in the Message box
  • Set Webhook URL to your VPS endpoint, e.g. https://your-vps.com/tv-webhook

5. Self-hosted bridge setup steps

  1. 1

    Buy a VPS

    DigitalOcean / Vultr / Hetzner $5/mo with 1 vCPU 1G is enough. Pick Tokyo or Singapore for lowest latency to Binance.

  2. 2

    Domain + SSL

    TradingView only POSTs to HTTPS. Use Cloudflare free SSL or Caddy/Nginx + Let's Encrypt.

  3. 3

    Write the receiver

    Use Express (Node) or FastAPI (Python) for a POST endpoint, validate passphrase, then call Binance API.

  4. 4

    Process supervisor

    Use pm2 or systemd so service auto-restarts after crash, and log to file for debugging.

  5. 5

    Binance API permissions

    API mgmt → create key → enable spot/margin or futures only, do NOT enable withdrawal, whitelist your VPS public IP.

  6. 6

    TradingView alert config

    Right-click chart → Add alert → Webhook URL = https://your-vps.com/tv-webhook, Message = {{strategy.order.alert_message}}, create.

  7. 7

    Small-size testing

    Run 50-100 USDT on BTC spot for 3-5 days. Verify every signal converts correctly before scaling.

6. Binance API order code (Node.js example)

import express from 'express';
import crypto from 'crypto';
import axios from 'axios';

const app = express();
app.use(express.json());

const KEY    = process.env.BN_KEY;
const SECRET = process.env.BN_SECRET;
const PASSPHRASE = process.env.PASSPHRASE;
const BASE = 'https://fapi.binance.com';

function sign(query){
  return crypto.createHmac('sha256', SECRET).update(query).digest('hex');
}

app.post('/tv-webhook', async (req, res) => {
  const { passphrase, symbol, action, qty, type='MARKET' } = req.body;
  if (passphrase !== PASSPHRASE) return res.status(401).send('bad passphrase');
  const side = action === 'buy' ? 'BUY' : 'SELL';
  const ts = Date.now();
  const query = `symbol=${symbol}&side=${side}&type=${type}&quantity=${qty}×tamp=${ts}`;
  const url = `${BASE}/fapi/v1/order?${query}&signature=${sign(query)}`;
  try{
    const r = await axios.post(url, null, { headers:{'X-MBX-APIKEY':KEY}});
    res.json(r.data);
  }catch(e){
    console.error(e.response?.data || e.message);
    res.status(500).send('order failed');
  }
});

app.listen(3000, () => console.log('listening 3000'));
✅ Security
Load API Key/Secret via environment variables, never hardcode. Passphrase should be at least 32 random chars. Force HTTPS.

7. Risk control & monitoring

  • Position cap: hardcode max position on server, reject if exceeded
  • Daily loss circuit breaker: poll /fapi/v2/account, pause service if drawdown exceeds threshold
  • Slippage guard: check bookTicker before market order, abort if spread too wide
  • Idempotency: dedupe by client_order_id to avoid double orders
  • Telegram alerts: send every fill or failure to your TG bot
  • Leverage: 3-5x for futures, higher = faster liquidation
  • Heartbeat: cron pings service every 5 min, alerts on failure
⚠️ Strong recommendation
Always test with spot or Binance testnet (testnet.binancefuture.com) first, switch to live only after full logic verification.

8. Common pitfalls & troubleshooting

  • TradingView shows no response: HTTPS cert must be valid, self-signed will be rejected
  • Binance -1021 timestamp expired: sync server clock with apt install ntp
  • -2010 insufficient balance: no margin in futures wallet, transfer USDT first
  • -4131 PERCENT_PRICE_FILTER: limit price too far from market, switch to market or adjust offset
  • Duplicate fills: did you check "once per bar close"? Without it, alerts fire on every tick
  • VPS IP changed: update API whitelist; consider static IP

9. FAQ

Q1: Is TradingView Webhook auto-trading on Binance legal?
Binance allows API trading and TradingView supports webhooks — the combination is compliant. But some countries restrict derivatives, check local rules.
Q2: Can free TradingView use Webhook?
No. Webhook URL is a Pro/Pro+/Premium feature. Free plan only has popup or email.
Q3: Self-hosted vs third-party — which is better?
Self-hosted is controllable and free of monthly fees but requires coding. Third-party is plug-and-play but costs money and has platform risk.
Q4: Does webhook latency hurt strategy?
Typically 500ms-2s. Big impact on sub-1-min strategies, negligible on 4h+ timeframes.
Q5: Does Binance API support market and limit orders?
Both. Market orders are recommended for webhook strategies; large size can use limit IOC.
Q6: How to prevent malicious webhook calls?
The bridge must validate Bearer Token or shared secret. Include passphrase in TradingView body and reject mismatches.
Q7: Is API IP whitelist mandatory?
Strongly recommended. Even if your key leaks, strangers can't use it from other IPs. Most important API protection.
Q8: What if auto-trading liquidates?
Use stop-loss in Pine + on server (double layer). Keep futures leverage at 3-5x, single trade risk under 2% of account.
Q9: Can I run multiple strategies in parallel?
Yes. Each strategy sends a different strategy_id; the bridge routes to different sub-accounts or position pools.

🚀 Start your auto-trading journey

Register Binance with code BNAPP for lifetime fee rebate — high-frequency auto strategies save more.

Referral: BNAPP · APK: BNApp_F0000680.apk

Ready to start your Binance journey?

Sign up with referral code BNAPP for lifetime fee rebate

🔑 Sign Up 📱 Download 📚 Tutorials
QR

Scan to download

Download APK