Unable to get historical data and intraday data of any stock or options

I am unable to get historical data and also intraday data

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

After writing this code I am getting an error msg as displayed in image
APIs, Automation, Algos & Code

Hello @Scooby_Doo

Welcome to MadeForTrade community!

Can you raise this on the following thread:

Trying to maintain single thread for all youtube course related issues.

Hi @Tradehull_Imran
I am unable to get historical data

t

oken_id = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJkaGFuIiwicGFydG5lcklkIjoiIiwiZXhwIjoxNzM2NzQ0OTAzLCJ0b2tlbkNvbnN1bWVyVHlwZSI6IlNFTEYiLCJ3ZWJob29rVXJsIjoiIiwiZGhhbkNsaWVudElkIjoiMTAwMDYwMjk5OSJ9.GaHlvpzynS6-ObQlV8gAulAzEoKCkabZ1ECw7Y5AmUOJFW2cWXPphWtobSlMaFCViYbTPkv0OJuY8BNeShkqMw"
tsl = Tradehull(client_code,token_id) # tradehull_support_library


#tsl.get_intraday_data('ACC','NSE',1)

#tsl.get_intraday_data('NIFTY','NSE',1)

available_balance = tsl.get_balance()

max_risk_for_the_day = (available_balance*1)/100*-1
print("available_balance", available_balance)


ltp1 = tsl.get_ltp('ACC')
ltp2 = tsl.get_ltp('NIFTY')
ltp3 = tsl.get_ltp('BANKNIFTY 24 DEC 53600 CALL')
ltp4 = tsl.get_ltp('NIFTY 26 DEC 24700 CALL')

pdb.set_trace()



previous_hist_data = tsl.get_historical_data('ACC','NSE',12)
intraday_hist_data = tsl.get_intraday_data('ACC','NSE',1)``
Microsoft Windows [Version 10.0.26100.2605]
(c) Microsoft Corporation. All rights reserved.

D:\Dhan\3. Session3 - Codebase\3. Session3 - Codebase\Dhan codebase>py "Dhan_codebase usage.py"
-----Logged into Dhan-----
reading existing file all_instrument 2024-12-15.csv
Got the instrument file
available_balance 40000.0
[0] > d:\dhan\3. session3 - codebase\3. session3 - codebase\dhan codebase\dhan_codebase usage.py(34)<module>()
-> previous_hist_data = tsl.get_historical_data('ACC','NSE',12)
(Pdb++) previous_hist_data
*** NameError: name 'previous_hist_data' is not defined
(Pdb++) previous_hist_data = tsl.get_historical_data('ACC','NSE',12)
DataFrame constructor not properly called!
Traceback (most recent call last):
  File "C:\Users\HP\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\HP\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++)

I m getting same error. Please advise how can i fix this

Do update codebase on your system

  • 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

refer the below video for updated codebase :

I am getting following error while using Option chain :-1:
Codebase Version 2.7 : Solved - Option Chain Issue
-----Logged into Dhan-----
reading existing file all_instrument 2025-02-26.csv
Got the instrument file

Getting Error at Option Chain as ‘NIFTY’
Traceback (most recent call last):
File “C:\1Algo_Dhan\Nifty_Option_chain_to_excel.py”, line 24, in
atm_strike, option_chain = tsl.get_option_chain(Underlying = ‘NIFTY’,exchange = ‘INDEX’,expiry = 1, num_strikes = 15)
TypeError: cannot unpack non-iterable NoneType object
[Finished in 5.5s]

Following is the 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
import xlwings as xw

client_code = “1100951152”
token_id = “eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJkaGFuIiwicGFydG5lcklkIjoiIiwiZXhwIjoxNzQyMjg3NjE3LCJ0b2tlbkNvbnN1bWVyVHlwZSI6IlNFTEYiLCJ3ZWJob29rVXJsIjoiIiwiZGhhbkNsaWVudElkIjoiMTEwMDk1MTE1MiJ9.THj6EdVMk-g8t42d0xzimwBXSC3KY_GWhb4ck9_xpjCnLBLbPGnmHsgH7F9ZwaJ3JXccAqdxSK5JU9p64yXV8g”
tsl = Tradehull(client_code,token_id) # tradehull_support_library

wb = xw.Book(‘Live Option Chain.xlsx’)
sheet = wb.sheets[‘Sheet1’]

atm_strike, option_chain = tsl.get_option_chain(Underlying = ‘NIFTY’,exchange = ‘INDEX’,expiry = 1, num_strikes = 15)