Please Follow the Instructions from Video then go for the Code Below:
from upstox_api.api import *
import pandas as pd
api_key=open('api_key.txt','r').read()
access_token=open('access_token.txt','r').read()
u=Upstox(api_key,access_token)
u.get_master_contract('NSE_EQ')
instruments_tradingsymbol=[]
instruments=pd.read_csv('tradingsymbol.csv',names=['tradingsymbol','instrument_token'])
for symbol in instruments['tradingsymbol']:
instruments_tradingsymbol.append(u.get_instrument_by_symbol('NSE_EQ','{}'.format(symbol)))
def event_handler_quote_update(ticks):
print(ticks['symbol'],ticks['ltp'])
u.set_on_quote_update( event_handler_quote_update)
u.subscribe(instruments_tradingsymbol,LiveFeedType.Full,'NSE_EQ')
u.start_websocket(True)
Plese do Copy Paste Tradingsymbol with instrumen token of nifty 50 stocks list as filname.csv from Below:
ADANIPORTS,3861249
AMBUJACEM,325121
ASIANPAINT,60417
AUROPHARMA,70401
AXISBANK,1510401
BAJAJ-AUTO,4267265
BAJFINANCE,81153
BHARTIARTL,2714625
INFRATEL,7458561
BOSCHLTD,558337
BPCL,134657
CIPLA,177665
COALINDIA,5215745
DRREDDY,225537
EICHERMOT,232961
GAIL,1207553
HCLTECH,1850625
HDFC,340481
HDFCBANK,341249
HEROMOTOCO,345089
HINDALCO,348929
HINDUNILVR,356865
HINDPETRO,359937
ICICIBANK,1270529
IBULHSGFIN,7712001
INDUSINDBK,1346049
INFY,408065
IOC,415745
ITC,424961
KOTAKBANK,492033
LT,2939649
LUPIN,2672641
M&M,519937
MARUTI,2815745
NTPC,2977281
ONGC,633601
POWERGRID,3834113
RELIANCE,738561
SBIN,779521
SUNPHARMA,857857
TCS,2953217
TATAMOTORS,884737
TATASTEEL,895745
TECHM,3465729
ULTRACEMCO,2952193
UPL,2889473
VEDL,784129
WIPRO,969473
YESBANK,3050241
ZEEL,975873