Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.

fetch tradingview candle stick data

Last updated on 9 hours ago
C
caaSuper Admin
Posted 9 hours ago
TradingView itself does not offer a public API for fetching candlestick data directly, but you can use the following approaches:


### 1. **Third-Party Data APIs**
Several APIs provide financial market data, similar to what TradingView displays:

#### Popular APIs:
1. **Alpha Vantage**
- Offers historical and intraday stock data.
- [Get API Key here](https://www.alphavantage.co/support/#api-key).

Example (Intraday Candlestick Data for AAPL):
python
 import requests

 API_KEY = "your_alpha_vantage_api_key"
 symbol = "AAPL"
 url = f"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol={symbol}&interval=1min&apikey={API_KEY}"

 response = requests.get(url)
 data = response.json()

 # Accessing candlestick data
 time_series = data.get("Time Series (1min)", {})
 for time, ohlc in time_series.items():
 print(f"Time: {time}, Open: {ohlc['1. open']}, High: {ohlc['2. high']}, Low: {ohlc['3. low']}, Close: {ohlc['4. close']}")
 


2. **Yahoo Finance API**
- Fetch OHLC data using a library like yfinance in Python.
python
 import yfinance as yf

 ticker = "AAPL"
 data = yf.download(ticker, interval="1m", period="1d")

 print(data.head())
 
C
caaSuper Admin
Posted 9 hours ago
3. **IEX Cloud**
- Real-time and historical data for U.S. and international markets.
- [IEX Cloud API](https://iexcloud.io/).

4. **Polygon.io**
- Comprehensive candlestick data for stocks, forex, and crypto.
- [Polygon.io API](https://polygon.io/).

---

### 2. **WebSocket Data Feeds**
For real-time candlestick updates, use data providers with WebSocket APIs:

#### Example: Binance WebSocket for Crypto
python
import websocket
import json

def on_message(ws, message):
 data = json.loads(message)
 print("Candlestick data:", data)

socket = "wss://stream.binance.com:9443/ws/btcusdt@kline_1m"

ws = websocket.WebSocketApp(socket, on_message=on_message)
ws.run_forever()


---

### 3. **TradingView Charting Library with Custom Datafeed**
If you use the **TradingView Charting Library**, you must implement a custom datafeed using their Datafeed API.
C
caaSuper Admin
Posted 9 hours ago
#### Steps:
1. Download the TradingView Charting Library.
2. Use a custom server or API as the data source.
3. Implement the onReady, resolveSymbol, and getBars methods in JavaScript for your datafeed.

---

### 4. **Scraping TradingView (Not Recommended)**
You can scrape candlestick data, but it **violates TradingView's Terms of Service**. If you proceed, do so responsibly and understand the risks.

#### Example (Using Python with Selenium/BeautifulSoup):
python
from selenium import webdriver
from bs4 import BeautifulSoup

url = "https://www.tradingview.com/symbols/NASDAQ-AAPL/"

driver = webdriver.Chrome() # Use the appropriate WebDriver for your browser
driver.get(url)

html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')

# Locate candlestick data (you'll need to inspect the DOM structure)
print(soup.prettify())
driver.quit()


---
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.
Sign In
Not a member yet? Click here to register.
Forgot Password?
Users Online Now
Guests Online 2
Members Online 0

Total Members: 11
Newest Member: Jhilam