to set up a system to send TradingView signals to WhatsApp.
Here's how you can approach this:
Create a TradingView alert
Use a webhook to send the alert data
Process the data and forward it to WhatsApp
There are a few methods to accomplish this:
Option 1: Use a third-party service
Services like Zapier, Make (formerly Integromat), or Pabbly Connect can connect TradingView to WhatsApp. These platforms offer pre-built templates to automate this workflow without coding knowledge.
Option 2: Set up your own webhook server
# Python script to relay TradingView signals to WhatsApp
import flask
from flask import request, Flask
import requests
import json
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# WhatsApp Business API credentials
WHATSAPP_TOKEN = os.getenv("WHATSAPP_TOKEN")
WHATSAPP_PHONE_ID = os.getenv("WHATSAPP_PHONE_ID")
RECIPIENT_PHONE = os.getenv("RECIPIENT_PHONE") # Phone number to receive alerts
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def webhook():
try:
# Parse the incoming JSON data from TradingView
data = request.json
# Format the trading signal message
symbol = data.get('symbol', 'Unknown')
action = data.get('action', 'Unknown')
price = data.get('price', 'Unknown')
message = f"🔔 TRADING SIGNAL 🔔nn"
message += f"Symbol: {symbol}n"
message += f"Action: {action}n"
message += f"Price: {price}n"
# Additional data if available
if 'strategy' in data:
message += f"Strategy: {data['strategy']}n"
if 'interval' in data:
message += f"Timeframe: {data['interval']}n"
# Send the message to WhatsApp
send_whatsapp_message(message)
return "Signal received and sent to WhatsApp", 200
except Exception as e:
print(f"Error processing webhook: {str(e)}")
return f"Error: {str(e)}", 500
def send_whatsapp_message(message):
url = f"https://graph.facebook.com/v17.0/{WHATSAPP_PHONE_ID}/messages"
headers = {
"Authorization": f"Bearer {WHATSAPP_TOKEN}",
"Content-Type": "application/json"
}
data = {
"messaging_product": "whatsapp",
"to": RECIPIENT_PHONE,
"type": "text",
"text": {
"body": message
}
}
response = requests.post(url, headers=headers, data=json.dumps(data))
print(f"WhatsApp API Response: {response.status_code} - {response.text}")
return response
if __name__ == "__main__":
# For production, use a proper WSGI server like Gunicorn instead
app.run(host='0.0.0.0', port=5000)
How to set it up:
TradingView Alert Configuration:
Create an alert in TradingView
Set the alert to use a webhook
Format the alert message as JSON with fields like symbol, action, price
WhatsApp Integration Options:
WhatsApp Business API (shown in the code)
Twilio API for WhatsApp
WhatsApp Cloud API
Hosting Options:
Heroku, PythonAnywhere, or Railway for the webhook server
AWS Lambda for a serverless approach
Any VPS that can run Python applications
You'll need to register for the WhatsApp Business API to use the official integration method. Alternatively, you could use unofficial libraries like pywhatkit or integrate with Twilio's WhatsApp service which is easier to set up for small-scale use.