Not getting historical and intraday data through dhan data api

(Pdb++) previous_hist_data = tsl.get_historical_data(‘ACC’,‘NSE’,20)
DataFrame constructor not properly called!
Traceback (most recent call last):
File “C:\Users\com\AppData\Local\Programs\Python\Python38\lib\cmd.py”, line 214, in onecmd
func = getattr(self, ‘do_’ + cmd)
AttributeError: ‘Pdb’ object has no attribute ‘do_previous_hist_data’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\Dhan\3. Session3 - Codebase\3. Session3 - Codebase\Dhan codebase\Dhan_Tradehull.py”, line 222, in get_historical_data
df = pd.DataFrame(ohlc[‘data’])
File “C:\Users\com\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\frame.py”, line 817, in init
raise ValueError(“DataFrame constructor not properly called!”)
ValueError: DataFrame constructor not properly called!
(Pdb++)

(Pdb++) intraday_hist_data = tsl.get_intraday_data(‘ACC’,‘NSE’,1)
intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
Traceback (most recent call last):
File “C:\Users\com\AppData\Local\Programs\Python\Python38\lib\cmd.py”, line 214, in onecmd
func = getattr(self, ‘do_’ + cmd)
AttributeError: ‘Pdb’ object has no attribute ‘do_intraday_hist_data’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\Dhan\3. Session3 - Codebase\3. Session3 - Codebase\Dhan codebase\Dhan_Tradehull.py”, line 253, in get_intraday_data
ohlc = self.Dhan.intraday_minute_data(str(security_id),exchangeSegment,instrument_type)
TypeError: intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
(Pdb++)
intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
Traceback (most recent call last):
File “C:\Users\com\AppData\Local\Programs\Python\Python38\lib\cmd.py”, line 214, in onecmd
func = getattr(self, ‘do_’ + cmd)
AttributeError: ‘Pdb’ object has no attribute ‘do_intraday_hist_data’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\Dhan\3. Session3 - Codebase\3. Session3 - Codebase\Dhan codebase\Dhan_Tradehull.py”, line 253, in get_intraday_data
ohlc = self.Dhan.intraday_minute_data(str(security_id),exchangeSegment,instrument_type)
TypeError: intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
(Pdb++)

Hi @om_prakash_soni ,
The below code seems to be right, but the timeframe 20 is not currently supported.

previous_hist_data = tsl.get_historical_data(‘ACC’,‘NSE’,20)

The timeframe for the data. It can be:

  • ‘1’ for 1-minute candles
  • ‘5’ for 5-minute candles
  • ‘15’ for 15-minute candles
  • ‘25’ for 25-minute candles
  • ‘60’ for 60-minute candles
  • ‘DAY’ for daily candles

tsl.get_intraday_data() function is deprecated.

Same error…

previous_hist_data = tsl.get_historical_data(‘ACC’,‘NSE’,1)
DataFrame constructor not properly called!
Traceback (most recent call last):
File “C:\Users\com\AppData\Local\Programs\Python\Python38\lib\cmd.py”, line 214, in onecmd
func = getattr(self, ‘do_’ + cmd)
AttributeError: ‘Pdb’ object has no attribute ‘do_previous_hist_data’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\Dhan\3. Session3 - Codebase\3. Session3 - Codebase\Dhan codebase\Dhan_Tradehull.py”, line 222, in get_historical_data
df = pd.DataFrame(ohlc[‘data’])
File “C:\Users\com\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\frame.py”, line 817, in init
raise ValueError(“DataFrame constructor not properly called!”)
ValueError: DataFrame constructor not properly called!
(Pdb++)

Hi @om_prakash_soni ,

Refer the below code:

data = tsl.get_historical_data('ACC', 'NSE', '1')

Please guide. I am stuck here.
Error:

-----Logged into Dhan-----
reading existing file all_instrument 2025-04-28.csv
Got the instrument file
[0] > e[33;01md:\dhan\3. session3 - codebase\3. session3 - codebase\dhan codebase\dhan_codebase usage.pye[00m(e[36;01m35e[00m)()
→ data = tsl.get_historical_data(‘ACC’, ‘NSE’, ‘1’)
(Pdb++) data = tsl.get_historical_data(‘ACC’, ‘NSE’, ‘1’)
unsupported type for timedelta days component: str
Traceback (most recent call last):
File “C:\Users\com\AppData\Local\Programs\Python\Python38\lib\cmd.py”, line 214, in onecmd
func = getattr(self, ‘do_’ + cmd)
AttributeError: ‘Pdb’ object has no attribute ‘do_data’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\Dhan\3. Session3 - Codebase\3. Session3 - Codebase\Dhan codebase\Dhan_Tradehull.py”, line 211, in get_historical_data
from_date= datetime.datetime.now()-datetime.timedelta(days=days)
TypeError: unsupported type for timedelta days component: str
(Pdb++) data
(Pdb++)

The errors are still there. Please help

Hi @om_prakash_soni ,

Do update to our latest codebase version 3.0.6:

  • Open Command Prompt: Press Win, type cmd, and press Enter.
  • Install Dhan-Tradehull: Run pip install Dhan-Tradehull
  • Confirm the installation by running pip show Dhan-Tradehull

Tried for INFY also. Result is same. Please see again

reading existing file all_instrument 2025-04-30.csv
Got the instrument file
[0] > e[33;01md:\dhan\3. session3 - codebase\3. session3 - codebase\dhan codebase\dhan_codebase usage.pye[00m(e[36;01m35e[00m)()
→ data = tsl.get_historical_data(‘ACC’, ‘NSE’, ‘1’)
(Pdb++) data = tsl.get_historical_data(‘ACC’, ‘NSE’, ‘1’)
unsupported type for timedelta days component: str
Traceback (most recent call last):
File “C:\Users\com\AppData\Local\Programs\Python\Python38\lib\cmd.py”, line 214, in onecmd
func = getattr(self, ‘do_’ + cmd)
AttributeError: ‘Pdb’ object has no attribute ‘do_data’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\Dhan\3. Session3 - Codebase\3. Session3 - Codebase\Dhan codebase\Dhan_Tradehull.py”, line 211, in get_historical_data
from_date= datetime.datetime.now()-datetime.timedelta(days=days)
TypeError: unsupported type for timedelta days component: str
(Pdb++) Data
*** NameError: name ‘Data’ is not defined
(Pdb++) data
(Pdb++) data = tsl.get_historical_data(‘INFY’, ‘NSE’, 1)
DataFrame constructor not properly called!
Traceback (most recent call last):
File “C:\Users\com\AppData\Local\Programs\Python\Python38\lib\cmd.py”, line 214, in onecmd
func = getattr(self, ‘do_’ + cmd)
AttributeError: ‘Pdb’ object has no attribute ‘do_data’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\Dhan\3. Session3 - Codebase\3. Session3 - Codebase\Dhan codebase\Dhan_Tradehull.py”, line 222, in get_historical_data
df = pd.DataFrame(ohlc[‘data’])
File “C:\Users\com\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\frame.py”, line 817, in init
raise ValueError(“DataFrame constructor not properly called!”)
ValueError: DataFrame constructor not properly called!
(Pdb++) data
(Pdb++) data = tsl.get_historical_data(‘INFY’, ‘NSE’, ‘1’)
unsupported type for timedelta days component: str
Traceback (most recent call last):
File “C:\Users\com\AppData\Local\Programs\Python\Python38\lib\cmd.py”, line 214, in onecmd
func = getattr(self, ‘do_’ + cmd)
AttributeError: ‘Pdb’ object has no attribute ‘do_data’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\Dhan\3. Session3 - Codebase\3. Session3 - Codebase\Dhan codebase\Dhan_Tradehull.py”, line 211, in get_historical_data
from_date= datetime.datetime.now()-datetime.timedelta(days=days)
TypeError: unsupported type for timedelta days component: str
(Pdb++)

Hi @om_prakash_soni ,

In cmd can you enter the below code and share a screenshot?

pip show Dhan-Tradehull

Hi @om_prakash_soni ,

Do check the result of the code during market hours.

(Pdb++) data = tsl.get_historical_data(‘ACC’,‘NSE’,‘5’)
unsupported type for timedelta days component: str
Traceback (most recent call last):
File “C:\Users\com\AppData\Local\Programs\Python\Python38\lib\cmd.py”, line 214, in onecmd
func = getattr(self, ‘do_’ + cmd)
AttributeError: ‘Pdb’ object has no attribute ‘do_data’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\Dhan\6. Session6- 1st Live Algo\1st live Algo\Dhan_Tradehull.py”, line 211, in get_historical_data
from_date= datetime.datetime.now()-datetime.timedelta(days=days)
TypeError: unsupported type for timedelta days component: str
(Pdb++)

Hi @om_prakash_soni ,

The exchange for sensex options must be ‘BFO’

data = tsl.get_historical_data('SENSEX 06 MAY 83200 PUT', 'BFO', '1')

Error code is similar. Is there any requirement with excel file also.
:\Dhan\6. Session6- 1st Live Algo\1st live Algo>py “test_live algo.py”
-----Logged into Dhan-----
reading existing file all_instrument 2025-05-06.csv
Got the instrument file
unsupported type for timedelta days component: str
Traceback (most recent call last):
File “D:\Dhan\6. Session6- 1st Live Algo\1st live Algo\Dhan_Tradehull.py”, line 211, in get_historical_data
from_date= datetime.datetime.now()-datetime.timedelta(days=days)
TypeError: unsupported type for timedelta days component: str

D:\Dhan\6. Session6- 1st Live Algo\1st live Algo>

Good Morning Imran Sir, I am trying to get historical data from tradehull its giving data but only of few days only

  • ‘1’ for 1-minute candles # of 5 days # 1124 rows
  • ‘5’ for 5-minute candles # of 5 days # 225 rows
  • ‘15’ for 15-minute candles # of 5 days # 76 rows
  • ‘25’ for 25-minute candles # of 5 days # 45 rows
  • ‘60’ for 60-minute candles # of 5 days # 21 rows
  • ‘DAY’ for daily candles of 247 days
    we are unable to view the intraday chart pattern of 60 Minute time frame of multiple days for developing any strategy of our own based on the histrorical data.

can you please help on this matter i am runing the below mentioned code

for name in watchlist:
chart = tsl.get_historical_data(tradingsymbol=name, exchange=‘NSE’, timeframe=“XX”)

Everytime, I am getting this error. Please help on this

TypeError: unsupported type for timedelta days component: str

chart = tsl.get_historical_data(tradingsymbol=‘RELIANCE’, exchange=‘NSE’, days= 3)
DataFrame constructor not properly called!
Traceback (most recent call last):
File “C:\Users\com\AppData\Local\Programs\Python\Python38\lib\cmd.py”, line 214, in onecmd
func = getattr(self, ‘do_’ + cmd)
AttributeError: ‘Pdb’ object has no attribute ‘do_chart’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\Dhan\6. Session6- 1st Live Algo\1st live Algo\Dhan_Tradehull.py”, line 222, in get_historical_data
if ‘data’ in ohlc.keys():
File “C:\Users\com\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\frame.py”, line 817, in init
raise ValueError(“DataFrame constructor not properly called!”)
ValueError: DataFrame constructor not properly called!
(Pdb++)

Please help on this. I have tried all combinations. Please confirm, if I am not getting data on this