How to add from date and to date in historical data

Can we add from date and to date in below historical data

sample code
data = tsl.get_historical_data(tradingsymbol=‘NIFTY’, exchange=‘INDEX’, timeframe=“5”)

How to add from date and to date on this code

Hey @John_Anson ,

Thanks for bringing this up @Tradehull_Imran may be able to assist here.

Hi @John_Anson ,

After fetching the data, you can slice the data according to the dates required as below.

data['timestamp'] = pd.to_datetime(data['timestamp'])
start_date = '2025-10-05'
end_date   = '2025-10-10'
filtered_data = data[(data['timestamp'].dt.date >= pd.to_datetime(start_date).date()) &
                (data['timestamp'].dt.date <= pd.to_datetime(end_date).date())]

print(filtered_data)

Hi @Tradehull_Imran When I try to extract data from below code
data = tsl.get_historical_data(tradingsymbol=‘NIFTY’, exchange=‘INDEX’, timeframe=“60”)

I get only 15 candles which is insufficient to calculate indicator. I need more data like at least 20 candles to calculate this. How can extract more historical data

Hi @John_Anson ,

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

Guide to use the updated codebase:
Refer the below pypi link for more details:

Hi @Tradehull_Imran , I have updated

C:\Users\meetj>pip show Dhan-Tradehull
Name: Dhan_Tradehull
Version: 3.0.6
Summary: A Dhan Codebase from TradeHull
Author: TradeHull
License:

But still I am getting only 16 candles. How can I get minimum 20 candles historical data of 60 mins timeframe

I have refereed the PyPi. and I used the same code.

Hey @John_Anson ,

Thanks for bringing this up @Tradehull_Imran would be able to assist you better.

Hey @Tradehull_Imran kindly look into this

Hi @John_Anson ,

  • Open your command prompt
  • Run the following command to find where the Dhan_Tradehull.py file is located:
pip show Dhan-Tradehull
  • Look for the line starting with Location: in the output.
  • Example:
Location: C:\Users\<username>\AppData\Local\Programs\Python\Python311\Lib\site-packages
  • Inside that folder, navigate to:
Dhan_Tradehull.py
  • Scroll or search (Ctrl + F) for:
def get_start_date():
  • Inside the function, locate this line:
start_date = df.iloc[-2]['timestamp']
  • Replace it with:
start_date = df.iloc[-30]['timestamp']
  • Save the file after making the change.
  • Restart your Python script or application that imports Dhan_Tradehull.py.

That works. Thanks

1 Like