Trading Portal
Home

Connect TradingView

Connect TradingView

This guide walks through connecting TradingView alerts to Trading Portal: creating a webhook, configuring the alert message, and sending authenticated POST requests.

Prerequisites

  1. A Trading Portal account with an active subscription (see Pricing).
  2. A publicly reachable app URL (for local testing, use ngrok or Cloudflare Tunnel and set BETTER_AUTH_URL to that HTTPS origin).
  3. At least one webhook created under App → Webhooks.

1. Create a webhook

  1. Sign in and open Webhooks (/app/webhook).
  2. Click Create webhook, choose a label (e.g. BTC, ETH, FOREX), and optionally set asset class or allowed tickers.
  3. Copy the webhook URL and secret when shown. The secret is only displayed once after create or rotate — store it securely.

Your endpoint URL looks like:

POST https://your-domain.example/api/webhooks/tradingview/<webhookId>

2. Canonical alert JSON

Trading Portal validates every alert against this shape. Field names must match exactly (lowercase keys):

{
  "id": "Long Take Profit",
  "time": "2026-05-28T18:00:00Z",
  "timenow": "2026-05-28T18:07:46Z",
  "action": "sell",
  "ticker": "SOLUSDT",
  "price": "82.66",
  "contracts": "160.45",
  "position_size": "0",
  "position_type": "flat",
  "comment": "Long Take Profit",
  "interval": "60",
  "exchange": "BINANCE"
}
FieldRequiredNotes
idyesStrategy or alert name; stored as strategy metadata
timeyesSignal time (ISO 8601) → signalAt
timenowyesIngest metadata; stored in raw payload
actionyesbuy or sell (close semantics use position_type)
tickeryesSymbol, e.g. SOLUSDT
priceyesString decimal
contractsyesSize / quantity as string decimal
position_size, position_typeyesPosition state for analytics
comment, interval, exchangeyesexchange is mapped case-insensitively (e.g. BINANCEbinance)

TradingView can send the body as application/json or as a raw JSON string; both are accepted.

TradingView placeholders

In the alert Message box, you can mix static JSON with TradingView placeholders, for example:

{
  "id": "{{strategy.order.id}}",
  "time": "{{timenow}}",
  "timenow": "{{timenow}}",
  "action": "{{strategy.order.action}}",
  "ticker": "{{ticker}}",
  "price": "{{close}}",
  "contracts": "{{strategy.order.contracts}}",
  "position_size": "{{strategy.position_size}}",
  "position_type": "{{strategy.market_position}}",
  "comment": "{{strategy.order.comment}}",
  "interval": "{{interval}}",
  "exchange": "{{exchange}}"
}

Adjust placeholders to match your strategy; the server still requires all keys listed above after TradingView substitutes values.

3. Authentication in the webhook URL

TradingView webhook alerts do not support custom request headers. Every request must include your webhook secret as a query parameter on the URL:

https://your-domain.example/api/webhooks/tradingview/YOUR_WEBHOOK_ID?secret=YOUR_SECRET

Trading Portal also accepts X-Webhook-Secret and Authorization: Bearer <secret> for curl/proxy tests, but TradingView users should paste the URL with ?secret=....

Requests with a missing or wrong secret receive 401 Invalid webhook secret.

4. Configure the TradingView alert

  1. On your chart, create or edit an Alert.
  2. Under Notifications, enable Webhook URL and paste the full URL with ?secret=YOUR_SECRET.
  3. Set Message to the canonical JSON (or placeholder version) from §2.
  4. Save the alert and trigger a test (or wait for the condition).

5. Verify ingestion

  1. Open Trades (/app/trades) and confirm a new row appears.
  2. Or run this curl from your machine (replace URL, secret, and JSON):
curl -sS -X POST "https://your-domain.example/api/webhooks/tradingview/YOUR_WEBHOOK_ID?secret=YOUR_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "Manual test",
    "time": "2026-05-28T18:00:00Z",
    "timenow": "2026-05-28T18:07:46Z",
    "action": "buy",
    "ticker": "SOLUSDT",
    "price": "82.66",
    "contracts": "1",
    "position_size": "1",
    "position_type": "long",
    "comment": "curl test",
    "interval": "60",
    "exchange": "BINANCE"
  }'

Success (200):

{ "ok": true, "tradeId": "trade_..." }

Duplicate alert (idempotent retry):

{ "ok": true, "tradeId": "trade_...", "duplicate": true }

6. HTTP responses

StatusMeaning
200Trade stored (or duplicate acknowledged)
400Invalid JSON / schema / ticker not on allowlist — body includes issues when validation fails
401Invalid or missing secret
404Unknown or inactive webhook ID
429Rate limit exceeded — retry after Retry-After seconds
500Server error — contact support if persistent

7. Multiple webhooks

Create separate webhooks per asset or strategy (e.g. BTC, ETH, FOREX). Each has its own URL, secret, optional ticker allowlist, and trade history dimension in analytics.

8. Security tips

Next steps