Learn Algo Trading with Python | Codes | Youtube Series

Hi @Maaz ,

Do update to our latest codebase and use the below function to fetch ltp data -

  data = tsl.get_ltp_data(names=['CRUDEOIL', 'NIFTY'])
  crudeoil_ltp = data['CRUDEOIL']

Refer the below thread to update to latest codebase -

@Tradehull_Imran Sir i have around 400-500 stocks in my wathclist and if run using loops it takes around 12-15 seconds for each stock to get scanned so 15*500 = ~2hrs for just one while loop cycle , suppose my strategy starts with 10am candle and by 10:05 it needs to complete the scan so how do i scan all my stocks in seconds , because it needs to keep on updating the values so the other conditions get satisfied if it will take minutes to just scan one cycle then the values wont get updated fast there will be a lag in price and order placement
I tried concurrent method instead of for loop but then i got ERROR-805 for
calling too many request and if i dont stop my account will be banned
Please provide a solution in such a way that i can scan my watchlist in around 10-15 seconds
Thank you

Exactly similar issue happeing with me.

Hi @Chandrapal_Singh ,

Do refer this thread and use the latest version of codebase to avoid this,

Hi @Harry ,

Tagging @Dhan for rate limits.

@Harry What are you fetching from APIs to prepare data for the scanner? May be separating the API calls (raw data) from scanning process (processed data) can help or may be Websocket. Your algo strategy architecture seems wrong.

Very Good Morning Sir, I have updayted my Access token for today. I tried executing the file “Working with optionchain.py” file. I am getting error at ‘vpcr’, also at line: ltp based strike selection sir. The Error is as follows: Please resolve sir. ERROR: C:\Users\Admin\Desktop\TRADES\Dhan Algo\11-01-2026-Algo Adv Stratgy\1. Option Chain>py “RP-Working With Optionchain.py”
Codebase Version 3.2.0
-----Trying to login using (ACCESS TOKEN)-----
This BOT Is Picking New File From Dhan
Got the instrument file
-----SUCCESSFULLY LOGGED INTO DHAN-----
Traceback (most recent call last):
File “C:\Users\Admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\indexes\base.py”, line 3641, in get_loc
return self._engine.get_loc(casted_key)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
File “pandas/_libs/index.pyx”, line 168, in pandas._libs.index.IndexEngine.get_loc
File “pandas/_libs/index.pyx”, line 197, in pandas._libs.index.IndexEngine.get_loc
File “pandas/_libs/hashtable_class_helper.pxi”, line 7668, in pandas._libs.hashtable.PyObjectHashTable.get_item
File “pandas/_libs/hashtable_class_helper.pxi”, line 7676, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: ‘PE VOLUME’

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “C:\Users\Admin\Desktop\TRADES\Dhan Algo\11-01-2026-Algo Adv Stratgy\1. Option Chain\RP-Working With Optionchain.py”, line 16, in
vpcr = option_chain[‘PE VOLUME’].sum() / option_chain[‘CE VOLUME’].sum()
~~~~~~~~~~~~^^^^^^^^^^^^^
File “C:\Users\Admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\frame.py”, line 4378, in getitem
indexer = self.columns.get_loc(key)
File “C:\Users\Admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\indexes\base.py”, line 3648, in get_loc
raise KeyError(key) from err
KeyError: ‘PE VOLUME’

C:\Users\Admin\Desktop\TRADES\Dhan Algo\11-01-2026-Algo Adv Stratgy\1. Option Chain>py “RP-Working With Optionchain.py”
Codebase Version 3.2.0
-----Trying to login using (ACCESS TOKEN)-----
reading existing file all_instrument 2026-02-25.csv
Already logged in for today, so reusing the token
Got the instrument file
-----SUCCESSFULLY LOGGED INTO DHAN-----
Traceback (most recent call last):
File “C:\Users\Admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\indexing.py”, line 993, in _validate_tuple_indexer
self._validate_key(k, i)
~~~~~~~~~~~~~~~~~~^^^^^^
File “C:\Users\Admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\indexing.py”, line 1635, in _validate_key
raise ValueError(f"Can only index by location with a [{self._valid_types}]")
ValueError: Can only index by location with a [integer, integer slice (START point is INCLUDED, END point is EXCLUDED), listlike of integers, boolean array]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “C:\Users\Admin\Desktop\TRADES\Dhan Algo\11-01-2026-Algo Adv Stratgy\1. Option Chain\RP-Working With Optionchain.py”, line 19, in
required_strike = option_chain.iloc[option_chain[‘CE LTP’] < 10, ‘Strike Price’].iloc[0] # Selected LTP price less than Rs.10/-
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\indexing.py”, line 1200, in getitem
return self._getitem_tuple(key)
~~~~~~~~~~~~~~~~~~~^^^^^
File “C:\Users\Admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\indexing.py”, line 1711, in _getitem_tuple
tup = self._validate_tuple_indexer(tup)
File “C:\Users\Admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\indexing.py”, line 995, in _validate_tuple_indexer
raise ValueError(
f"Location based indexing can only have [{self._valid_types}] types"
) from err
ValueError: Location based indexing can only have [integer, integer slice (START point is INCLUDED, END point is EXCLUDED), listlike of integers, boolean array] types

Hi @Vasili_Prasad ,

Once do add pdb and check data is been fetched.
Do share screenshot in which line you are facing issue.

Line: 3. Ltp based strike Selection

required_strike = option_chain.loc[option_chain[‘CE LTP’] < 10, ‘Strike Price’].iloc[0]

Latest Error Now: C:\Users\Admin\Desktop\TRADES\Dhan Algo\11-01-2026-Algo Adv Stratgy\1. Option Chain\1. Option Chain>py “Working with Option chain.py”
Codebase Version 3.2.0
-----Trying to login using (ACCESS TOKEN)-----
This BOT Is Picking New File From Dhan
Got the instrument file
-----SUCCESSFULLY LOGGED INTO DHAN-----
Traceback (most recent call last):
File “C:\Users\Admin\Desktop\TRADES\Dhan Algo\11-01-2026-Algo Adv Stratgy\1. Option Chain\1. Option Chain\Working with Option chain.py”, line 24, in
required_strike = option_chain.loc[option_chain[‘CE LTP’] < 10, ‘Strike Price’].iloc[0]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
File “C:\Users\Admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\indexing.py”, line 1207, in getitem
return self._getitem_axis(maybe_callable, axis=axis)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\indexing.py”, line 1773, in _getitem_axis
self._validate_integer(key, axis)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
File “C:\Users\Admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\indexing.py”, line 1706, in _validate_integer
raise IndexError(“single positional indexer is out-of-bounds”)
IndexError: single positional indexer is out-of-bounds

Imran is back live to solve all your questions and teach something new!

This time for a session on Option Buying using algos.

:date: March 06 (Friday)
:alarm_clock: 8:00 – 9:00 PM

In this live session, you’ll discover how algo trading can execute option buying strategies without manual intervention.

:small_blue_diamond: How algo option buying works
:small_blue_diamond: Setting predefined rules for entries
:small_blue_diamond: Removing emotional trading with automation
:small_blue_diamond: Real examples of automated trades

:backhand_index_pointing_right:t3: Enroll Here Now

@Tradehull_Imran

I am writing to report and seek clarification on a dependency issue encountered while attempting to install and use the latest version of the Dhan-Tradehull library. I have described the environment, steps performed, and the exact issue in detail below so your engineering team can review it.

Environment Details
Operating System: Windows 10 (64-bit)
Python Version: Python 3.12.9
pip Version: Latest version installed via python -m pip install --upgrade pip
Installation Method: Standard pip installation from PyPI

Initial Objective
I was attempting to install and use the latest version of the Dhan-Tradehull library available on PyPI for building an automated trading workflow using Python.

Step 1: Attempt to install the latest Tradehull package
I attempted to install the latest version using the following command:

pip install Dhan-Tradehull==3.2.0

However, pip failed with a dependency resolution error indicating that a required dependency could not be found.

Observed Error
The pip installer returned the following type of error message:

“Could not find a version that satisfies the requirement dhanhq >= 2.1.0 (from Dhan-Tradehull)”
“No matching distribution found for dhanhq >= 2.1.0”

Step 2: Verification of available dhanhq versions on PyPI
To investigate further, I checked the versions available for the dhanhq package using:

pip index versions dhanhq

The versions available on PyPI appeared to be:

1.x series versions
2.0.0
2.0.1
2.0.2
2.2.0rc1 (release candidate)

There was no stable release version >= 2.1.0 available.

Dependency Mismatch Identified
The latest Dhan-Tradehull version (3.2.0) appears to require:

dhanhq >= 2.1.0

However, since a stable dhanhq version >= 2.1.0 is not available on PyPI, pip cannot resolve this dependency during installation.

Step 3: pip fallback installation
Because of this mismatch, pip automatically installed the latest compatible combination that satisfied available dependencies:

Dhan-Tradehull 3.0.6
dhanhq 2.0.2

This environment worked correctly and the API was functional.

Verification performed using:

pip show Dhan-Tradehull
pip show dhanhq

Resulting environment:

Python 3.12.9
Dhan-Tradehull 3.0.6
dhanhq 2.0.2

API calls such as authentication, LTP retrieval, ATM strike selection, and option LTP queries worked successfully with this configuration.

Step 4: Testing updated codebase provided by the community
In addition to the pip package, I also tested the updated local codebase file provided in the community:

Dhan_Tradehull_V2.py

This codebase reports internally:

“Codebase Version 2.8 : Solved - Strike Selection Issue”

Using this implementation with dhanhq 2.0.2 also worked correctly for the following functions:

get_ltp_data()
ATM_Strike_Selection()
get_live_pnl()
Instrument file loading
Spot and option LTP retrieval

Current Understanding
Based on the above testing, the main issue appears to be a dependency mismatch in the PyPI release.

Specifically:

The latest version of Dhan-Tradehull requires dhanhq >= 2.1.0
However, a stable dhanhq version >= 2.1.0 does not appear to be available on PyPI.

Because of this, installing the latest Tradehull version in a clean Python environment fails.

Questions for the Engineering Team

  1. Has dhanhq >= 2.1.0 been officially released but not published on PyPI?

  2. Is the dependency requirement in Dhan-Tradehull 3.2.x intended to be dhanhq >= 2.0.x instead?

  3. Is there a recommended stable combination of versions that should currently be used for production environments?

  4. Will a corrected dependency version be published for the Tradehull package?

My goal is to ensure that I am using the officially supported and stable library versions for building an automated trading workflow.

If there is updated documentation or a recommended installation method for the latest versions, I would appreciate guidance.

Thank you for your support and for maintaining the API ecosystem.

Hi @Dpwd ,

Refer the below thread -

steps for installation -
Dhan_Tradehull Library Update: Python 3.12 & Authentication Improvements - APIs, Automation, Algos & Code - MadeForTrade

@Tradehull_Imran
Thank you
I have used it and issue is solved

As it is a pre released so is it stable or still improvements are going on.
Can it be deployed in the live market ?

Hi @Dpwd ,

Yes it can be deployed in live market.

Hey @Tradehull_Imran sir, I’m currently building a Python script to automate my Options trading on Windows. I plan to hold my positions until expiry rather than squaring them off intraday.Which trade_type should I pass to the API to ensure the position isn’t auto-closed at the end of the session? Based on the standard types (MIS, MARGIN, MTF, CO, BO, CNC), I believe MARGIN is the correct one for positional F&O, but I wanted to double-check if anyone has had issues with auto-square-offs using this flag. Thanks!

1 Like

Hi @Rakesh_Durgam ,

You can pass trade_type as CNC for positional trades.