# Alerts and Webhooks

> How price alerts and webhooks work, how to send TradingView alerts to your own server or a chat channel, and how to secure webhook endpoints against fake signals.

Source: https://learn.tradelabsai.com/programming/alerts-and-webhooks/  
Track: Programming and Data · Level: Intermediate · Updated: 2026-10-03  
Publisher: TradeLabs AI (https://tradelabsai.com). Education, not financial advice.  
Cite as: TradeLabs Learn, "Alerts and Webhooks", https://learn.tradelabsai.com/programming/alerts-and-webhooks/

An alert tells you that something happened: price crossed a level, an indicator triggered or your bot hit an error. A webhook is a way for one system to send that message to another automatically, as an HTTP request to a URL. Together, alerts and webhooks let traders connect charting platforms, bots, servers and chat apps without writing a full trading system. They are the glue behind many semi automated setups, and also the basis of the monitoring that keeps fully automated systems safe.

## Types of trading alerts

| Alert | Example | Lesson |
|---|---|---|
| Price | BTC crosses $100,000 | [Support and Resistance](https://learn.tradelabsai.com/price-action/support-and-resistance/) |
| Indicator | RSI drops below 30 | [RSI (Relative Strength Index)](https://learn.tradelabsai.com/indicators/rsi/) |
| Strategy signal | Moving average crossover | [Pine Script Basics](https://learn.tradelabsai.com/programming/pine-script-basics/) |
| Account | Margin usage above 50% | [Margin](https://learn.tradelabsai.com/markets/margin/) |
| System health | Bot has not sent a heartbeat in 2 minutes | [Monitoring Positions, P&L and Risk](https://learn.tradelabsai.com/algo-trading/live-monitoring/) |
| Risk | Daily loss limit reached | [Maximum Trade Risk and Daily Loss Limits](https://learn.tradelabsai.com/risk/daily-loss-limit/) |

## How a webhook works

1. You give a service, such as TradingView, a URL that belongs to your server or another app.
2. When the alert fires, the service sends an HTTP POST request to that URL with a message body, usually JSON.
3. Your server receives the message, checks it and acts: logs it, sends a notification or passes it to a bot.

## A TradingView alert message

TradingView lets you write the alert message, with placeholders that fill in live values:

```
{
  "secret": "replace-with-a-long-random-value",
  "strategy": "sma-cross",
  "ticker": "{{ticker}}",
  "action": "{{strategy.order.action}}",
  "price": "{{close}}",
  "time": "{{timenow}}"
}
```

TradingView webhooks require a paid plan and send requests to the URL you enter in the alert settings. See [TradingView](https://learn.tradelabsai.com/industry/tradingview/).

## A minimal receiver

```python
from flask import Flask, request, abort
import hmac, os

app = Flask(__name__)
SECRET = os.environ["WEBHOOK_SECRET"]

@app.post("/hook")
def hook():
    data = request.get_json(silent=True) or {}
    if not hmac.compare_digest(str(data.get("secret", "")), SECRET):
        abort(403)
    handle_signal(data)     # validate fields, check risk, then act
    return "ok"
```

## Securing webhook endpoints

Anyone who learns your webhook URL can send it messages. If those messages place trades, that is a serious risk.

- **Use HTTPS** so messages cannot be read in transit.
- **Include a secret** in the message or header and reject anything without it.
- **Validate every field:** known symbols, allowed actions, sensible sizes.
- **Reject stale messages** using the timestamp, and ignore duplicates.
- **Never let a webhook bypass risk checks.** See [Risk Controls and Kill Switches](https://learn.tradelabsai.com/algo-trading/risk-controls-and-kill-switches/).
- **Keep the secret out of code** and screenshots, and rotate it if exposed.

**Example: A delayed alert**
A webhook signal to buy arrives at a trader's server 40 seconds after it was generated, because of a brief network delay. The alert says buy at $64.20, but the market is now $65.10, about 1.4% higher. The receiver compares the alert's timestamp with the current time and the alert price with the current price, sees the alert is older than its 15 second limit and the price has moved beyond its 0.5% tolerance, and skips the trade with a logged warning. Without those checks, the bot would have chased a stale signal.

## Sending alerts to chat

Many traders route alerts to a phone through messaging apps. Discord, Slack and Telegram all accept messages from programs, either through incoming webhooks or bot APIs. This is a simple way to get bot health and trade notifications on your phone. Keep chat webhook URLs private, since anyone with the URL can post to the channel.

## Avoiding alert overload

Too many alerts lead to ignoring them. Keep alerts actionable, group related ones and review which alerts you actually act on. See [Monitoring Positions, P&L and Risk](https://learn.tradelabsai.com/algo-trading/live-monitoring/).

## Frequently asked questions

### What is a webhook in trading?

An automatic HTTP message sent from one system to another when an event happens, such as a TradingView alert sending a signal to a trading bot.

### Can TradingView alerts place trades automatically?

They can send webhooks to services or your own server that place trades; TradingView itself does not place trades through webhooks.

### How do I secure a trading webhook?

Use HTTPS, require a secret, validate every field, reject stale or duplicate messages and keep risk checks in place.

Next, learn the institutional standard for order messaging in [FIX Protocol](https://learn.tradelabsai.com/programming/fix-protocol/).

## Continue learning

- Next lesson: [FIX Protocol](https://learn.tradelabsai.com/programming/fix-protocol/)
- Previous lesson: [Building Trading Bots](https://learn.tradelabsai.com/programming/building-trading-bots/)
- Related: [Building Trading Bots](https://learn.tradelabsai.com/programming/building-trading-bots/): How to build a trading bot that is safe to run: the main components, an event loop, state and position tracking, risk checks, logging and a staged path to live.
- Related: [Pine Script Basics](https://learn.tradelabsai.com/programming/pine-script-basics/): Learn Pine Script, TradingView's language for custom indicators, strategies and alerts. Covers series, plots, inputs, a crossover strategy and common pitfalls.
- Related: [Monitoring Positions, P&L and Risk](https://learn.tradelabsai.com/algo-trading/live-monitoring/): Running algorithms need constant monitoring. Learn the key health, trading and risk metrics to track, how to design useful alerts and how to avoid alert fatigue.
- Related: [Automated vs Semi-Automated Trading](https://learn.tradelabsai.com/algo-trading/automated-trading/): Automated trading systems place and manage orders without manual input. Learn levels of automation, platforms, what to automate first and the safeguards.
- Related: [TradingView](https://learn.tradelabsai.com/industry/tradingview/): TradingView is a browser based charting and social platform covering stocks, crypto, forex and futures. Learn its features, Pine Script, alerts, plans and limits.
