Take a look

Tech

Get Live Data Of (National Stock Exchange)NSE Stocks Of All Symbols(Nifty50) Using Python

Fetching Pre market report or NSE live data of Nifty 50 stocks would help you to identify the trends and build strategies. With the collected data in real time you can easily write some logics to find the stocks that comes under any of the particular intraday or swing strategies of your choice. Although Zerodha Kite and various other APIs are available for algorithmic trading which is not free of cost, For doing trades manually with the help of python to identify the suitable stocks you can use the below code to generate your own methods. For example If you would like to find the stocks that are coming under ORB(Opening range breakout) or OHL strategies at a given point of time we might need the live data from nifty at a particular point of time. So Please find the python code to fetch the Nifty real time data with OHL strategy stocks suitable for buying/selling.

import requests
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; '
            'x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36'}

main_url = "https://www.nseindia.com/"
response = requests.get(main_url, headers=headers)
print(response.status_code)
cookies = response.cookies


preopen_market_url = "https://www.nseindia.com/api/market-data-pre-open?key=NIFTY"
preopen_data = requests.get(preopen_market_url, headers=headers, cookies=cookies)
print(preopen_data.status_code)
print("Pre-open market data", preopen_data.text)


url = "https://www.nseindia.com/api/equity-stockIndices?index=NIFTY%2050"
nifty_50_data = requests.get(url, headers=headers, cookies=cookies)
print(nifty_50_data.status_code)
nifty50_data = nifty_50_data.json()
print(nifty50_data)

ohl_buy_stocks = []
ohl_sell_stocks = []

for stocks in nifty50_data.get("data"):
    if stocks['open'] == stocks['dayLow']:
        ohl_buy_stocks.append(stocks['symbol'])

    if stocks['open'] == stocks['dayHigh']:
        ohl_sell_stocks.append(stocks['symbol'])


print("Most Probable buying Stocks based on OHL Strategy", ohl_buy_stocks)
print("Most Probable Selling Stocks based on OHL Strategy", ohl_sell_stocks)

Leave a Reply