Trading
DEX TradingView Webhooks
9 min read
What it is
Connect TradingView alerts to DEX execution via pre-signed buy/sell pools. When TradingView fires an alert with action=buy or action=sell, the webhook pulls one pre-signed order from the matching pool and submits it to CoW or Velora. Gas-free fills. Two-sided pool with separate buy / sell capacity. Secret authentication via either JSON body field OR HMAC-SHA256 header (for n8n / Pipedream / custom relays).
How to think about it
DEX TV Webhooks is the DEX counterpart to CEX TradingView Webhooks. The mechanism is very different: CEX queues market orders for the executor to place via API; DEX pulls a pre-signed order out of a pool that you signed upfront. The DEX version is gas-free on fills (solvers absorb gas) but requires more upfront signing. Live-validated May 2026 on Base with the validTo-stagger fix for the CoW DuplicatedOrder error on identical-param pools.
Step-by-step
-
Pick protocol + chain + pair
Protocol = CoW (Eth/Arb/Base) or Velora (adds Polygon/BSC/Optimism/Avalanche). Chain from the dropdown. Sell + Buy tokens — both buy-side and sell-side cycles use the same token pair (just flipped direction).
-
Set per-cycle amount
How much to swap on each fire. e.g., 25 USDC per buy cycle means each TradingView "buy" alert fires a 25 USDC → WETH swap. Sell cycles use the same notional in the other direction. Pick based on (max-tolerable-per-alert × pool-size = total commitment).
-
Pick pool size (5 / 10 / 20 each side)
5 each side = 10 total cycles = 20 EIP-712 signatures. 10 each side = 20 cycles = 40 sigs. 20 each side = 40 cycles = 80 sigs. Pool depletes as TradingView fires alerts — refill when low.
-
Sign approval + N×2 cycles per side
First-time spend-token: ERC-20 approval (gas, one-time). Then N buy cycles × signatures + N sell cycles × signatures. 10 each side = 20 popups. Be ready for the cadence. Each signed cycle has its own validTo staggered by 1 second to avoid CoW DuplicatedOrder error.
-
Copy URL + secret from the reveal modal
After commit, a one-time modal shows your webhook URL + secret. Copy BOTH immediately — the secret is only visible once. Paste the URL into TradingView Alert → Notifications → Webhook URL. Paste the JSON template into the Message field: `{"action":"buy","secret":"<your_secret>"}`. Replace "buy" with "sell" for sell-side alerts.
-
Test from the row + watch fires
The bot row has a Test button that fires a fake alert end-to-end to validate the pool wiring. Real TradingView alerts then fire via the webhook URL — each pulls one pre-signed order from the matching action pool. Two-side capacity bar shows remaining buys / sells separately.
-
Refill when pool runs low
When buy or sell pool runs ≤30% remaining, the capacity bar turns amber. Click Refill to add +1 cycle of each side (or buy-only / sell-only). Same signing UX as initial setup.
Tips & pitfalls
- Body-secret vs HMAC dual auth: simple setups paste the secret in the JSON body. Advanced setups (n8n, Pipedream, custom relay servers) can omit it from the body and send HMAC-SHA256 of the body in the X-Webhook-Signature header instead — better security because the secret never travels in the payload.
- The webhook URL is path-based (`/dex/tv/<key>`) — there is no Bearer token. Anyone with the URL + secret can fire the webhook, so keep them BOTH private.
- Live-validated May 2026 on Base. The page handles the CoW "DuplicatedOrder" rejection by staggering validTo timestamps by 1 second per signed order — if you build your own DEX pool elsewhere, you must do the same or CoW rejects all but the first.
- Two-side pool means buy and sell capacity are independent. A heavy buy week can drain the buy pool while sells stay full. Refill the depleted side separately if you don't want to over-commit signatures.
- TradingView Pine Script: any strategy that emits alerts with "buy"/"sell" actions can drive this. Useful for "buy when RSI < 30 AND EMA9 crosses EMA20" type strategies that are easy to author in Pine but hard to encode anywhere else.
- For ONE-OFF execution, use DEX Swap directly. For RECURRING fills on a schedule, use DEX DCA. TV Webhooks is for EVENT-DRIVEN execution where the trigger is a TradingView indicator you defined.
- Test button on the row sends a synthetic alert end-to-end (URL → secret check → pool pull → submission). Use it after every Refill to confirm the new orders are wired correctly before TradingView fires for real.
- Delete vs Pause: Delete removes the webhook URL (TradingView alerts fail thereafter). Pause keeps the URL but rejects fires. Use Pause for temporary blackouts; Delete for permanent retirement.