Skip to content

Lightweight webhook server that receives TradingView alerts and forwards them to Telegram as plain text messages. Built with FastAPI, supports JSON and plain text alerts, and deploys easily to Railway/Render.

License

Notifications You must be signed in to change notification settings

medamine1920/tradingview-telegram-webhook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📡 TradingView → Telegram Webhook

Python FastAPI License Deploy on Railway

A lightweight, reliable webhook server that receives TradingView alerts and instantly forwards them to Telegram as clean, plain-text messages.


✨ Features

  • Instant Delivery — Alerts arrive in Telegram within seconds
  • Flexible Input — Accepts both JSON and plain text from TradingView
  • Variable Preservation — All TradingView placeholders ({{ticker}}, {{close}}, etc.) work perfectly
  • Clean Messages — Plain text only, no charts or link previews
  • Easy Deployment — One-click deploy to Railway, Render, or any VPS
  • Health Monitoring — Built-in endpoints for status checks

🚀 Quick Start

1. Create a Telegram Bot

  1. Open Telegram and message @BotFather
  2. Send /newbot and follow the prompts
  3. Copy your Bot Token
  4. Message your new bot (required to enable messaging)

2. Get Your Chat ID

  1. Message @userinfobot on Telegram
  2. Copy the Chat ID it returns

3. Deploy to Railway

Deploy on Railway

  1. Click the button above or go to railway.app
  2. Connect your GitHub repo
  3. Add environment variables:
    Variable Value
    TELEGRAM_BOT_TOKEN Your bot token from BotFather
    TELEGRAM_CHAT_ID Your chat ID
  4. Deploy and copy your public URL

4. Configure TradingView

  1. Open any chart on TradingView
  2. Create an alert (press Alt+A)
  3. In Notifications, enable Webhook URL
  4. Enter: https://your-app.up.railway.app/webhook
  5. Set your message template (see below)

📝 Alert Message Templates

Simple Alert

🚨 {{ticker}} @ {{close}}
{{interval}} timeframe

JSON Format (Recommended)

{
    "ticker": "{{ticker}}",
    "exchange": "{{exchange}}",
    "price": "{{close}}",
    "interval": "{{interval}}",
    "message": "🚨 {{ticker}} alert triggered at ${{close}}"
}

Strategy Alert

{
    "ticker": "{{ticker}}",
    "action": "{{strategy.order.action}}",
    "price": "{{strategy.order.price}}",
    "contracts": "{{strategy.order.contracts}}",
    "message": "{{strategy.order.comment}}"
}

📊 TradingView Placeholders

Placeholder Description
{{ticker}} Symbol (e.g., BTCUSDT)
{{exchange}} Exchange name
{{close}} Current/trigger price
{{open}} Open price
{{high}} High price
{{low}} Low price
{{volume}} Volume
{{time}} Alert trigger time
{{interval}} Timeframe (1m, 1h, 1D)
{{strategy.order.action}} buy/sell
{{strategy.order.price}} Order price
{{strategy.order.contracts}} Position size
{{strategy.order.comment}} Order comment

🔌 API Endpoints

Endpoint Method Description
/ GET Basic health check
/health GET Detailed status with config info
/webhook POST Main endpoint for TradingView alerts
/test POST Send a test message to Telegram

🖥️ Local Development

# Clone the repo
git clone https://github.com/YOUR_USERNAME/tradingview-telegram-webhook.git
cd tradingview-telegram-webhook

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Configure environment
cp .env.example .env
# Edit .env with your credentials

# Run server
uvicorn main:app --reload --port 5000

🐳 Docker

docker build -t tv-webhook .
docker run -d -p 8000:8000 \
  -e TELEGRAM_BOT_TOKEN=your_token \
  -e TELEGRAM_CHAT_ID=your_chat_id \
  tv-webhook

🔒 Security (Optional)

Add WEBHOOK_SECRET environment variable for additional security:

WEBHOOK_SECRET=your_random_secret_key

🛠️ Troubleshooting

Issue Solution
No messages in Telegram Verify bot token & chat ID. Make sure you messaged the bot first.
401 Unauthorized Bot token is incorrect
400 Bad Request Chat ID is wrong. Use /getUpdates to find correct ID
TradingView alerts not working Webhook requires TradingView Pro or higher

📄 License

MIT License — feel free to use for personal and commercial projects.


🤝 Contributing

Pull requests are welcome! For major changes, please open an issue first.


⭐ Star this repo if it helped you!

About

Lightweight webhook server that receives TradingView alerts and forwards them to Telegram as plain text messages. Built with FastAPI, supports JSON and plain text alerts, and deploys easily to Railway/Render.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published