5 Easy Ways to Fetch Real-Time Indian Market Data with Python
- Amman Kumar
- Feb 5
- 5 min read
Imagine having the power to track live stock prices, market trends, and trading volumes at your fingertips sounds exciting, right?
Whether you're a beginner investor, an active trader, or diving into algorithmic trading, real-time market data is crucial for making smart moves.
The good news? Python makes it incredibly easy!
With its powerful libraries, you can fetch live Indian stock market data effortlessly—whether you're building a simple script or a full-fledged trading bot.
Here are five simple and effective ways to access real-time stock data and take your trading game to the next level!
yFinance – The Quick & Free Option

If you're just starting, yFinance (powered by Yahoo Finance) is your best friend. It's free, beginner-friendly, and gives you stock prices, historical data, and key financial indicators. You can even fetch data for multiple tickers at once, making it easy to track your portfolio.
Why yFinance?
Free and beginner-friendly! 🎉
You can fetch live stock prices, historical data, and more.
A great starting point for casual investors or those dipping their toes into Python-based market analysis.
Though it’s not the fastest option, yFinance is reliable for most casual traders. If you don’t need ultra-low latency and just want quick stock prices, this is perfect.
How to Use it: Here’s some simple Python code to get real-time data. Let’s say you’re interested in Reliance Industries (NSE).
import yfinance as yf
stock = yf.Ticker("RELIANCE.NS")
print(stock.history(period="1d"))

KiteConnect

If you trade with Zerodha, their KiteConnect API is a one of the most reliable API.
Zerodha is one of the largest retail stockbrokers in India, and the API provides access to a wealth of features that can be integrated into various trading algorithms.
You get real-time stock data and order execution, making it perfect for serious traders and algo traders who want to integrate live market data into their strategies.
Why KiteConnect?
Real-time data with no delays
Seamless order execution for trades
Super reliable, especially for active traders
Proper API documentation
If you're using Zerodha, the KiteConnect API is an best option. It lets you integrate live market data directly into your trading strategies. For algo traders, this is a must-have tool.
How to Use it: To get started, you’ll need a Zerodha account and an API key. Once that’s set up, here’s how you can get live market data:
from kiteconnect import KiteConnect
api_key = "sdfsfgdfigsndsf"
api_secret = "dsfewwsdasdaS"
# Initialize KiteConnect
self.kite = KiteConnect(api_key=api_key)
kite.set_access_token(access_token)
kite.get_ltp(*instrument)
Moreover, you can use WebSocket connectivity for tick-by-tick data. That we will see in our future blogs.
Dhan HQ API

Need ultra-low-latency market data? Dhan’s API is your go-to option. It’s fast, reliable, and designed for algo traders who need millisecond-level execution speed.
Why Dhan?
Super fast – milliseconds matter here!
Great for algorithmic trading (low latency is key!)
Reliable and perfect for those who need quick execution speeds
The Dhan API is built to give you data quickly. So, if you're into algo trading and need live data for making split-second decisions, this one’s for you.
How to Use it: After signing up and getting your API token, you can use Python to fetch live data with this code:
import requests
headers = {"access-token": "adfsgsdfweaxaef"}
print(requests.get(url, headers=headers).json())
SmartConnect – Angel One’s Trading API

Angel One’s SmartAPI is another great option for fetching real-time stock data and executing trades. It’s similar to KiteConnect but tailored for Angel One users.
It works similarly to Zerodha’s KiteConnect but is designed specifically for Angel One’s users.
If you’re already trading with Angel One, this is a great API to help automate and streamline your trading strategies. It’s easy to set up and use, making it accessible for both beginners and advanced traders.
How to Use it: Here’s a quick example to fetch live data for Reliance on NSE:
from SmartApi import SmartConnect
smart = SmartConnect(api_key="your_api_key")
print(smart.ltp("NSE", "RELIANCE"))
NSE Website

Want live stock data for free, no API keys, no subscriptions? Just scrape the NSE website! It’s not as polished as an API, but if you’re willing to get your hands dirty, it works like a charm.
Why Scrape the NSE Website?
Completely free
No API key or subscription needed
A good solution for casual investors who need occasional updates
Just keep in mind, the NSE website structure changes from time to time, so you’ll need to tweak your code accordingly. But if you’re working with smaller datasets and don’t need ultra-fast execution speeds, scraping is a solid option.
How to Use it: Here's a Python script that uses the requests and BeautifulSoup libraries to scrape live stock data from the NSE website:
import requests
from bs4 import BeautifulSoup
headers = {"User-Agent": "Mozilla/5.0"}
data = requests.get(url, headers=headers).json()
print(data['priceInfo']['lastPrice'])
Final Thoughts
Real-time market data is essential for anyone serious about trading. Whether you’re just starting out or an active trader,
Python gives you all the tools you need to access live data from the Indian stock market.
Python allows you to choose the solution that best fits your needs. Whether you’re building your own trading bot, analyzing stocks, or just want to track live data for your portfolio, there’s a tool for every type of trader.
Whichever option you choose, you’re now ready to take your trading game to the next level. So, get coding, fetch that live data, and start making smarter trading decisions!
FAQ’s
Is it legal to fetch real-time stock market data?
Yes, but you must use authorized sources such as official APIs from brokers (e.g., Zerodha KiteConnect, Angel One SmartConnect) or financial data providers. Scraping websites like NSE India can be a gray area, as the site’s structure changes frequently and may have usage restrictions.
Do I need programming experience to fetch real-time stock data?
Basic knowledge of Python is recommended, as you’ll be working with APIs and handling data in JSON format. However, beginner-friendly libraries like yFinance make it easy even for those with minimal coding experience.
What is the fastest way to get real-time stock data?
Low-latency APIs like Dhan and KiteConnect offer the fastest data retrieval, which is critical for algo traders.
Are these APIs free to use?
Some APIs like yFinance are free. However, broker APIs like KiteConnect, SmartConnect, and Dhan may require a subscription or a trading account.
How frequently is the data updated?
Data update frequency depends on the source:
yFinance: Delayed data (not real-time)
KiteConnect, Dhan, SmartConnect: Real-time updates with low latency
NSE Web Scraping: May have delays and depend on website response times
What should I do if my API key isn’t working?
Double-check that you’ve entered the correct API key.
Ensure your API subscription is active.
Read the API documentation for any authentication requirements.
Contact the broker’s support if issues persist.
Can I use these APIs for algo trading?
Yes, APIs like KiteConnect and Dhan are designed for algorithmic trading. Ensure that your trading strategies comply with exchange regulations before deploying automated trading systems.
Comments