PermissionException: Insufficient permission for that call

sanjaya
Hi - I am running below code

when I executed, the line fetchOHLC("INFY","5minute",5), I get the error PermissionException: Insufficient permission for that call

FYI - i have subscribed for Kite connect API and also Historical API


from kiteconnect import KiteConnect
import logging
import os
import datetime as dt
import pandas as pd

#cwd = os.chdir("D:\\Udemy\\Zerodha KiteConnect API\\1_account_authorization")
cwd = os.chdir("C:\\Users\\Sanjaya Guptha\\algo-g")

#generate trading session
access_token = open("access_token.txt",'r').read()
key_secret = open("api_key.txt",'r').read().split()
kite = KiteConnect(api_key=key_secret[0])
kite.set_access_token(access_token)


#get dump of all NSE instruments
instrument_dump = kite.instruments("NSE")
instrument_df = pd.DataFrame(instrument_dump)
instrument_df.to_csv("NSE_Instruments_14052024.csv",index=False)


def instrumentLookup(instrument_df,symbol):
"""Looks up instrument token for a given script from instrument dump"""
try:
return instrument_df[instrument_df.tradingsymbol==symbol].instrument_token.values[0]
except:
return -1
instrumentLookup(instrument_df,"INFY")


def fetchOHLC(ticker,interval,duration):
"""extracts historical data and outputs in the form of dataframe"""
instrument = instrumentLookup(instrument_df,ticker)
data = pd.DataFrame(kite.historical_data(instrument,dt.date.today()-dt.timedelta(duration), dt.date.today(),interval))
data.set_index("date",inplace=True)
return data

fetchOHLC("INFY","5minute",5)
Sign In or Register to comment.