Learn Algo Trading with Python | Codes | Youtube Series

@Tradehull_Imran sir how do I make 2,3,6 or any other minute timeframe which is not available directly, how do I write the code for it ?

Hi @Prasad_Magar, I am currently in face of building algo using dhan api and currently in managing in market feed data usage using ticker and quote.Will you able to share codebase link or repo

Hi Team, @Tradehull_Imran

We are getting an exception for get_ltp_data function after updating Dhan_Tradehull 3.1.2 version

Error: Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}

@Tradehull_Imran Sir if i want get a particular candle based on the time then how do i do it?

Hi @Prasad_Magar ,

Yes do share the details.

Hi @Harry ,

You can resample the data. Firstly fetch 1min timeframe data and use in the below function -

tsl.resample_timeframe(df, timeframe='2T') # for 2 min data

Hi @Surendra_Singh1 ,

The access token might be expired, do regenerate the access token and try again.

Hi @Tradehull_Imran sir

code - ltp_data = trading_session.get_ltp_data(names=symbols)

If the access token has expired, it should have an impacted on other functions like get holdings, intraday data etc but i am getting exceptions only for get_ltp_data function after updating Dhan_Tradehull 3.1.2 version

Error: Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}

Hi @Tradehull_Imran Sir,
I want to calculate the “maximum profit”, and “maximum loss” from basket orders using Python before placing live trades.
And,
is there a way to caluclate “overall margin, final margin”
using python

1 Like

Hi @Harry ,

Refer the below code-

data  = tsl.get_historical_data(tradingsymbol = 'TCS',exchange = 'NSE' ,timeframe="1")
data["timestamp"] = pd.to_datetime(data["timestamp"])
candle_data = data.loc[data["timestamp"] == pd.Timestamp("2026-01-30 15:25:00+05:30")]

Hi @Surendra_Singh1 ,

We will check on this.

Hi @Rakesh_Durgam ,

Use this formula for max profit and loss calculation
For basket order margin, Dhan is already building it will update once live.
Tagging @Dhan for same.

@Tradehull_Imran Sir

लंबे समय के बाद गुरु के चरणों में प्रणाम ।

सर लम्बे समय से एक रणनीति पर काम कर रहा था, हमने इसका नाम "Smart Aalgo Traders " Strategy रख। है,

जिसका एक साल का पिछला परीक्षण परिणाम मुझे चौका रहा है, जो कि “निफ्टी” है। ये आपकी शिक्षा का परिणाम है।

1 Like

How Can I get India Vix data from live API ?
@Hardik @Tradehull_Imran sir

After running the below command in cmd:

pip install Dhan-Tradehull

I developed the following script in sublime text:

Hi @vedvishwa ,

Do refer the below thread and follow all the steps and update -

Hi @Subhajitpanja ,

You can fetch the live LTP using the below code-

ltp_data = tsl.get_ltp_data(["INDIA VIX"])
1 Like

Hi Sir,

I am trying to run Dhan_codebase.py file but getting following error. My API connection has happened successfully as my Dhan balance gets printed properly. Please note still I haven’t subscribed to data API-

/Users/apple/PycharmProjects/PythonProject-Dhan-API/.venv/bin/python /Users/apple/PycharmProjects/PythonProject-Dhan-API/3. Session3 - Codebase1/Dhan codebase/Dhan_codebase usage.py
Mibian requires scipy to work properly
-----Logged into Dhan-----
This BOT Is Picking New File From Dhan
Got the instrument file
Traceback (most recent call last):
File “/Users/apple/PycharmProjects/PythonProject-Dhan-API/3. Session3 - Codebase1/Dhan codebase/Dhan_Tradehull.py”, line 258, in get_intraday_data
ohlc = self.Dhan.intraday_minute_data(str(security_id), exchangeSegment, instrument_type)
TypeError: dhanhq.intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
dhanhq.intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
dhanhq.intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
Traceback (most recent call last):
File “/Users/apple/PycharmProjects/PythonProject-Dhan-API/3. Session3 - Codebase1/Dhan codebase/Dhan_Tradehull.py”, line 258, in get_intraday_data
ohlc = self.Dhan.intraday_minute_data(str(security_id), exchangeSegment, instrument_type)
TypeError: dhanhq.intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
DataFrame constructor not properly called!
Traceback (most recent call last):
File “/Users/apple/PycharmProjects/PythonProject-Dhan-API/3. Session3 - Codebase1/Dhan codebase/Dhan_Tradehull.py”, line 224, in get_historical_data
df = pd.DataFrame(ohlc[‘data’])
File “/Users/apple/PycharmProjects/PythonProject-Dhan-API/.venv/lib/python3.14/site-packages/pandas/core/frame.py”, line 869, in init
raise ValueError(“DataFrame constructor not properly called!”)
ValueError: DataFrame constructor not properly called!
Traceback (most recent call last):
File “/Users/apple/PycharmProjects/PythonProject-Dhan-API/3. Session3 - Codebase1/Dhan codebase/Dhan_Tradehull.py”, line 258, in get_intraday_data
ohlc = self.Dhan.intraday_minute_data(str(security_id), exchangeSegment, instrument_type)
TypeError: dhanhq.intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
dhanhq.intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
dhanhq.intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’

Traceback (most recent call last):
File “/Users/apple/PycharmProjects/PythonProject-Dhan-API/3. Session3 - Codebase1/Dhan codebase/Dhan_Tradehull.py”, line 258, in get_intraday_data
ohlc = self.Dhan.intraday_minute_data(str(security_id), exchangeSegment, instrument_type)
TypeError: dhanhq.intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’
Traceback (most recent call last):
File “/Users/apple/PycharmProjects/PythonProject-Dhan-API/3. Session3 - Codebase1/Dhan codebase/Dhan_codebase usage.py”, line 39, in
intraday_hist_data[‘rsi’] = talib.RSI(intraday_hist_data[‘close’], timeperiod=14)
~~~~~~~~~~~~~~~~~~^^^^^^^^^
TypeError: ‘NoneType’ object is not subscriptable

Process finished with exit code 1

Thank you sir

Hi @Manish_M ,intraday_minute_data() requires additional parameters mentioned in errors - from_dat and to_date.These two parameters are required for calling a function