Compatibility Issue: dhanhq v2.0.2 missing DhanContext required by Dhan_Tradehull

@Tradehull_Imran Facing an issue with the 3.1 codebase run. I’ve completed the required steps from the update video, but am still hitting the attached error.

code-

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


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

pdb.set_trace()

error-

Microsoft Windows [Version 10.0.26200.8246]
(c) Microsoft Corporation. All rights reserved.

C:\Users\mahim\OneDrive\Documents\Nirav\Dhan\Basic Python\Code\3.1 Codebase Upgrade\3.1 Codebase Upgrade>python V2.py
Traceback (most recent call last):
  File "C:\Users\mahim\OneDrive\Documents\Nirav\Dhan\Basic Python\Code\3.1 Codebase Upgrade\3.1 Codebase Upgrade\V2.py", line 5, in <module>
    from Dhan_Tradehull import Tradehull
  File "C:\Users\mahim\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\Dhan_Tradehull\__init__.py", line 1, in <module>
    from .Dhan_Tradehull import Tradehull
  File "C:\Users\mahim\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\Dhan_Tradehull\Dhan_Tradehull.py", line 1, in <module>
    from dhanhq import DhanContext, dhanhq, FullDepth, DhanLogin
ImportError: cannot import name 'DhanContext' from 'dhanhq' (C:\Users\mahim\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\dhanhq\__init__.py)

C:\Users\mahim\OneDrive\Documents\Nirav\Dhan\Basic Python\Code\3.1 Codebase Upgrade\3.1 Codebase Upgrade>pip show dhanhq
Name: dhanhq
Version: 2.0.2
Summary: The official Python client for communicating with the DhanHQ API
Home-page: https://dhanhq.co/
Author: Dhan
Author-email: dhan-oss@dhan.co
License: MIT LICENSE
Location: C:\Users\mahim\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages
Requires: pandas, pyOpenSSL, requests, websockets
Required-by: Dhan_Tradehull

Hi @niravbhanu ,

Check with the Dhan-Tradehull version and For updating and installation kindly check below codes

To install Dhan Tradehull package

pip install --pre dhanhq

pip install Dhan-Tradehull

Upgrade Dhan Package

To update the Dhan package

pip install --upgrade Dhan-Tradehull

Refer this link for Dhan-Tradehull -

@Tradehull_Imran thank you for your reply, able to run code till LTP fetching, post change of version from 2.0.2 to 2.2.0

error (Exception in Getting OHLC data as dhanhq.convert_to_date_time() takes 2 positional arguments but 3 were given)

As per given instructions; version upgraded to 2.2.0

Microsoft Windows [Version 10.0.26200.8246]
(c) Microsoft Corporation. All rights reserved.

C:\Users\mahim>pip install --pre dhanhq
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: dhanhq in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (2.0.2)
Requirement already satisfied: pandas>=1.4.3 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from dhanhq) (3.0.2)
Requirement already satisfied: requests>=2.28.1 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from dhanhq) (2.33.1)
Requirement already satisfied: websockets>=12.0.1 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from dhanhq) (16.0)
Requirement already satisfied: pyOpenSSL>=20.0.1 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from dhanhq) (26.1.0)
Requirement already satisfied: numpy>=1.26.0 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from pandas>=1.4.3->dhanhq) (2.4.4)
Requirement already satisfied: python-dateutil>=2.8.2 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from pandas>=1.4.3->dhanhq) (2.9.0.post0)
Requirement already satisfied: tzdata in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from pandas>=1.4.3->dhanhq) (2026.2)
Requirement already satisfied: cryptography<48,>=46.0.0 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from pyOpenSSL>=20.0.1->dhanhq) (47.0.0)
Requirement already satisfied: cffi>=2.0.0 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from cryptography<48,>=46.0.0->pyOpenSSL>=20.0.1->dhanhq) (2.0.0)
Requirement already satisfied: pycparser in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from cffi>=2.0.0->cryptography<48,>=46.0.0->pyOpenSSL>=20.0.1->dhanhq) (3.0)
Requirement already satisfied: six>=1.5 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from python-dateutil>=2.8.2->pandas>=1.4.3->dhanhq) (1.17.0)
Requirement already satisfied: charset_normalizer<4,>=2 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from requests>=2.28.1->dhanhq) (3.4.7)
Requirement already satisfied: idna<4,>=2.5 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from requests>=2.28.1->dhanhq) (3.13)
Requirement already satisfied: urllib3<3,>=1.26 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from requests>=2.28.1->dhanhq) (2.6.3)
Requirement already satisfied: certifi>=2023.5.7 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from requests>=2.28.1->dhanhq) (2026.4.22)

C:\Users\mahim>pip install Dhan-Tradehull
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: Dhan-Tradehull in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (3.2.1)
Collecting dhanhq>=2.1.0 (from Dhan-Tradehull)
  Using cached dhanhq-2.2.0-py3-none-any.whl.metadata (13 kB)
Requirement already satisfied: mibian>=0.1.3 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from Dhan-Tradehull) (0.1.3)
Requirement already satisfied: numpy>=1.24.4 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from Dhan-Tradehull) (2.4.4)
Requirement already satisfied: pandas>=2.0.3 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from Dhan-Tradehull) (3.0.2)
Requirement already satisfied: pytz>=2024.1 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from Dhan-Tradehull) (2026.1.post1)
Requirement already satisfied: requests>=2.32.3 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from Dhan-Tradehull) (2.33.1)
Requirement already satisfied: websocket-client>=1.8.0 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from Dhan-Tradehull) (1.9.0)
Requirement already satisfied: websockets>=12.0.1 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from dhanhq>=2.1.0->Dhan-Tradehull) (16.0)
Requirement already satisfied: pyOpenSSL>=20.0.1 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from dhanhq>=2.1.0->Dhan-Tradehull) (26.1.0)
Requirement already satisfied: python-dateutil>=2.8.2 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from pandas>=2.0.3->Dhan-Tradehull) (2.9.0.post0)
Requirement already satisfied: tzdata in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from pandas>=2.0.3->Dhan-Tradehull) (2026.2)
Requirement already satisfied: cryptography<48,>=46.0.0 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from pyOpenSSL>=20.0.1->dhanhq>=2.1.0->Dhan-Tradehull) (47.0.0)
Requirement already satisfied: cffi>=2.0.0 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from cryptography<48,>=46.0.0->pyOpenSSL>=20.0.1->dhanhq>=2.1.0->Dhan-Tradehull) (2.0.0)
Requirement already satisfied: pycparser in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from cffi>=2.0.0->cryptography<48,>=46.0.0->pyOpenSSL>=20.0.1->dhanhq>=2.1.0->Dhan-Tradehull) (3.0)
Requirement already satisfied: six>=1.5 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from python-dateutil>=2.8.2->pandas>=2.0.3->Dhan-Tradehull) (1.17.0)
Requirement already satisfied: charset_normalizer<4,>=2 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from requests>=2.32.3->Dhan-Tradehull) (3.4.7)
Requirement already satisfied: idna<4,>=2.5 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from requests>=2.32.3->Dhan-Tradehull) (3.13)
Requirement already satisfied: urllib3<3,>=1.26 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from requests>=2.32.3->Dhan-Tradehull) (2.6.3)
Requirement already satisfied: certifi>=2023.5.7 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from requests>=2.32.3->Dhan-Tradehull) (2026.4.22)
Using cached dhanhq-2.2.0-py3-none-any.whl (36 kB)
Installing collected packages: dhanhq
  Attempting uninstall: dhanhq
    Found existing installation: dhanhq 2.0.2
    Uninstalling dhanhq-2.0.2:
      Successfully uninstalled dhanhq-2.0.2
Successfully installed dhanhq-2.2.0

C:\Users\mahim>pip install --upgrade Dhan-Tradehull
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: Dhan-Tradehull in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (3.2.1)
Requirement already satisfied: dhanhq>=2.1.0 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from Dhan-Tradehull) (2.2.0)
Requirement already satisfied: mibian>=0.1.3 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from Dhan-Tradehull) (0.1.3)
Requirement already satisfied: numpy>=1.24.4 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from Dhan-Tradehull) (2.4.4)
Requirement already satisfied: pandas>=2.0.3 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from Dhan-Tradehull) (3.0.2)
Requirement already satisfied: pytz>=2024.1 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from Dhan-Tradehull) (2026.1.post1)
Requirement already satisfied: requests>=2.32.3 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from Dhan-Tradehull) (2.33.1)
Requirement already satisfied: websocket-client>=1.8.0 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from Dhan-Tradehull) (1.9.0)
Requirement already satisfied: websockets>=12.0.1 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from dhanhq>=2.1.0->Dhan-Tradehull) (16.0)
Requirement already satisfied: pyOpenSSL>=20.0.1 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from dhanhq>=2.1.0->Dhan-Tradehull) (26.1.0)
Requirement already satisfied: python-dateutil>=2.8.2 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from pandas>=2.0.3->Dhan-Tradehull) (2.9.0.post0)
Requirement already satisfied: tzdata in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from pandas>=2.0.3->Dhan-Tradehull) (2026.2)
Requirement already satisfied: cryptography<48,>=46.0.0 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from pyOpenSSL>=20.0.1->dhanhq>=2.1.0->Dhan-Tradehull) (47.0.0)
Requirement already satisfied: cffi>=2.0.0 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from cryptography<48,>=46.0.0->pyOpenSSL>=20.0.1->dhanhq>=2.1.0->Dhan-Tradehull) (2.0.0)
Requirement already satisfied: pycparser in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from cffi>=2.0.0->cryptography<48,>=46.0.0->pyOpenSSL>=20.0.1->dhanhq>=2.1.0->Dhan-Tradehull) (3.0)
Requirement already satisfied: six>=1.5 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from python-dateutil>=2.8.2->pandas>=2.0.3->Dhan-Tradehull) (1.17.0)
Requirement already satisfied: charset_normalizer<4,>=2 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from requests>=2.32.3->Dhan-Tradehull) (3.4.7)
Requirement already satisfied: idna<4,>=2.5 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from requests>=2.32.3->Dhan-Tradehull) (3.13)
Requirement already satisfied: urllib3<3,>=1.26 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from requests>=2.32.3->Dhan-Tradehull) (2.6.3)
Requirement already satisfied: certifi>=2023.5.7 in .\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages (from requests>=2.32.3->Dhan-Tradehull) (2026.4.22)

C:\Users\mahim>pip show dhanhq
Name: dhanhq
Version: 2.2.0
Summary: The official Python client for communicating with the DhanHQ API
Home-page: https://dhanhq.co/
Author: Dhan
Author-email: dhan-oss@dhan.co
License: MIT LICENSE
Location: C:\Users\mahim\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages
Requires: pandas, pyOpenSSL, requests, websockets
Required-by: Dhan_Tradehull

C:\Users\mahim>

Post version changed able to run code and able to fetch live data and received error for historical data given below;

error (Exception in Getting OHLC data as dhanhq.convert_to_date_time() takes 2 positional arguments but 3 were given)

Microsoft Windows [Version 10.0.26200.8246]
(c) Microsoft Corporation. All rights reserved.

C:\Users\mahim\OneDrive\Documents\Nirav\Dhan\Basic Python\Code\3.1 Codebase Upgrade\3.1 Codebase Upgrade>python V2.py
Codebase Version 3.2.1
Attempting authentication using ACCESS TOKEN.
reading existing file all_instrument 2026-04-28.csv
Already logged in for today, so reusing the token
Instrument file retrieved successfully
-----SUCCESSFULLY LOGGED INTO DHAN-----
[0] > c:\users\mahim\onedrive\documents\nirav\dhan\basic python\code\3.1 codebase upgrade\3.1 codebase upgrade\v2.py(15)<module>()
-> pdb.set_trace()
(Pdb++) chart = tsl.get_historical_data(tradingsymbol = 'NIFTY',  exchange = 'INDEX',timeframe="5")
Exception in Getting OHLC data as dhanhq.convert_to_date_time() takes 2 positional arguments but 3 were given
(Pdb++) all_ltp_data   = tsl.get_ltp_data(names = ['NIFTY 28 APR 24000 CALL', 'NIFTY 28 APR 24000 PUT', "ACC", "CIPLA"]\
)
(Pdb++) all_ltp_data   = tsl.get_ltp_data(names = ['NIFTY 28 APR 24000 CALL', 'NIFTY 28 APR 24000 PUT', "ACC", "CIPLA"]\
)all_ltp_data   = tsl.get_ltp_data(names = ['NIFTY 28 APR 24000 CALL', 'NIFTY 28 APR 24000 PUT', "ACC", "CIPLA"])
*** SyntaxError: invalid syntax
(Pdb++) all_ltp_data
{'ACC': 1441.0, 'CIPLA': 1307.7, 'NIFTY 28 APR 24000 CALL': 26.15, 'NIFTY 28 APR 24000 PUT': 4.25}
(Pdb++) stock_name = 'NIFTY'
(Pdb++) ltp   = tsl.get_ltp_data(names = [stock_name])[stock_name]
(Pdb++) ltp
24029.25
(Pdb++) chart = tsl.get_historical_data(tradingsymbol = 'NIFTY',  exchange = 'INDEX',timeframe="5")
Exception in Getting OHLC data as dhanhq.convert_to_date_time() takes 2 positional arguments but 3 were given
(Pdb++) chart
(Pdb++) data  = tsl.get_historical_data(tradingsymbol = 'NIFTY 28 APR 24000 CALL' ,exchange = 'NFO'  ,timeframe="15")
Exception in Getting OHLC data as dhanhq.convert_to_date_time() takes 2 positional arguments but 3 were given
(Pdb++) data
(Pdb++) data
(Pdb++) chart = tsl.get_historical_data(tradingsymbol = 'NIFTY',  exchange = 'INDEX',timeframe="DAY")
*** WARNING: file 'C:\Users\mahim\OneDrive\Documents\Nirav\Dhan\Basic Python\Code\3.1 Codebase Upgrade\3.1 Codebase Upgrade\V2.py' was edited, running stale code until the program is rerun
Exception in Getting OHLC data as dhanhq.convert_to_date_time() takes 2 positional arguments but 3 were given
(Pdb++)

Hi @niravbhanu ,

We have updated the Dhan-Tradehull Codebase . So reinstall again and use of it .

Refer this link -

Hi @niravbhanu

yes we have checked on this
This was causing the issue

error (Exception in Getting OHLC data as dhanhq.convert_to_date_time() takes 2 positional arguments but 3 were given)

we have updated the code again,
please install latest version

pip install Dhan-Tradehull==3.2.2