2025 Guide: Connect TradingView Webhook to Upstox/Zerodha
TradingView webhooks are an incredible tool for automating your trading strategies. Instead of manually executing trades based on alerts, you can set up a webhook to send a signal directly to your broker’s API. This is where the power of programmatic trading comes in, allowing for near-instantaneous execution and eliminating human error.
This guide will walk you through the process of connecting a TradingView webhook to two of India’s most popular brokers: Upstox and Zerodha. We’ll cover the essential concepts, provide code snippets, and highlight important considerations for a successful setup.

The Core Concepts: How it Works
Before we dive into the code, it’s crucial to understand the fundamental components of this automated workflow:
- TradingView Alert: This is the trigger. You create an alert on TradingView based on your Pine Script strategy or an indicator. When the alert’s conditions are met (e.g., a moving average crossover), it sends a signal.
- Webhook URL: This is the destination for the TradingView signal. Instead of sending a notification to your email or mobile, the alert is configured to send an HTTP POST request to a specific URL.
- API Bridge/Server: This is the “middleman.” Since Upstox and Zerodha’s APIs don’t directly accept TradingView webhooks, you need a small server or a third-party API bridge to receive the webhook and translate it into a valid API request for your broker. This server will contain the logic to parse the webhook message, authenticate with your broker, and place the order.
- Broker API: This is the engine. You use the official developer APIs provided by Upstox (Upstox Developer API) or Zerodha (Kite Connect API) to place, modify, and manage orders.

🛠️ Step 1: Setting up Your Broker’s Developer Account
The first and most important step is to get your hands on the necessary API credentials. Both Upstox and Zerodha require you to create a developer account and an “app” to get your API key and secret.
Zerodha (Kite Connect API)
- Sign Up: Go to the Kite Connect developer portal and sign up for an account.
- Choose a Plan: Zerodha offers a “Personal API” plan which is free but does not include live market data. The “Paid API” costs ₹500/month and provides all features, including historical and live data. For automated trading, the paid plan is usually necessary.
- Create Your App: Navigate to “My Apps” and create a new app. You’ll need to provide an App Name, your Zerodha Client ID, and a Redirect URL. This URL is crucial for the OAuth authentication flow. You can use a local host URL for testing (e.g.,
http://127.0.0.1:8000). - Get Credentials: Once your app is created, you will be given an API Key and API Secret. Keep these secure, as they are your access to the API.
Upstox (Upstox Developer API)
- Sign Up: Head over to the Upstox developer website.
- Create Your App: Similar to Zerodha, you’ll need to create a new app. Provide a name, and importantly, configure the Redirect URI. This URL is where the user will be redirected after authentication. Upstox also has a
postback URLoption, which is where you can receive real-time order updates. - Get Credentials: After creating the app, you will receive your API Key and API Secret.
🖥️ Step 2: Building the API Bridge (Node.js Example)
This is where the coding begins. You need a server-side application to act as the webhook receiver. We’ll use Node.js and the Express framework for this example.
First, set up a new Node.js project and install the necessary libraries:
Bash
npm init -y
npm install express body-parser axios
Next, create a file named server.js and add the following code. This is a generic template; you’ll need to adapt it for your specific broker and trading logic.
JavaScript
// server.js
const express = require('express');
const bodyParser = require('body-parser');
const axios = require('axios');
const app = express();
const PORT = 3000;
// Upstox/Zerodha API credentials
const API_KEY = 'YOUR_API_KEY';
const API_SECRET = 'YOUR_API_SECRET';
const REDIRECT_URI = 'YOUR_REDIRECT_URI'; // This is for authentication flow
// This will be your long-lived access token, get it after the initial OAuth flow
let ACCESS_TOKEN = 'YOUR_ACCESS_TOKEN';
app.use(bodyParser.json());
// Main webhook endpoint
app.post('/tradingview-webhook', async (req, res) => {
try {
console.log('Webhook received:', req.body);
// Your TradingView alert message should contain the trade details
const tradeData = req.body;
// Example message format from TradingView:
// {
// "symbol": "NSE:RELIANCE",
// "action": "BUY",
// "quantity": 1
// }
// --- Add Your Trading Logic Here ---
// Validate the incoming data, check for security keys, etc.
// Prepare the order payload for your broker's API
let orderPayload = {};
// --- Example for Zerodha (Kite Connect) ---
// orderPayload = {
// "tradingsymbol": tradeData.symbol,
// "exchange": "NSE",
// "transaction_type": "BUY",
// "order_type": "MARKET",
// "quantity": tradeData.quantity,
// "product": "CNC"
// };
// const zerodhaApiUrl = "https://api.kite.trade/orders/regular";
// const headers = { "X-Kite-Version": "3", "Authorization": `token ${API_KEY}:${ACCESS_TOKEN}` };
// --- Example for Upstox ---
orderPayload = {
"order_type": "MARKET",
"quantity": tradeData.quantity,
"product": "I", // I for Intraday, C for CNC
"instrument_token": "NSE_EQ|INE002A01018", // You need to fetch this beforehand
"transaction_type": "BUY",
"price": 0,
"trigger_price": 0
};
const upstoxApiUrl = "https://api.upstox.com/v2/order/place";
const headers = { "Authorization": `Bearer ${ACCESS_TOKEN}` };
// --- End of Broker-specific Configuration ---
// Send the order to the broker's API
const response = await axios.post(upstoxApiUrl, orderPayload, { headers });
console.log('Order placed successfully:', response.data);
res.status(200).send('Order placed successfully');
} catch (error) {
console.error('Error processing webhook:', error.response ? error.response.data : error.message);
res.status(500).send('Error processing webhook');
}
});
app.listen(PORT, () => {
console.log(`Webhook server listening on port ${PORT}`);
});
📢 Step 3: Configuring the TradingView Alert
Once your API bridge is running, the final step is to configure your TradingView alert to send the data to it.
- Open the Alert Menu: On TradingView, click the “Create Alert” button.
- Condition: Set the condition for your alert (e.g., your custom Pine Script strategy).
- Notification: In the “Notifications” tab, tick the checkbox for “Webhook URL.”
- Enter the URL: Enter the public URL of your server. If you’re running it locally, you’ll need a tool like ngrok to expose your localhost to the internet. The URL would look something like
https://your-public-ngrok-url.ngrok.io/tradingview-webhook. - Alert Message: This is the most critical part. In the “Message” box, use the correct JSON format that your server is expecting. For our example, a simple JSON payload will do:JSON
{ "symbol": "{{ticker}}", "action": "{{strategy.order.action}}", "quantity": 1 }{{ticker}}: TradingView’s placeholder for the instrument’s symbol.{{strategy.order.action}}: A dynamic placeholder from Pine Script that will be “buy” or “sell.”
- Create: Click “Create” and your webhook is live!
✅ Important Considerations and Best Practices
- Security: Never expose your API keys or secrets in the client-side code. Your server-side bridge acts as a secure intermediary. Additionally, consider adding a custom security token to your webhook message to verify that the request is coming from your TradingView account and not a malicious source.
- Access Token Management: API access tokens expire. You need to implement a mechanism in your server to refresh the token periodically. Both Zerodha and Upstox have clear documentation on how to do this via their API.
- Error Handling: Robust error handling is non-negotiable. What happens if the broker’s API is down? What if the order is rejected? Your server should log errors and, if possible, have a retry mechanism.
- Position Sizing and Risk Management: The code above is a basic example. In a real-world scenario, your server should handle position sizing, stop-loss, and target orders based on your risk management rules.
- Broker-Specific Differences: The API payloads for Zerodha and Upstox are different. Upstox uses
instrument_token, while Zerodha usestradingsymbolandexchange. You’ll need to fetch and manage these details.
This guide provides the technical foundation for a powerful automated trading system. By combining the alerting capabilities of TradingView with the robust APIs of Upstox and Zerodha, you can build a reliable and efficient trading bot that executes your strategies around the clock.
This video provides an overview of how a TradingView webhook can be used to automate trading.
<br> TradingView to Broker API Automation
5️⃣ Supported Brokers in India
| Broker | API Available | Notes |
|---|---|---|
| Upstox | Yes | REST API + Websocket |
| Zerodha | Yes | Kite Connect API (Python/Node/Java) |
| Angel One | Yes | Angel API for Algo Trading |
| ICICI Direct | Limited | Web-based triggers only |
| Groww | Limited | No official public API |
6️⃣ FAQ for Indian Traders (SEO Optimized)
Q1: Can I trade multiple stocks automatically?
Yes! Your webhook server can process multiple symbols from TradingView alerts.
Q2: Do I need coding experience?
Basic Python knowledge helps. You can also hire developers for setup.
Q3: Is it safe to connect TradingView with Upstox/Zerodha?
Yes, as long as you keep your API keys secure and use HTTPS endpoints.
Q4: Can I use this with intraday strategies?
Absolutely, webhooks are real-time, perfect for intraday trading.
7️⃣ Tips for 2025 Auto Trading Success
- Test your webhook with paper trading first.
- Keep API keys safe, rotate tokens monthly.
- Use logging + alerts for failed trades.
- Combine multiple strategies for better returns.
- Repurpose this guide to YouTube tutorials + Instagram Reels to attract clients.
8️⃣ Conclusion
Automating trades with TradingView webhooks and Indian brokers like Upstox/Zerodha is now easier than ever. With this 2025-ready setup, you can execute trades instantly, accurately, and securely, freeing you from manual monitoring and maximizing your market opportunities.
CTA:
Need expert help to automate your trades in 3 minutes? Contact Jayadev Rana – Pine Script & Algo Trading Expert today and start auto trading effortlessly!

TradingView webhook Upstox, TradingView webhook Zerodha, auto trading India, Pine Script automation, Upstox API, Zerodha Kite Connect, Indian stock market auto trade
