Fetching Realtime OHLCV Candle Data and Converting Timestamp into Readable Format Data UPSTOX Python API

Follow the Video for Proper Instructions then go for the Code Input Below:


from upstox_api.api import *
import pandas as pd
from datetime import datetime
now=datetime.now()
from_date=datetime.strftime(now,'%d/%m/%Y')
to_date=datetime.strftime(now,'%d/%m/%Y')
api_key=open('api_key.txt','r').read()
access_token=open('access_token.txt','r').read().strip()
u=Upstox(api_key,access_token)
instruments=u.get_master_contract('nse_eq')
instruments=pd.DataFrame(instruments)
print(instruments)
exchange='nse_eq'
tradingsymbol='yesbank'
data=u.get_ohlc(u.get_instrument_by_symbol(exchange,tradingsymbol),
OHLCInterval.Minute_1,
datetime.strptime('{}'.format(from_date),'%d/%m/%Y').date(),datetime.strptime('{}'.format(to_date),'%d/%m/%Y').date())
data=pd.DataFrame(data)
data['timestamp']=pd.to_datetime(data['timestamp'],unit='ms')
data['timestamp']=data['timestamp'].dt.tz_localize('UTC').dt.tz_convert('Asia/Kolkata')
print(data)