Skip to content

About

TradingView alert webhook to websocket bridge.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

About

Catch TradingView alert webhooks and bridge them to local trading tools over WebSocket.

Webhook bodies must be JSON and include a channel secret. Clients subscribe on the WebSocket with a channel secret and only receive alerts for that channel.

TradingView docs: About webhooks.

Protocol

HTTP webhook — POST /webhook

{"secret":"changeme-crypto-secret","symbol":"BTCUSDT","side":"buy"}

Only valid JSON is accepted. Requests must come from TradingView IPs (unless DEBUG=true). Unknown secret → 401. The secret field is stripped before broadcast; channel is added.

You can put anything in the JSON payload, this program only needs the secret attribute set.

WebSocket — /ws

  1. Connect
  2. Send: {"action":"subscribe","secret":"changeme-crypto-secret"}
  3. Receive ack: {"status":"ok","channel":"crypto"}
  4. Receive forwarded alert JSON for that channel only (without secret)

Channels config

Secrets live in channels.json (mounted into the container). Copy the example and edit:

cp channels.example.json channels.json
{
  "channels": {
    "default": "changeme-default-secret",
    "crypto": "changeme-crypto-secret"
  }
}

Each key is a channel name; each value is that channel’s secret. Secrets must be unique.

Configuration

Copy .env.template to .env (optional overrides).

Variable Description
CHANNELS_CONFIG Path to channels JSON (default channels.json; Docker: /app/channels.json)
DEBUG true skips TradingView IP allowlist
HTTP_HOST / HTTP_PORT Bind address (default 0.0.0.0:8000)

Local (UV)

cp channels.example.json channels.json
cp .env.template .env
uv sync
uv run python main.py

Test client (set secret to a channel from channels.json):

WEBHOOK_SECRET=changeme-crypto-secret uv run python websocketTest.py

Docker

Use install.sh script to create a new instance using docker in a new folder with a new random token.

Caddy for HTTPS

Simple reverse proxy configuration for caddy.

webhook.example.com {
	reverse_proxy 127.0.0.1:8000
}

Endpoints:

  • https://webhook.example.com/webhook
  • wss://webhook.example.com/ws

TradingView only allows ports 80 and 443.

About

TradingView alert webhook to websocket bridge.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages