Learn Algo Trading with Python | Codes | Youtube Series

Hi @Tradehull_Imran
I am facing issue after pasting chart in pdb its not fetching data

import pdb
from Dhan_Tradehull import Tradehull
import pandas as pd
import talib

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


watchlist = ['MOTHERSON', 'OFSS', 'MANAPPURAM', 'BSOFT', 'CHAMBLFERT', 'DIXON', 'NATIONALUM', 'DLF', 'IDEA', 'ADANIPORTS', 'SAIL', 'HINDCOPPER', 'INDIGO', 'RECLTD', 'PNB', 'HINDALCO', 'RBLBANK', 'GNFC', 'ALKEM', 'CONCOR', 'PFC', 'GODREJPROP', 'MARUTI', 'ADANIENT', 'ONGC', 'CANBK', 'OBEROIRLTY', 'BANDHANBNK', 'SBIN', 'HINDPETRO', 'CANFINHOME', 'TATAMOTORS', 'LALPATHLAB', 'MCX', 'TATACHEM', 'BHARTIARTL', 'INDIAMART', 'LUPIN', 'INDUSTOWER', 'VEDL', 'SHRIRAMFIN', 'POLYCAB', 'WIPRO', 'UBL', 'SRF', 'BHARATFORG', 'GRASIM', 'IEX', 'BATAINDIA', 'AARTIIND', 'TATASTEEL', 'UPL', 'HDFCBANK', 'LTF', 'TVSMOTOR', 'GMRINFRA', 'IOC', 'ABCAPITAL', 'ACC', 'IDFCFIRSTB', 'ABFRL', 'ZYDUSLIFE', 'GLENMARK', 'TATAPOWER', 'PEL', 'IDFC', 'LAURUSLABS', 'BANKBARODA', 'KOTAKBANK', 'CUB', 'GAIL', 'DABUR', 'TECHM', 'CHOLAFIN', 'BEL', 'SYNGENE', 'FEDERALBNK', 'NAVINFLUOR', 'AXISBANK', 'LT', 'ICICIGI', 'EXIDEIND', 'TATACOMM', 'RELIANCE', 'ICICIPRULI', 'IPCALAB', 'AUBANK', 'INDIACEM', 'GRANULES', 'HDFCAMC', 'COFORGE', 'LICHSGFIN', 'BAJAJFINSV', 'INFY', 'BRITANNIA', 'M&MFIN', 'BAJFINANCE', 'PIIND', 'DEEPAKNTR', 'SHREECEM', 'INDUSINDBK', 'DRREDDY', 'TCS', 'BPCL', 'PETRONET', 'NAUKRI', 'JSWSTEEL', 'MUTHOOTFIN', 'CUMMINSIND', 'CROMPTON', 'M&M', 'GODREJCP', 'IGL', 'BAJAJ-AUTO', 'HEROMOTOCO', 'AMBUJACEM', 'BIOCON', 'ULTRACEMCO', 'VOLTAS', 'BALRAMCHIN', 'SUNPHARMA', 'ASIANPAINT', 'COALINDIA', 'SUNTV', 'EICHERMOT', 'ESCORTS', 'HAL', 'ASTRAL', 'NMDC', 'ICICIBANK', 'TORNTPHARM', 'JUBLFOOD', 'METROPOLIS', 'RAMCOCEM', 'INDHOTEL', 'HINDUNILVR', 'TRENT', 'TITAN', 'JKCEMENT', 'ASHOKLEY', 'SBICARD', 'BERGEPAINT', 'JINDALSTEL', 'MFSL', 'BHEL', 'NESTLEIND', 'HDFCLIFE', 'COROMANDEL', 'DIVISLAB', 'ITC', 'TATACONSUM', 'APOLLOTYRE', 'AUROPHARMA', 'HCLTECH', 'LTTS', 'BALKRISIND', 'DALBHARAT', 'APOLLOHOSP', 'ABBOTINDIA', 'ATUL', 'UNITDSPR', 'PVRINOX', 'SIEMENS', 'SBILIFE', 'IRCTC', 'GUJGASLTD', 'BOSCHLTD', 'NTPC', 'POWERGRID', 'MARICO', 'HAVELLS', 'MPHASIS', 'COLPAL', 'CIPLA', 'MGL', 'ABB', 'PIDILITIND', 'MRF', 'LTIM', 'PAGEIND', 'PERSISTENT']

for stock_name in watchlist:
    print(stock_name)
    chart = tsl.get_intraday_data(stock_name, 'NSE',1)
    print(stock_name)
    

    pdb.set_trace()

* List item

error

C:\Users\Rahul\Desktop\Dhan API\6. Session6- 1st Live Algo\1st live Algo>py "Dhan_codebase usage - Copy.py"
-----Logged into Dhan-----
reading existing file all_instrument 2025-08-13.csv
Got the instrument file
MOTHERSON
intraday_minute_data() missing 2 required positional arguments: 'from_date' and 'to_date'
Traceback (most recent call last):
  File "C:\Users\Rahul\Desktop\Dhan API\6. Session6- 1st Live Algo\1st live Algo\Dhan_Tradehull.py", line 253, in get_intraday_data
    ohlc = self.Dhan.intraday_minute_data(str(security_id),exchangeSegment,instrument_type)
TypeError: intraday_minute_data() missing 2 required positional arguments: 'from_date' and 'to_date'
MOTHERSON
[0] > ←[33;01mc:\users\rahul\desktop\dhan api\6. session6- 1st live algo\1st live algo\dhan_codebase usage - copy.py←[00m(←[36;01m13←[00m)<module>()
-> ←[94mfor←[39;49;00m stock_name ←[95min←[39;49;00m watchlist:←[90m←[39;49;00m
(Pdb++) chart
(Pdb++)

all_instrument 2025-08-16.csv

I am not getting this file

Hi @Tradehull_Imran ,

the below mentioned error is appearing while running the code.

Error is :

exception got in ce_pe_option_df ‘<’ not supported between instances of ‘int’ and ‘str’
Getting Error at OTM strike Selection as ‘<’ not supported between instances of ‘int’ and ‘str’
Getting Error at OTM strike Selection as ‘<’ not supported between instances of ‘int’ and ‘str’
‘NoneType’ object has no attribute ‘upper’
Traceback (most recent call last):
File “C:\Users\SVIMS CAO\OneDrive\Desktop\Python\Revised\Dhan_Tradehull_V2.py”, line 516, in get_intraday_data
tradingsymbol = tradingsymbol.upper()
AttributeError: ‘NoneType’ object has no attribute ‘upper’
Traceback (most recent call last):
File “C:\Users\SVIMS CAO\OneDrive\Desktop\Python\Revised\Dhan_codebase usage.py”, line 52, in
intraday_hist_data[‘rsi’] = talib.RSI(intraday_hist_data[‘close’], timeperiod=14)
TypeError: ‘NoneType’ object is not subscriptable

Above mentioned error is appearing. i am using the Updated version of Dhan_Tradehull_V2.py file and Dhan Code base usage. Please check and guide me the possible solution

Use Dhan_Tradehull_V2 code base

it will auto download once you start running your codebase code


how do i solve this
?

Hi @Tradehull_Imran ,
Greetings for the eve :tada:

I’m using following code.
Here I’m fetching quote data,
But it almost takes 1min 16 sec to retrieve the required data.
How can we fetch the data with minimal time by using multiple Token Id or by any means.
If I scan for Nifty FNO stocks all the intraday time will go on scanning only.
Please help me out.
TIA :smiley:

SetExpiry = 0
Ops_S0_CE, Ops_S0_PE, ATM_Strike = tsl.ATM_Strike_Selection(Underlying = ListName, Expiry = SetExpiry)

U1_CE_Strike, U1_PE_Strike, U1_CE_Price, U1_PE_Price = tsl.OTM_Strike_Selection(Underlying = ListName, Expiry = SetExpiry, OTM_count = 1)
U2_CE_Strike, U2_PE_Strike, U2_CE_Price, U2_PE_Price = tsl.OTM_Strike_Selection(Underlying = ListName, Expiry = SetExpiry, OTM_count = 2)
U3_CE_Strike, U3_PE_Strike, U3_CE_Price, U3_PE_Price = tsl.OTM_Strike_Selection(Underlying = ListName, Expiry = SetExpiry, OTM_count = 3)
U4_CE_Strike, U4_PE_Strike, U4_CE_Price, U4_PE_Price = tsl.OTM_Strike_Selection(Underlying = ListName, Expiry = SetExpiry, OTM_count = 4)
U5_CE_Strike, U5_PE_Strike, U5_CE_Price, U5_PE_Price = tsl.OTM_Strike_Selection(Underlying = ListName, Expiry = SetExpiry, OTM_count = 5)

L1_CE_Strike, L1_PE_Strike, L1_CE_Price, L1_PE_Price = tsl.ITM_Strike_Selection(Underlying = ListName, Expiry = SetExpiry, ITM_count = 1)
L2_CE_Strike, L2_PE_Strike, L2_CE_Price, L2_PE_Price = tsl.ITM_Strike_Selection(Underlying = ListName, Expiry = SetExpiry, ITM_count = 2)
L3_CE_Strike, L3_PE_Strike, L3_CE_Price, L3_PE_Price = tsl.ITM_Strike_Selection(Underlying = ListName, Expiry = SetExpiry, ITM_count = 3)
L4_CE_Strike, L4_PE_Strike, L4_CE_Price, L4_PE_Price = tsl.ITM_Strike_Selection(Underlying = ListName, Expiry = SetExpiry, ITM_count = 4)
L5_CE_Strike, L5_PE_Strike, L5_CE_Price, L5_PE_Price = tsl.ITM_Strike_Selection(Underlying = ListName, Expiry = SetExpiry, ITM_count = 5)

Hi @Tradehull_Imran ,
Greetings !!

I am very new to Algo Trading but i am very much want to follow you video series.

when i am running how to use updated codebase.py i am getting the below error in the begining itself. please help me resolve it.

Mibian requires scipy to work properly
Codebase Version 3
-----Logged into Dhan-----
dhanhq.init() takes 2 positional arguments but 3 were given
‘Tradehull’ object has no attribute ‘response’
Traceback (most recent call last):
File “C:\Users\pri\AppData\Local\Programs\Python\Python313\Lib\site-packages\Dhan_Tradehull\Dhan_Tradehull.py”, line 74, in get_login
self.Dhan = dhanhq(self.ClientCode, self.token_id)
~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: dhanhq.init() takes 2 positional arguments but 3 were given

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:\Users\pri\AppData\Local\Programs\Python\Python313\Lib\site-packages\Dhan_Tradehull\Dhan_Tradehull.py”, line 52, in init
self.get_login(ClientCode,token_id)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\pri\AppData\Local\Programs\Python\Python313\Lib\site-packages\Dhan_Tradehull\Dhan_Tradehull.py”, line 80, in get_login
print(self.response)
^^^^^^^^^^^^^
AttributeError: ‘Tradehull’ object has no attribute ‘response’
Exception at calling ltp as ‘Tradehull’ object has no attribute ‘instrument_df’
PS C:\Users\pri\python learning>

Hello Imran Sir

what is the use of these two lines ?

get_quote and get_ltp are throwing error …

→ ltp = tsl.get_ltp_data(names = [‘NIFTY 28 AUG 24000 CALL’, ‘NIFTY 28 AUG 24000 PUT’])
(Pdb++) n
Exception for instrument name NIFTY 28 AUG 24000 CALL as Check the Tradingsymbol
Exception for instrument name NIFTY 28 AUG 24000 PUT as Check the Tradingsymbol
[0] > ←[33;01mg:\sree\test\2.py←[00m(←[36;01m33←[00m)()
→ print(ltp)

actual code is …

ltp = tsl.get_ltp_data(names = [‘NIFTY 28 AUG 24000 CALL’, ‘NIFTY 28 AUG 24000 PUT’])
print(ltp)

Is there any one to respond … Algos are not fetching any sort of data from past 2 days which were working fine earlier. Is it a techinical glitch. Whom should I contact regarding this …

Hey @Tradehull_Imran Sir,
good day! thanks for all your contribution.

I need a help for resolving the error, pls help me for the same.

Its resolved now, thanks!

import pdb	
from Dhan_Tradehull import Tradehull

client_code = "XXX"
token_id = "XXXX"
tsl = Tradehull(client_code,token_id)


for distance in range(1,10):
	
	ce_name, pe_name, ce_strike, pe_strike = tsl.OTM_Strike_Selection(Underlying='NIFTY', Expiry=0, OTM_count=distance)
	#print(distance,"---",ce_name,"---", pe_name,"---",ce_strike,"---",pe_strike)
	ce_ltp_data   = tsl.get_ltp_data(ce_name)
	if ce_ltp_data < 10:
		print(ce_name,ce_ltp_data)

and my error is


C:\Users\Admin\Desktop\Dhan Algo\5. Session5- Python Part 2\5. Session5- Python Part 2>py "Session 5.py"
Codebase Version 3
-----Logged into Dhan-----
reading existing file all_instrument 2025-08-29.csv
Got the instrument file
Traceback (most recent call last):
  File "Session 5.py", line 14, in <module>
    if ce_ltp_data < 10:
TypeError: '<' not supported between instances of 'dict' and 'int'

C:\Users\Admin\Desktop\Dhan Algo\5. Session5- Python Part 2\5. Session5- Python Part 2>

am not able to install libraries as i have the latest python installed its showing error