kiteconnect.exceptions.PermissionException: Insufficient permission for that call

from Zerodha_Tradehull import Tradehull
from rich import print
import talib

api_key    = ""
api_secret = ""
tsl        = Tradehull(api_key, api_secret, "yes")
kite       = tsl.kite

watchlist = ['ADANIPORTS', 'ADANIENT', 'SBIN', 'TATASTEEL', 'BAJAJFINSV', 'RELIANCE', 'TCS', 'JSWSTEEL',  'HCLTECH', 'TECHM',  'NTPC', 'BHARTIARTL', 'WIPRO', 'BAJFINANCE', 'INDUSINDBK', 'KOTAKBANK', 'HINDALCO', 'ULTRACEMCO',   'AXISBANK', 'M&M', 'MARUTI', 'HEROMOTOCO',  'EICHERMOT', 'COALINDIA', 'TITAN', 'UPL', 'HINDUNILVR', 'ITC', 'NESTLEIND', 'APOLLOHOSP', 'ICICIBANK',  'GRASIM', 'BRITANNIA', 'ASIANPAINT',  'POWERGRID', 'SBILIFE', 'ONGC']
traded_watchlist = []


while True:
    print()
    for name in watchlist:
        
        print(name)
    
    chart = tsl.get_short_term_hist_data(name=name, exchange="NSE", interval="minute", oi = True) 
# chart = tsl.get_short_length_hist_data(name=name,exchange="NSE",interval="minute",oi=True)
    chart['rsi'] = talib.RSI(chart['close'], timeperiod=14)





    comp_candle  = chart.iloc[-2]


    bc1 = comp_candle['rsi'] > 60
    bc2 = name not in traded_watchlist
    bc3 = len(traded_watchlist) <= 2
        
        
    sc1 = comp_candle['rsi'] < 40
    sc2 = name not in traded_watchlist
    sc3 = len(traded_watchlist) <= 2



    if bc1 and bc2 and bc3:
        print(name, "is oversold")


        atm_name = tsl.get_atm(ltp = comp_candle['close'], underlying=name, exchange = "NSE", expiry=0, script_type="CE")
        entry_price = tsl.get_ltp(atm_name, "NFO")
        sl_price    = round(entry_price*0.7, 1)
        quantity    = tsl.get_lot_size(atm_name)    

        entry_id    = tsl.place_order(variety="amo", exchange='NFO', tradingsymbol=atm_name, transaction_type='BUY', quantity=quantity, product="MIS", order_type="LIMIT", price = entry_price)
        stoploss_id = tsl.place_order(variety="amo", exchange='NFO', tradingsymbol=atm_name, transaction_type='SELL', quantity=quantity, product="MIS", order_type="SL", price = sl_price, trigger_price = round(sl_price*0.9, 1))
        traded_watchlist.append(name)




    if sc1 and sc2 and sc3:
            print(name, "is overbought")

            atm_name = tsl.get_atm(underlying=name, exchange = "NSE", expiry=0, script_type="PE")
            entry_price = tsl.get_ltp(atm_name, "NFO")
            sl_price    = round(entry_price*0.7, 1)
            quantity    = tsl.get_lot_size(atm_name)

            entry_id    = tsl.place_order(variety="amo", exchange='NFO', tradingsymbol=atm_name, transaction_type='BUY', quantity=quantity, product="MIS", order_type="LIMIT", price = entry_price)
            stoploss_id = tsl.place_order(variety="amo", exchange='NFO', tradingsymbol=atm_name, transaction_type='SELL', quantity=quantity, product="MIS", order_type="SL", price = sl_price, trigger_price = round(sl_price*0.9, 1))
            traded_watchlist.append(name)





            modified_order_id = tsl.modify_order(variety="amo", order_id=stoploss_id, quantity=350, trigger_price=None)
            kite.order_history(order_id=stoploss_id)            
            status = tsl.get_order_status(stoploss_id)
            kite.cancel_order(variety="amo", order_id=stoploss_id, parent_order_id=None)



            ohlc_dict = {}
            openx     = ohlc_dict['openx']
            high     = ohlc_dict['high']
            low     = ohlc_dict['low']
            close     = ohlc_dict['close']




Evaluating: chart = tsl.get_short_term_hist_data(name=name,exchange=“NSE”,interval=“minute”,oi=True) did not finish after 3.00 seconds.
This may mean a number of things:

  • This evaluation is really slow and this is expected.
    In this case it’s possible to silence this error by raising the timeout, setting the
    PYDEVD_WARN_EVALUATION_TIMEOUT environment variable to a bigger value.

  • The evaluation may need other threads running while it’s running:
    In this case, it’s possible to set the PYDEVD_UNBLOCK_THREADS_TIMEOUT
    environment variable so that if after a given timeout an evaluation doesn’t finish,
    other threads are unblocked or you can manually resume all threads.

    Alternatively, it’s also possible to skip breaking on a particular thread by setting a
    pydev_do_not_trace = True attribute in the related threading.Thread instance
    (if some thread should always be running and no breakpoints are expected to be hit in it).

  • The evaluation is deadlocked:
    In this case you may set the PYDEVD_THREAD_DUMP_ON_WARN_EVALUATION_TIMEOUT
    environment variable to true so that a thread dump is shown along with this message and
    optionally, set the PYDEVD_INTERRUPT_THREAD_TIMEOUT to some value so that the debugger
    tries to interrupt the evaluation (if possible) when this happens.
    Insufficient permission for that call.
    Traceback (most recent call last):
    File “c:\Users\shubh\AppData\Local\Programs\Python\Python38\lib\site-packages\Zerodha_Tradehull\Zerodha_Tradehull.py”, line 227, in get_short_term_hist_data
    instrument_token = self.kite.ltp(exchange+“:”+name)[exchange+“:”+name][‘instrument_token’]
    File “c:\Users\shubh\AppData\Local\Programs\Python\Python38\lib\site-packages\kiteconnect\connect.py”, line 611, in ltp
    return self._get(“market.quote.ltp”, params={“i”: ins})
    File “c:\Users\shubh\AppData\Local\Programs\Python\Python38\lib\site-packages\kiteconnect\connect.py”, line 861, in _get
    return self._request(route, “GET”, url_args=url_args, params=params, is_json=is_json)
    File “c:\Users\shubh\AppData\Local\Programs\Python\Python38\lib\site-packages\kiteconnect\connect.py”, line 937, in _request
    raise exp(data[“message”], code=r.status_code)
    kiteconnect.exceptions.PermissionException: Insufficient permission for that call.

Hi @7350982949 ,

Your Zerodha API key doesn’t have historical data permission.
Zerodha restricts historical data unless you subscribe to Kite Connect + Historical API.

Do subscribe for both and then try: