Advanced Algo Trading 2026 | Codes | Youtube

(Pdb++) data = tsl.get_expired_option_data(tradingsymbol=name,exchange=“NFO”,interval=1,expiry_flag=“WEEK”,expiry_code=1,strike=“ATM”,option_type=“CALL”,from_date=from_date,to_date=expiry)
*** AttributeError: ‘Tradehull’ object has no attribute ‘get_expired_option_data’

Getting this error while executing the code. pl guide sir.

Hi @ayaa

let us know which codebase and dhanhq version are you using
check by sending below commands on cmd

pip show Dhan-Tradehull
pip show dhanhq

Why is the part 2 shows as private? Any backup link?

Hi @sagh
Tagging @Dhan for same

hi ,
i do have a dhan account , i am able to generate the access token and at last the csv files also in my system.
but the issue is they are coming up as 1 kb files and there is no data in it .
what do i do PLEASE GUIDE.

Hi @SANDESH_Agrawal
can you share the code as well, that you have used
Also is data subscription also active

Hi @Tradehull_Imran ,

I created algo strategy and storing trade log history for trades taken. I am trying to calculate ROI% metric and facing some challenges in calculating capital/margin used by strategies.

For simple equity or option buying trades calculation is simple like Qty * Buy price.
But when I am trying to calculate it for complex options strategies like Bull Call Spread, Short Iron Condor, or Straddle then I am unable to calculate accurate margin value which is visible on Dhan Options portal.

Is there any way to calculate it using Python program or Dhan api? It should match with Dhan Options platform.

Please guide me on this. Thank you in advance!

Hi @Siddhesh_Amrute
Nice to see you after a long time

try with multi order margin calculator

1 Like

Thank you for your response it worked and I am able to get more accurate numbers now.
Your memory is so sharp you still remember my name even after long time.

I was not active on community but I was continuously watching your videos on youtube and building my own platform which is almost complete now.

Keep sharing your knowledge with us about Algo Trading its really helpful. Appreciate your efforts and Dhan!

1 Like

Dhan data is different from Tradingview, Zerodha and Chartink! I backtested my strategy on Tradingview and was going to get data from Dhan API but I am seeing mismatches in the data! I just want to know whether this mismatch is in the chart only or also in the data. (I am unable to attach more than one image)

Close price of GODREJCP 5min candle opened at 9:35
Dhan : 1042.8
Tradingview : 1042.3
Chartink : 1042.3
Zerodha : 1042.3

Hi @Shinchan

All platforms are technically correct. as each platform captures snapshot data per candle from lakhs of actual ticks, so OHLC values will naturally vary slightly between platforms.

like in the quoted example, prices differ by 2-3 ticks, which is nearly 0.05% variance

To get a more aligned data, we may backtest and make live algo using Dhan api, so that platform remains same, and we can remove the slight variance by this method

Hello sir, Is the algo for directional option selling available now?

Hi @prashantjawale21 ,

Its still in progress. Once done will update it.

Very Good Morning Sir. You have started another New series: ‘AI and Algos by Dhan’ I could not traceout the code snippets of these series. What exactly the link, if I have missed them to traceout sir. Thanks a lot sir for all your efforts at Dhan.

Hi @Vasili_Prasad ,

The code snippets are available in these posts along with the corresponding videos. Kindly refer to them.

https://madefortrade.in/t/algo-api-strategy-codes-youtube/63991?u=tradehull_imran

Screenshot 2026-07-03 191126

How can I solve this error?

I downloaded the latest version (Session 3), but the Dhan_websocket.py file is missing. I tried using data.py instead, but it is not working.

Below are the steps I have completed:

1.install libraries.bat – Installed :white_check_mark:

2.python-3.8.0-amd64.exe – Installed :white_check_mark:

3.sublime_text_build_4152_x64_setup.exe – Installed :white_check_mark:

4.Excel – Enabled :white_check_mark:

5.Latest Version (Session 3) – Downloaded :white_check_mark:

6.Dhan_websocket.py – Missing from Session 3 :cross_mark:

 I tried using data.py, but it is not working.

7.data.py

 client_code – Updated ✅
 token_id – Updated ✅

8. Dhan_codebase usage.py

 client_code – Updated ✅
token_id – I couldn’t find any place to paste the token_id. Is there a specific line or option where it should be added?

9. Dhan_Tradehull.py

client_code – I couldn’t find any place to paste the client_code.
token_id – I couldn’t find any place to paste the token_id.
  1. Dhan Data API Monthly Plan (₹499/month) – Purchased :white_check_mark:

1 Ran the command:

 pip install dhanhq==2.2.0

but it shows some errors.

Issue- Excel data is not updating. :cross_mark:

Issue- Excel is not opening. :cross_mark:

Could you please check the attached screenshots and help me identify what is causing these issues? I would appreciate your guidance on how to fix them.

Hi @Nibu ,

Try the following steps to resolve the installation error. Once the installation issue is resolved, everything should work as expected.

Step 1: Check Python version

python --version

Step 2: Check pip version

python -m pip --version

Step 3: Upgrade pip

python -m ensurepip --upgrade

Step 4: Upgrade required packages

python -m pip install --upgrade pip setuptools wheel certifi

Step 5: Install DhanHQ

python -m pip install dhanhq==2.2.0

Step 6: If the SSL error still comes, use this command

python -m pip install dhanhq==2.2.0 --trusted-host pypi.org --trusted-host files.pythonhosted.org