Learn Algo Trading with Python | Codes | Youtube Series

Hi @abhishekku16 ,

Seems like you have not subscribed for data API.

Follow below steps to Subscribe for Data API:

  1. Go to Profile Section
  2. Select “Dhan HQ Trading API”
  3. Switch to Data API tab
  4. Click Subscribe
  5. Revoke the access token and try
    Once you have active subscription you will be able to fetch historical and live data.

Hi @Rajashekhar_Rangappa ,

We have upgraded our files to pip and currently there is no link for Dhan_Tradehull_V3.
If you wish to get the location of the file you can run pip show Dhan-Tradehull and get the location from there.

Hi @Tradehull_Imran sir,
abhi toh code sahi chal raha, maine kuch bhi change nahi kia. Ye kaise possible hai.
Please see the screenshot, ye error aa raha tha. Iska reason kya ho skta hai

Hi @Tradehull_Imran sir,


Please see the screenshot. same code sahi chala ek baar, aur jab firse run kra ab ye error aa raha

Dear Sir,

Sorry i had missed to to install libraries.
i went through session 2 and its working. now i m at 3.1.
my objective is to trade only

  1. weekly SENSEX - Entry Monday and exit Tuesday
  2. and weekly NIFTY - Entry Wednesday and exit Thrusday

Book Profit at 1% or move out at loss of 1% of capital.
Trying to learn Delta neutral for this strategy.

1 Like

Thanks @Tradehull_Imran . Suggested ltp code is working fine.
I see all_instrument 2025… csv is not updating it seems. It is showing last year data and all expired info too.
Is there any update needed?

Also some times giving tsl error

    import tsl
ModuleNotFoundError: No module named 'tsl'

Hello @Tradehull_Imran Sir,
Not able to retrieve Option chain for crudeoil. please can you share the code for getting option chain for crudeoil or natgast? My code is mentioned below along with error,

Blockquote
(Pdb++) atm_strike, option_chain = tsl.get_option_chain(Underlying=“CRUDEOIL”, exchange=“MCX”, expiry=expiry_seq, num_strikes=1) Getting Error at Option Chain as No option chain data available for the CRUDEOIL
*** TypeError: cannot unpack non-iterable NoneType object
(Pdb++) pip show Dhan-Tradehull
*** SyntaxError: invalid syntax

@Tradehull_Imran
Hello sir when I am running this code ----

I am getting an error like this ----
Traceback (most recent call last):
File “C:\TheAlgoTrader\S6_1st_algo\Dhan codebase S6\Dhan_Tradehull.py”, line 139, in order_placement
orderid = order[“data”][“orderId”]
KeyError: ‘orderId’

What is the problem? I can’t understand. How to fix it?

Hi Rahul,

Getting below error when executing “Dhan_codebase usage.py”

Hi @Tradehull_Imran ,
Greetings for the day…!

I want to get the executed price of this order,
or the price of Options strike as per the Order Id/order time for Rejected order.
I tried on my own but didn’t crack it.

Dhan Order Id: 2225040713722
Order Time: 07 Apr 2025 09:15:21

TIA :slightly_smiling_face:

Python 3.8.0 is not being detected. What to do

Hi @narayan_uppu ,

You can install Talib before importing it using :

pip install TA-Lib

Let me know if you are facing issue.

Hi @Lekhini ,

Instrument file is provided by dhan api and is updated everyday. No updation is required.

tsl is initialized when login process happens as :

from Dhan_Tradehull import Tradehull
tsl = Tradehull(client_code,token_id)

Hi @rohit2312 ,

Handle the exceptions by using try and except block as below:

for name in watchlist:
    try:
        current_time = datetime.datetime.now()
        chart = tsl.get_historical_data(tradingsymbol= name, exchange='NSE', timeframe="5")
        
        chart['EMA_5'] = ta.ema(chart['close'], length=5)
        chart['EMA_20'] = ta.ema(chart['close'], length=20)

        # make inicators rsi
        chart['rsi'] = talib.RSI(chart['close'], timeperiod=14)

        # CCI Indicator
        chart['CCI'] = talib.CCI(chart['high'], chart['low'], chart['close'], timeperiod=14)
        # pdb.set_trace()

        # completed_candle
        cc = chart.iloc[-2]

        # buy entry conditions
        bc1 = cc['EMA_5'] > cc['EMA_20']
        bc2 = cc['rsi'] > 60
        bc3 = cc['CCI'] > 100

        # sell entry conditions
        sc1 = cc['EMA_5'] < cc['EMA_20']
        sc2 = cc['rsi'] < 40
        sc3 = cc['CCI'] <-100

        if bc1 and bc2 and bc3:
            print("buy ", name)


        if sc1 and sc2 and sc3:
            print("sell ", name)
    except Exception as e:
        print(e)
        continue

Hi @saurabha213 ,

The code seems to be right but currently data is not available from the api. We are looking onto this issue.

1 Like

Hi @Trideb ,

Itseems that orderId is not present in order[“data”]. Make sure orderId is present within the order dictionary.

Hi @Akshay_Bawane ,

Executed price cannot be fetched for a rejected order.

Hi @Tradehull_Imran Sir,

I called index values for NIFTY, BANKNIFTY, FINNIFTY

But not able to call:
** “NIFTYAUTO”, **
** “NIFTYIT”, **
** “NIFTYFMCG”,**
** “NIFTYMETAL”, **
** “NIFTYPHARMA”, **
** “NIFTYREALTY”,**
** “NIFTYMEDIA”, **
** “NIFTYHEALTHCARE”,**

Kindly provide trading symbol/codes and guide how to get it

Very Good Morning sir. Last night I have watched the last and latest Session 11, posted yesterday. I am bit disappointed to note that No soild examples are given for rule sets and backtesting.

I sincerely feel that some more explanatory sessions are required on this important subject of application of Backtesting & Optimaization sir.

And how to integrate the Back tested and optimized results with actual Trading algo sir.

Also I have requested to explain on integrating Algo with Telegram, with an example. Kindly do it sir.

VBR Prasad

2 Likes

Getting below error when i am trying to run my code just now.

Blockquote
Traceback (most recent call last):
File “16. Tick By Tick data storage_abcd.py”, line 5, in
from Dhan_Tradehull import Tradehull
File “C:\Users\abcd\AppData\Local\Programs\Python\Python38\lib\site-packages\Dhan_Tradehull_init_.py”, line 1, in
from .Dhan_Tradehull import Tradehull
File “C:\Users\abcd\AppData\Local\Programs\Python\Python38\lib\site-packages\Dhan_Tradehull\Dhan_Tradehull.py”, line 2, in
import mibian
File “C:\Users\abcd\AppData\Local\Programs\Python\Python38\lib\site-packages\mibian_init_.py”, line 9, in
from scipy.stats import norm
File “C:\Users\abcd\AppData\Local\Programs\Python\Python38\lib\site-packages\scipy\stats_init_.py”, line 485, in
from .stats_py import *
File “C:\Users\abcd\AppData\Local\Programs\Python\Python38\lib\site-packages\scipy\stats_stats_py.py”, line 39, in
from scipy.spatial.distance import cdist
File "C:\Users\abcd\AppData\Local\Programs\Python\Python38\lib\site-packages\scipy\spatial_init
.py", line 105, in
from ._kdtree import *
File “C:\Users\abcd\AppData\Local\Programs\Python\Python38\lib\site-packages\scipy\spatial_kdtree.py”, line 4, in
from ._ckdtree import cKDTree, cKDTreeNode
File “ckdtree.pyx", line 10, in init scipy.spatial.ckdtree
File "C:\Users\abcd\AppData\Local\Programs\Python\Python38\lib\site-packages\scipy\sparse_init
.py", line 283, in
from . import csgraph
File "C:\Users\abcd\AppData\Local\Programs\Python\Python38\lib\site-packages\scipy\sparse\csgraph_init
.py”, line 185, in
from .laplacian import laplacian
File “C:\Users\abcd\AppData\Local\Programs\Python\Python38\lib\site-packages\scipy\sparse\csgraph_laplacian.py”, line 7, in
from scipy.sparse.linalg import LinearOperator
File "C:\Users\abcd\AppData\Local\Programs\Python\Python38\lib\site-packages\scipy\sparse\linalg_init
.py", line 120, in
from .isolve import *
File "C:\Users\abcd\AppData\Local\Programs\Python\Python38\lib\site-packages\scipy\sparse\linalg_isolve_init
.py", line 4, in
from .iterative import *
File “C:\Users\abcd\AppData\Local\Programs\Python\Python38\lib\site-packages\scipy\sparse\linalg_isolve\iterative.py”, line 11, in
from scipy.sparse.linalg._interface import LinearOperator
File “”, line 991, in _find_and_load
File “”, line 975, in _find_and_load_unlocked
File “”, line 671, in _load_unlocked
File “”, line 779, in exec_module
File “”, line 911, in get_code
File “”, line 580, in _compile_bytecode
ValueError: bad marshal data (unknown type code)

Blockquote
D:>pip show Dhan-Tradehull
Name: Dhan_Tradehull
Version: 3.0.6
Summary: A Dhan Codebase from TradeHull