Some code issue plz chk

from rich import print
import pandas_ta as ta
import pandas as pd
import talib





client_code="1109035880"
token_id="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJkaGFuIiwicGFydG5lcklkIjoiIiwiZXhwIjoxNzY0NDMxNDA5LCJpYXQiOjE3NjQzNDUwMDksInRva2VuQ29uc3VtZXJUeXBlIjoiU0VMRiIsIndlYmhvb2tVcmwiOiIiLCJkaGFuQ2xpZW50SWQiOiIxMTA5MDM1ODgwIn0.3FP8xPgv2sfmHSidXgk4SuAx6sWWmZcr7khNvI7s_RmJe6-8h81q7EYWfnOvoeo_RIlX3cL0Ruez7_XeU7O2eA"
tsl = codebase(client_code,token_id)


watchlist=["BAJAJFINSV","RELIANCE", 'NIFTY' ,"SBILIFE", "LT", "HINDUNILVR", "ADANIENT", "JIOFIN", "BAJAJFINSV", "BAJAJ-AUTO", "KOTAKBANK", "ITC", "EICHERMOT", "TATACONSUM", "TECHM", "ADANIPORTS", "HEROMOTOCO", "INFY", "ASIANPAINT", "HDFCLIFE", "TRENT", "NTPC", "ETERNAL", "AXISBANK", "GRASIM", "ULTRACEMCO",  "TITAN", "HCLTECH", "ONGC", "MARUTI", "TCS", "HINDALCO", "DRREDDY", "WIPRO", "CIPLA", "SBIN", "NESTLEIND", "SHRIRAMFIN", "SUNPHARMA", "POWERGRID", "RELIANCE", "JSWSTEEL", "HDFCBANK", "BEL", "COALINDIA", "BHARTIARTL", "INDUSINDBK", "ICICIBANK", "BAJFINANCE", "M&M", "APOLLOHOSP","NIFTY"]


while True:

    for stock_name in watchlist:

        chart      = tsl.get_historical_data(tradingsymbol=stock_name, exchange='NSE', timeframe="5")
        
        chart['RSI']= talib.RSI(chart['close'],timeperiod=14)
        rsi= chart.iloc[-2]['RSI']

        if rsi > 70:
            print("buy",stock_name)
            orderid = tsl.order_placement(tradingsymbol='stock_name', exchange='NSE', quantity=1, price=0.05, trigger_price=0,order_type='LIMIT', transaction_type='BUY', trade_type='MIS')

        if rsi < 30:
            print("sell",stock_name)
type or paste code here

error

-----Logged into Dhan-----
reading existing file all_instrument 2025-11-28.csv
Got the instrument file
Traceback (most recent call last):
File “c:\Users\Abhishek\OneDrive\Desktop\Algo mentorship program\Session 2\session2.py”, line 26, in
rsi= chart.iloc[-2][‘RSI’]
~~~~~~~~~~^^^^
File “C:\Users\Abhishek\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\indexing.py”, line 1192, in getitem
return self._getitem_axis(maybe_callable, axis=axis)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Abhishek\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\indexing.py”, line 1753, in _getitem_axis
self._validate_integer(key, axis)
File “C:\Users\Abhishek\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\indexing.py”, line 1686, in _validate_integer
raise IndexError(“single positional indexer is out-of-bounds”)
IndexError: single positional indexer is out-of-bounds
PS C:\Users\Abhishek>

The code which we learn in last session2 was trying to Run but facing above issue. let me know how can we solved it .thanks

add below line
from Dhan_Tradehull import Tradehull

also change codebase to Tradehull in line no 3 i.e.
tsl = Tradehull(client_code,token_id)

1 Like