14 - TradingView & GoCharting
Overview
OpenAlgo integrates with TradingView and GoCharting platforms to receive trading signals via webhooks. These charting platforms can trigger automated trades when alert conditions are met.
Architecture Diagram
┌───────────────────────────────────────────────────────────────────────────────┐
│ TradingView / GoCharting Integration │
└───────────────────────────────────────────────────────────────────────────────┘
┌───────────────────────────────────────────────────────────────────────────────┐
│ TradingView / GoCharting │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ Pine Script Strategy / Alert │ │
│ │ │ │
│ │ strategy.entry() → Webhook trigger │ │
│ │ strategy.exit() → Webhook trigger │ │
│ │ alert() → Webhook trigger │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
└───────────────────────────────────────────────────────────────────────────────┘
│
│ HTTP POST (Webhook)
▼
┌───────────────────────────────────────────────────────────────────────────────┐
│ OpenAlgo REST API │
│ │
│ POST /api/v1/placeorder (Simple orders) │
│ POST /api/v1/placesmartorder (Position-based orders) │
└───────────────────────────────────────────────────────────────────────────────┘TradingView Webhook Setup
Webhook URL
Alert Message Format
Pine Script Variables
{{ticker}}
Trading symbol
SBIN
{{strategy.order.action}}
BUY or SELL
BUY
{{strategy.order.contracts}}
Order quantity
100
{{close}}
Closing price
625.50
{{time}}
Alert time
2024-01-15T09:30:00
Symbol Format Examples
Equity
Index Futures (NFO - Expires Tuesday)
Index Options (NFO - Expires Tuesday)
Bank Nifty Options (NFO - Expires Tuesday)
SENSEX Options (BFO - Expires Thursday)
Lot Sizes Reference
Note: Lot sizes and expiry days are not hard-coded in OpenAlgo. They come from the broker's master contract (
lotsizeonSymToken) and from the exchange calendar, so the table below is indicative only. Always confirm the current values from the downloaded master contract or the symbol search page.
NIFTY
65
NFO
Tuesday
BANKNIFTY
30
NFO
Tuesday
FINNIFTY
25
NFO
Tuesday
MIDCPNIFTY
50
NFO
Monday
SENSEX
20
BFO
Thursday
BANKEX
30
BFO
Monday
Smart Order for Position Management
Webhook URL
Alert Message
Position Size Logic
0
100
BUY 100
100
0
SELL 100 (close)
100
-100
SELL 200 (reverse)
-50
50
BUY 100 (reverse)
GoCharting Webhook Setup
Webhook URL
Alert Message
Same format as TradingView:
JSON Generator Endpoints
OpenAlgo provides JSON generators for easy webhook configuration:
TradingView JSON Generator
Blueprint: tv_json_bp, url_prefix="/tradingview"
Endpoint: /tradingview (GET renders the page, POST returns the generated JSON)
Features:
Select symbol, exchange, product
Two modes selected with the
modefield in the POST body:strategy(default): emitsstrategy: "TradingView Strategy"withaction: "{{strategy.order.action}}",quantity: "{{strategy.order.contracts}}"andposition_size: "{{strategy.position_size}}", for use with/api/v1/placesmartorderline: requiresactionandquantityin the request and emitsstrategy: "TradingView Line Alert"with fixed values, for use with/api/v1/placeorder
The generated JSON embeds the user's real API key, resolved through
get_api_key_for_tradingview()The symbol is resolved through
enhanced_search_symbols()and the first match is usedCopy to clipboard
GoCharting JSON Generator
Blueprint: gc_json_bp, url_prefix="/gocharting"
Endpoint: /gocharting (GET renders the page, POST returns the generated JSON)
Features:
Select symbol, exchange, product, action and quantity (all five are required)
Emits
strategy: "GoCharting"withpricetype: "MARKET", for use with/api/v1/placeorderCopy to clipboard
Price Types
MARKET
Execute at market price
-
LIMIT
Execute at specific price
price
SL
Stop Loss Limit
price, trigger_price
SL-M
Stop Loss Market
trigger_price
Complete Webhook Examples
Intraday Equity Buy
Delivery Equity Buy
NIFTY Option Buy (Tuesday Expiry)
SENSEX Option Buy (Thursday Expiry)
Key Files Reference
blueprints/tv_json.py
TradingView JSON generator
blueprints/gc_json.py
GoCharting JSON generator
restx_api/place_order.py
Order placement API
restx_api/place_smart_order.py
Smart order API
frontend/src/pages/TradingView.tsx
TradingView JSON helper UI
frontend/src/pages/GoCharting.tsx
GoCharting JSON helper UI
Last updated