Webhook Integration Guide
Real-Time TradingView Webhook Integration
Section titled “Real-Time TradingView Webhook Integration”The #1 onboarding challenge solved. This guide walks you through setting up real-time webhook integration between TradingView and Algo Trade Analytics.
Overview: Dual Webhook Strategy
Section titled “Overview: Dual Webhook Strategy”The most effective setup uses two webhooks from the same TradingView strategy:
- Execution Webhook → Trading platform (e.g., TraderPost → Alpaca)
- Analytics Webhook → Algo Trade Analytics (signal recording)
This allows you to:
- ✅ Execute trades via your preferred platform
- ✅ Record all signals in Algo Trade Analytics for analysis
- ✅ Compare intended signals vs actual execution
- ✅ Optimize strategy performance based on real data
Why Two Webhooks? You need one webhook for trade execution and another for analytics. Algo Trade Analytics focuses on performance analysis, not trade execution.
Part 1: Algo Trade Analytics Webhook Setup
Section titled “Part 1: Algo Trade Analytics Webhook Setup”Step 1: Create Webhook in Algo Trade Analytics
Section titled “Step 1: Create Webhook in Algo Trade Analytics”- Navigate to the trading dashboard
- Click “Webhook Management” in the sidebar
- Click “Create New Webhook”
- Enter a descriptive name (e.g., “My Strategy Analytics”)
- Copy the generated webhook URL
Your webhook URL format:
https://algo-trade-analytics.com/api/webhooks/wh_[unique_id]Step 2: Understand Authentication
Section titled “Step 2: Understand Authentication”Each webhook requires authentication via auth_key in the payload:
{ "auth_key": "your_unique_auth_key_here", // ... rest of your payload}Security Note: The
auth_keyis unique per webhook and required for all requests.
Step 3: Rate Limiting (Important!)
Section titled “Step 3: Rate Limiting (Important!)”Algo Trade Analytics is NOT built for High-Frequency Trading:
- Webhook Limit: 30 requests per minute
- Global Limit: 100 requests per 15 minutes
- Designed for: Strategy signals, not HFT scalping
If you exceed limits, you’ll receive a 429 error. This is intentional to ensure platform stability.
Part 2: TradingView Pine Script Configuration
Section titled “Part 2: TradingView Pine Script Configuration”Basic Webhook Alert Setup
Section titled “Basic Webhook Alert Setup”Configure your Pine Script strategy to send webhooks:
//@version=5strategy("My Strategy with Webhooks", overlay=true, calc_on_every_tick=true)
// Your strategy logic herelongCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
// Entry signals with webhook alertsif longCondition and strategy.position_size == 0 strategy.entry("Long", strategy.long) // Algo Trade Analytics Webhook alert('{"auth_key":"YOUR_AUTH_KEY","ticker":"' + syminfo.ticker + '","direction":"long","marketPrice":' + str.tostring(close) + ',"orderType":"market","qty":100,"positionIntent":"entryLong","metadata":{"strategy":"MA Crossover","signal":"Golden Cross","confidence":0.8,"timestamp":"' + str.tostring(time) + '"}}', alert.freq_once_per_bar)
if shortCondition and strategy.position_size == 0 strategy.entry("Short", strategy.short) // Algo Trade Analytics Webhook alert('{"auth_key":"YOUR_AUTH_KEY","ticker":"' + syminfo.ticker + '","direction":"short","marketPrice":' + str.tostring(close) + ',"orderType":"market","qty":100,"positionIntent":"entryShort","metadata":{"strategy":"MA Crossover","signal":"Death Cross","confidence":0.8,"timestamp":"' + str.tostring(time) + '"}}', alert.freq_once_per_bar)Advanced: Unified Dual Webhook Pine Script
Section titled “Advanced: Unified Dual Webhook Pine Script”This example shows how to create webhook functions that can format for either platform:
// ==================// WEBHOOK PLATFORM SELECTION// ==================g_platform = "Webhook Platform"i_webhookPlatform = input.string("Algo Trade Analytics", "Webhook Platform", options=["TraderPost", "Algo Trade Analytics"], group=g_platform, tooltip="Select the webhook platform format")
// ==================// WEBHOOK CONFIGURATION// ==================g_webhook = "Webhook Configuration"i_authKey = input.string("your_auth_key", "Webhook Auth Key", group=g_webhook)i_webhookQty = input.int(100, "Webhook Quantity", minval=1, group=g_webhook)
// ==================// UNIFIED WEBHOOK FUNCTIONS// ==================
// TraderPost webhook formatcreateTraderPostAlert(direction, orderType) => ticker = syminfo.ticker sentiment = direction == "buy" ? "bullish" : "bearish" baseMsg = '"ticker": "' + ticker + '", "action": "' + direction + '", "sentiment": "' + sentiment + '", "orderType": "' + orderType + '", "timeInForce": "gtc"' extrasMsg = '"message": "Strategy Entry", "price": ' + str.tostring(close) '{' + baseMsg + ', "extras": {' + extrasMsg + '}}'
// Algo Trade Analytics webhook formatcreateAlgoTradeAnalyticsAlert(side, orderType) => ticker = syminfo.ticker direction = side == "buy" ? "long" : "short" positionIntent = side == "buy" ? "entryLong" : "entryShort"
// Required fields requiredFields = '"auth_key": "' + i_authKey + '", "ticker": "' + ticker + '", "direction": "' + direction + '", "marketPrice": ' + str.tostring(close) + ', "qty": ' + str.tostring(i_webhookQty)
// Order configuration orderConfig = ', "orderType": "' + orderType + '", "positionIntent": "' + positionIntent + '"'
// Metadata metadata = ', "metadata": {"strategy": "Your Strategy", "signal": "Entry Signal", ' + '"signalPlatform": "tradingview", "brokerPlatform": "alpaca", ' + '"timestamp": "' + str.format_time(timenow, "yyyy-MM-dd'T'HH:mm:ss.000'Z'", "UTC") + '"}'
'{' + requiredFields + orderConfig + metadata + '}'
// Unified webhook creation that routes to the correct formatcreateUnifiedAlert(side, orderType) => if i_webhookPlatform == "TraderPost" createTraderPostAlert(side, orderType) else createAlgoTradeAnalyticsAlert(side, orderType)
// ==================// USAGE IN YOUR STRATEGY// ==================// In your entry/exit logic, use:// alert_message = createUnifiedAlert("buy", "market") // For long entries// alert_message = createUnifiedAlert("sell", "market") // For short entriesKey Benefits:
- ✅ Platform Switching: One dropdown to change webhook format
- ✅ Format Compliance: Each platform gets its expected structure
- ✅ Easy Integration: Drop these functions into any strategy
- ✅ Maintenance: Update webhook logic in one place
Part 3: TradingView Alert Configuration
Section titled “Part 3: TradingView Alert Configuration”Setting Up Dual Alerts
Section titled “Setting Up Dual Alerts”For Each Signal (Entry/Exit), Create TWO Alerts:
Alert 1: Execution Webhook
Section titled “Alert 1: Execution Webhook”- Condition: Your strategy → alert() function calls
- Webhook URL: Your execution platform URL (TraderPost, etc.)
- Message: Execution-focused payload
- Settings:
- Frequency: “Once Per Bar Close”
- Expiration: “Never”
Alert 2: Analytics Webhook
Section titled “Alert 2: Analytics Webhook”- Condition: Your strategy → alert() function calls
- Webhook URL: Your Algo Trade Analytics webhook URL
- Message: Analytics-focused payload (with auth_key)
- Settings:
- Frequency: “Once Per Bar Close”
- Expiration: “Never”
Advanced Alert Message Templates
Section titled “Advanced Alert Message Templates”Simple Market Order
Section titled “Simple Market Order”{ "auth_key": "YOUR_AUTH_KEY", "ticker": "{{ticker}}", "direction": "long", "marketPrice": {{close}}, "orderType": "market", "qty": 100, "positionIntent": "entryLong", "metadata": { "strategy": "{{strategy.order.comment}}", "signal": "Manual Entry", "timestamp": "{{time}}", "confidence": 0.8 }}Stop-Limit Order with Risk Management
Section titled “Stop-Limit Order with Risk Management”{ "auth_key": "YOUR_AUTH_KEY", "ticker": "{{ticker}}", "direction": "long", "marketPrice": {{close}}, "orderType": "stop_limit", "qty": 100, "stopPrice": {{close}}, "limitPrice": {{close}}, "timeInForce": "DAY", "positionIntent": "entryLong", "takeProfit": { "price": {{close * 1.02}}, "timeInForce": "GTC" }, "stopLoss": { "price": {{close * 0.98}}, "timeInForce": "GTC" }, "metadata": { "strategy": "Breakout Strategy", "signal": "Volume Spike", "signalPlatform": "tradingview", "brokerPlatform": "alpaca", "timestamp": "{{time}}", "confidence": 0.9, "riskLevel": "medium" }}Part 4: Testing Your Webhook Setup
Section titled “Part 4: Testing Your Webhook Setup”Using Algo Trade Analytics Webhook Tester
Section titled “Using Algo Trade Analytics Webhook Tester”- Navigate to Webhook Management
- Select your webhook
- Click “Test Webhook”
- Choose test mode:
- Single Test: Test one payload
- Bulk Test: Test multiple payloads from CSV
Manual Testing with cURL
Section titled “Manual Testing with cURL”Test your webhook directly:
curl -X POST https://algo-trade-analytics.com/api/webhooks/wh_your_id \ -H "Content-Type: application/json" \ -d '{ "auth_key": "your_auth_key", "ticker": "AAPL", "direction": "long", "marketPrice": 150.50, "orderType": "market", "qty": 100, "positionIntent": "entryLong" }'Expected Response:
{ "status": "success", "message": "Webhook processed successfully", "eventId": "evt_123456"}Common Testing Scenarios
Section titled “Common Testing Scenarios”- Market Order Entry: Basic buy/sell signals
- Stop-Limit Orders: Complex order types
- Risk Management: Orders with take profit/stop loss
- High Frequency: Test rate limiting (30/minute max)
- Error Handling: Invalid payloads, missing auth_key
Part 5: Monitoring & Troubleshooting
Section titled “Part 5: Monitoring & Troubleshooting”Webhook Event Log
Section titled “Webhook Event Log”Monitor all webhook activity in Algo Trade Analytics:
- Navigate to Webhook Management
- Select “Events” tab
- View real-time webhook deliveries
- Filter by webhook, date, or status
Common Issues & Solutions
Section titled “Common Issues & Solutions”❌ “Authentication Failed”
Section titled “❌ “Authentication Failed””Cause: Missing or invalid auth_key
Solution: Verify auth_key matches your webhook configuration
❌ “Rate Limit Exceeded”
Section titled “❌ “Rate Limit Exceeded””Cause: More than 30 requests per minute Solution: Reduce signal frequency or optimize your strategy
❌ “Invalid Payload Format”
Section titled “❌ “Invalid Payload Format””Cause: Malformed JSON or missing required fields
Solution: Validate JSON syntax and include required fields: auth_key, ticker, direction, marketPrice
❌ “Webhook Not Found”
Section titled “❌ “Webhook Not Found””Cause: Incorrect webhook URL Solution: Copy the correct URL from Algo Trade Analytics webhook management
❌ “TradingView Alert Not Firing”
Section titled “❌ “TradingView Alert Not Firing””Cause: Alert configuration or strategy issues Solution: Check strategy logic, calc_on_every_tick setting, and alert conditions
Part 6: Best Practices
Section titled “Part 6: Best Practices”Strategy Configuration
Section titled “Strategy Configuration”- ✅ Use
calc_on_every_tick=truefor real-time signals - ✅ Enable magnifier for accurate intrabar calculations
- ✅ Test in paper trading before going live
- ✅ Set reasonable position sizes for live trading
Webhook Optimization
Section titled “Webhook Optimization”- ✅ Include metadata for better analytics
- ✅ Use descriptive strategy names for organization
- ✅ Test webhook delivery before strategy deployment
- ✅ Monitor rate limits to avoid 429 errors
Error Handling
Section titled “Error Handling”- ✅ Implement retry logic in your execution platform
- ✅ Monitor webhook events for failed deliveries
- ✅ Set up alerts for webhook failures
- ✅ Keep backup logs of all signals
Part 7: Integration with Execution Platforms
Section titled “Part 7: Integration with Execution Platforms”TraderPost Integration Example
Section titled “TraderPost Integration Example”Execution Webhook (TraderPost format):
{ "ticker": "{{ticker}}", "action": "buy", "orderType": "market", "quantity": 100}Analytics Webhook (Algo Trade Analytics format):
{ "auth_key": "YOUR_AUTH_KEY", "ticker": "{{ticker}}", "direction": "long", "marketPrice": {{close}}, "orderType": "market", "qty": 100, "positionIntent": "entryLong", "metadata": { "executionPlatform": "traderpost", "signalPlatform": "tradingview" }}Alpaca Direct Integration (Future)
Section titled “Alpaca Direct Integration (Future)”Algo Trade Analytics plans to integrate with Alpaca Connect, eliminating the need for manual API setup. Users will authenticate directly through Alpaca’s platform.
Troubleshooting Workflow
Section titled “Troubleshooting Workflow”Step-by-Step Debugging
Section titled “Step-by-Step Debugging”-
Test Webhook Delivery
- Use Algo Trade Analytics webhook tester
- Verify payload format and auth_key
- Check rate limiting
-
Verify TradingView Configuration
- Confirm alert is active and not expired
- Check webhook URL is correct
- Validate JSON message syntax
-
Monitor Real-time Events
- Watch webhook events in real-time
- Check for error messages or failed deliveries
- Verify signal timing matches expectations
-
Compare with Execution Platform
- Check if execution webhook is working
- Compare signal timing between platforms
- Verify both webhooks receive same signals
Next Steps
Section titled “Next Steps”Once your webhook integration is working:
- Monitor Performance: Use Algo Trade Analytics to compare signals vs execution
- Optimize Strategy: Adjust Pine Script settings based on real performance
- Scale Up: Add more strategies with the same dual-webhook pattern
- Export Results: Use Pine Script export to visualize performance in TradingView
Related Documentation
Section titled “Related Documentation”- Strategy Configuration Guide - Optimize Pine Script for live trading
- Pine Script Export - Export results back to TradingView
- CSV Workflow - Alternative for historical analysis
- Knowledge Base - FAQ and troubleshooting