How to get Nifty or BankNifty Historical and Intraday data using Tradehull Codebase API?

How to get Nifty or BankNifty Historical and Intraday data using Tradehull Codebase API?

Hi @Krishan_Kant_Sinha

use below code

import pdb
import time
import datetime
import traceback
from Dhan_Tradehull_V2 import Tradehull
import pandas as pd
from pprint import pprint
import talib


client_code = "client_code"
token_id    = "token_id"
tsl = Tradehull(client_code,token_id)



nifty_chart     = tsl.get_historical_data(tradingsymbol = 'BANKNIFTY',exchange = 'INDEX',timeframe="5")
banknifty_chart = tsl.get_historical_data(tradingsymbol = 'NIFTY',exchange = 'INDEX',timeframe="5")


Also do post all your code queries on below link

Sir, how to get data “From date” to “to date”?

Hi @babji3

Can you elaborate the use case for same,
by default, the historical data start data is set to 6 days prior to today.

Sir, i mean to say, I want 5 minutes candle data from 26-11-2024 to till date, like that.

Thanks a Lot Imran Sir

1 Like

Hi Sir, I am using Dhan libraries and framework. Its a wonderful framework, easy to implement and easy to understand. Thanks for sharing. There are 2 existing NSE indexes, NIFTY and BANKNIFTY. I want to add all of the NSE indexes, i.e. MIDCAPNIFTY100, PRIVATEBANKNIFTY etc. Please help me to achieve it…

Hi @neeraj_arora ,

Here’s how you can fetch data for MIDCPNIFTY:

data = tsl.get_historical_data(tradingsymbol = 'MIDCPNIFTY',exchange = 'INDEX' ,timeframe="1")

1 Like

did copy pasted but its not coming can you please guide sir

Hi @kanhaji,

The code seems to be fine. 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:

Video reference :

thanks for your reply but sir indicator lagane ya uska value fetch karne ke liye minimum 20 days ka option data chahiye isme sirf 2-3 days ka aa raha hai

i will be always grateful to you sir for enlighten us to a new dimension, never ever imagined this is in my life. i bow my head towards you and entire dhan team for this, i am on my final leg to implement this. JUST AGAIN ONE MORE REQUEST PLEASE PROVIDE OTHER TIME FRAME LIKE 30 MIIN 45M 4 HR IN OPTION AND STOCKS CHART TO FETCH DATA.

Thank you so much :pray: :pray: