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