Learn Algo Trading with Python | Codes | Youtube Series

tsl = Tradehull(client_code,token_id) # tradehull_support_library

tsl.get_intraday_data(‘ACC’,‘NSE’,1)

tsl.get_intraday_data(‘NIFTY’,‘NSE’,1)

available_balance = tsl.get_balance()

max_risk_for_the_day = (available_balance1)/100-1

print(“available_balance”, available_balance)

ltp1 = tsl.get_ltp(‘ACC’)

ltp2 = tsl.get_ltp(‘NIFTY’)

ltp3 = tsl.get_ltp(‘BANKNIFTY 28 AUG 51600 CALL’)

ltp4 = tsl.get_ltp(‘NIFTY 29 AUG 23200 CALL’)

previous_hist_data = tsl.get_historical_data(‘ACC’,‘NSE’,12)

intraday_hist_data = tsl.get_intraday_data(‘ACC’,‘NSE’,1)

Nifty_previous_hist_data = tsl.get_historical_data(‘NIFTY’,‘NSE_IDX’,12)

Nifty_intraday_hist_data = tsl.get_intraday_data(‘ANIFTYCC’,‘NSE_IDX’,1)

print(“Nifty_intraday_hist_data”, Nifty_intraday_hist_data)

print(“Nifty_previous_hist_data”, Nifty_previous_hist_data)
‘NSE_IDX’
Traceback (most recent call last):
File “c:\Users\Udham Singh\Documents\Dhan\Dhan_Tradehull.py”, line 216, in get_historical_data
exchangeSegment = script_exchange[exchange]
KeyError: ‘NSE_IDX’
‘NSE_IDX’
Traceback (most recent call last):
File “c:\Users\Udham Singh\Documents\Dhan\Dhan_Tradehull.py”, line 250, in get_intraday_data
exchangeSegment = script_exchange[exchange]
KeyError: ‘NSE_IDX’
Nifty_intraday_hist_data None
Nifty_previous_hist_data None
PS C:\Users\Udham Singh\Documents\Dhan>

I have code like this

from Dhan_Tradehull import Tradehull
import talib
from dhanhq import dhanhq
import mibian
import datetime
import pandas as pd
import traceback
import xlwings as xw
import requests
import pdb
import os
import time
import json
from pprint import pprint
import logging
import warnings
from typing import Tuple, Dict

client_code = “abc”
token_id = “xyz”
tsl = Tradehull(client_code,token_id)

watchlist = [‘TATACONSUM’, ‘ICICIBANK’, ‘POWERGRID’, ‘ONGC’, ‘APOLLOHOSP’, ‘DRREDDY’, ‘HEROMOTOCO’, ‘TRENT’, ‘TITAN’, ‘AXISBANK’, ‘MARUTI’, ‘WIPRO’, ‘INFY’, ‘BAJFINANCE’, ‘M&M’, ‘TATAMOTORS’, ‘BRITANNIA’, ‘ASIANPAINT’, ‘KOTAKBANK’, ‘TECHM’, ‘BPCL’, ‘HDFCBANK’, ‘INDUSINDBK’, ‘ADANIENT’, ‘BAJAJFINSV’, ‘SBIN’, ‘SHRIRAMFIN’, ‘BAJAJ-AUTO’, ‘EICHERMOT’, ‘RELIANCE’, ‘ITC’, ‘GRASIM’, ‘NESTLEIND’, ‘HDFCLIFE’, ‘LT’, ‘BHARTIARTL’, ‘JSWSTEEL’, ‘CIPLA’, ‘ADANIPORTS’, ‘COALINDIA’, ‘TATASTEEL’, ‘HCLTECH’, ‘BEL’, ‘SUNPHARMA’, ‘HINDUNILVR’, ‘TCS’, ‘NTPC’, ‘SBILIFE’, ‘HINDALCO’, ‘ULTRACEMCO’]

for stock_name in watchlist:
chart = tsl.get_intraday_data(stock_name, ‘NSE’, 1)
chart[‘rsi’] = talib.RSI(chart[‘close’], timeperiod=14)
print(stock_name)
pdb.set_trace()

i am getting below error. not sure what exactly is wrong

i have resolved it by installing below packages

pip install pandas ta-lib matplotlib

2 Likes

Not yet. I’ve already requested it—sir might be updating it. Hopefully, it’ll be available soon.

Hi @Shafeeque_Muhammed
check below steps to solve SSL issuse

Hi @somnath_naskar

we need to update the token and client_id in below files

Dhan_codebase usage > add token_id and client_id

Dhan_websocket > add access_token and token_id

in the both files you need to replace by your api token

1 Like

Hi @Hitesh_Maurya

Check below steps ,

Also let me know if it works…
If the issue persists send me complete error screenshot (the screenshot provided as of now is half error)

Hi @Md_Naquibuddin

It can be that simply the data is not returned by the api.
doc check this link for solution

Hi @Happy_Life

In historical data use NSE, instead of NSE_IDX

Nifty_previous_hist_data = tsl.get_historical_data(‘NIFTY’,‘NSE_IDX’,12) # wrong
Nifty_previous_hist_data = tsl.get_historical_data(‘NIFTY’,‘NSE’,12)        # right

1 Like

:+1:

TyepError: ‘NoneType’ object is not subscriptable

@Tradehull_Imran Sir data is not correct Inside Candle not formed but according to code its is formed in Adani Ent. for refernce pls look at the attached screensots. What could be the error as I’ve cross checked the code from end but unable to recfity.

Thanks In Advance for your guidance.

P1

@Tradehull_Imran p2

@Tradehull_Imran p3

Again started this error

Traceback (most recent call last):
File “Dhan_codebase usage.py”, line 31, in
chart[‘rsi’] = talib.RSI(chart[‘close’], timeperiod=14)
TypeError: ‘NoneType’ object is not subscriptable

thanks for your quick reply
in historical it prints blank array and for intraday cmp is 24580 but it prints something else. Kindly try to guide me
tsl = Tradehull(client_code,token_id) # tradehull_support_library

Nifty_intraday_hist_data = tsl.get_intraday_data(‘NIFTY’,‘NSE’,1)
Nifty_previous_hist_data = tsl.get_historical_data(‘NIFTY’,‘NSE’,12)

print(“Nifty_intraday_hist_data”, Nifty_intraday_hist_data)
print(“\n\nNifty_previous_hist_data”, Nifty_previous_hist_data)

// Output of code
-----Logged into Dhan-----
reading existing file all_instrument 2024-10-23.csv
Got the instrument file
Nifty_intraday_hist_data open high low close volume start_Time
0 7995.85 8009.4 7991.25 8009.4 621.0 2024-10-23 12:46:00

Nifty_previous_hist_data Empty DataFrame
Columns:
Index:

Hi Imran @Tradehull_Imran
“‘NonType’ object is not subscriptable” error. Pls suggest solution

Hi @CBrid

For issues related to chart variable, or error: AttributeError: ‘NoneType’ object has no attribute ‘iloc’

Explanation of error:
This means in line no 15, the value of the chart was not received from the api
and now when on line no 16 we try to make rsi on it… it gives us error that on None type data … it cannot subscribe to close column

Solution:

you need to check if the data is correctly received,
chart dataframe should Not be None
if this is not the case so continue and restart the loop, from the last stock

code to be added



while True:
	for stock_name in watchlist:
		print(stock_name)

		chart = tsl.get_intraday_data(stock_name, 'NSE', 1)

		if chart is None:
			continue

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

		bc   = chart.iloc[-2] #pandas  breakout candle
		ic   = chart.iloc[-3] #pandas  inside candle
		ba_c = chart.iloc[-4] #pandas  base candle


Try it and… also let me know if any confusion

1 Like

Hi @Manish_Goel
I have gone through the code and cmd output.

ba_c['high'] > ic['high'] → 2874.4 > 2875.35 → False
ba_c['low'] < ic['low'] → 2871.65 < 2871.65 → False

Since both conditions are False, the overall condition for inside_candle_formed is False.

Also I think the signal was not generated at all. else it would have written
Adaniports is in uptrend in cmd (not just Adaniports)

Let me know… if this solves the issue

Hi @Khandu_Kshirsagar

Do check this link for solution