MagicTradeBot TradingView Integration Guide (Complete Setup with NATS & Webhooks)

1. Overview

MagicTradeBot can receive trade signals directly from TradingView indicators, strategies, and Pine Script alerts. Once a signal arrives it goes through the same execution engine as internal bot signals — order placement, DCA, smart decisions, and broadcast notifications all work identically.

Three components work together:

  • 🔗 tv-signal-bridge — standalone Axum service that receives TradingView webhooks, validates the secret, normalises the symbol, and publishes to NATS
  • 📡 NATS JetStream — lightweight message broker running in Docker that carries signals from the bridge to the bot with at-least-once delivery
  • 🤖 MagicTradeBot signal listener — subscribes to NATS, deduplicates, runs gatekeeper checks, then calls sync_bot_scan_result
INFO
External TV signals are first-class citizens. Once the signal key is registered in signal_registry.yaml, the bot treats it identically to TOP_GAINER_LONG_SIGNAL or any other internal signal.

2. Signal Key Format

Every TradingView signal produces a key in this format:

TV_{STRATEGY}_{SIDE}_EXTERNAL_SIGNAL

SettingResulting Signal Key
strategy: EMA_CROSS side: longTV_EMA_CROSS_LONG_EXTERNAL_SIGNAL
strategy: RSI_DIV side: shortTV_RSI_DIV_SHORT_EXTERNAL_SIGNAL
strategy: SUPERTREND side: longTV_SUPERTREND_LONG_EXTERNAL_SIGNAL

3. Prerequisites

  • MagicTradeBot installed and running
  • tv-signal-bridge binary built and available
  • Docker Desktop installed and running (for NATS)
  • TradingView paid plan — Essential or higher
  • A public URL or IP so TradingView can reach the bridge

4. Setup

4.1 Start NATS via Docker

docker run -d \
  --name nats \
  --restart unless-stopped \
  -p 4222:4222 \
  -p 8222:8222 \
  nats:latest -js

4.2 Configure tv-signal-bridge

Edit config/config.toml:

[bridge]
bot_name    = "MagicTradeBot-1"
hmac_secret = "your-long-secret-here"

[stream]
backend  = "nats"
nats_url = "nats://127.0.0.1:4222"
subject  = "trade.signals"

[symbols.mappings]
"BTCUSDT" = "BTC/USDT"
"ETHUSDT" = "ETH/USDT"

4.3 Start tv-signal-bridge

# Windows
./tv-signal-bridge-win.exe

# Linux / macOS
./tv-signal-bridge-linux

4.4 Register signal keys in signal_registry.yaml

register_trading_signals:
  - "TV_EMA_CROSS_LONG_EXTERNAL_SIGNAL"

register_broadcast_signals:
  - "TV_EMA_CROSS_LONG_EXTERNAL_SIGNAL"

4.5 Enable TV signals in MagicTradeBot

Edit settings/tradingview.yaml:

enabled: true
bot_name: "MagicTradeBot-1"
stream_backend: "nats"
nats_url: "nats://127.0.0.1:4222"
subject: "trade.signals"

5. TradingView Alert Setup

Webhook URL:

https://your-server.com:8090/webhook/tradingview

Message (JSON):

{
  "secret":     "your-long-secret-here",
  "symbol":     "{{ticker}}",
  "side":       "long",
  "strategy":   "EMA_CROSS",
  "confidence": 80.0,
  "timestamp":  {{timenow}}
}

6. Testing Without TradingView

PowerShell Test (Windows)

$timestamp = [int]([DateTimeOffset]::UtcNow.ToUnixTimeSeconds())

$body = @{
    secret     = "your-long-secret-here"
    symbol     = "BTCUSDT"
    side       = "long"
    strategy   = "EMA_CROSS"
    confidence = 85.0
    timestamp  = $timestamp
} | ConvertTo-Json

Invoke-RestMethod -Uri "http://localhost:8090/webhook/tradingview" `
  -Method POST -Body $body -ContentType "application/json"

7. Verifying the Full Chain

Check bridge logs → bot logs → Discord/Telegram notification → database trade record.

8. Configuration Reference

9. Troubleshooting

SymptomFix
Bridge returns 401 INVALID_SECRETSecret mismatch — copy exactly
Signal arrives at bridge but not at botCheck enabled: true and restart bot
'bot_name mismatch'bot_name must be identical in both config files

10. Quick Reference Checklist

  • Docker Desktop running
  • NATS container started with -js
  • Bridge running on port 8090
  • Signal keys registered in signal_registry.yaml
  • tradingview.yaml enabled with matching bot_name
  • Tested with curl / PowerShell
  • Notification and trade created successfully

📎 Related Topics