i’m also seeing similar issue. the same code was working couple of days back. could some1 provide a solution for this.
Hello @Tradehull_Imran Sir
I have a code that scans stocks whose current price > prev day high, the code is as below, in order to achieve the results can i replace get_historical_data() with get_ltp_data() ??
import pdb
from Dhan_Tradehull_V2 import Tradehull
import pandas as pd
import talib
import time
import datetime
Client details
client_code = “19”
token_id = “iR1w”
Initialize Tradehull
tsl = Tradehull(client_code, token_id)
available_balance = tsl.get_balance()
leveraged_margin = available_balance5
max_trades = 2
per_trade_margin = (leveraged_margin/max_trades)
max_loss = (available_balance1)/100*-1
watchlist = [‘ITC’]
traded_wathclist =
while True:
live_pnl = tsl.get_live_pnl()
current_time = datetime.datetime.now().time()
if current_time < datetime.time(9, 15):
print("wait for market to start", current_time)
continue
if (current_time > datetime.time(14, 30)) or (live_pnl < max_loss):
order_details = tsl.cancel_all_orders()
print("Market is over, Bye Bye see you tomorrow", current_time)
break
for stock_name in watchlist:
time.sleep(1)
print(stock_name)
chart_1 = tsl.get_historical_data(tradingsymbol = stock_name,exchange = 'NSE',timeframe="1")
chart_5min = tsl.get_historical_data(tradingsymbol = stock_name,exchange = 'NSE',timeframe="5") # this call has been updated to get_historical_data call,
chart_15 = tsl.get_historical_data(tradingsymbol = stock_name,exchange = 'NSE',timeframe="15") # this call has been updated to get_historical_data call,
chart_daily = tsl.get_historical_data(tradingsymbol = stock_name,exchange ='NSE', timeframe="DAY")
if (chart_1 is None) or (chart_5min is None) :
continue
if (chart_1.empty) or (chart_5min.empty):
continue
if (chart_15.empty) or (chart_15.empty):
continue
if (chart_15 is None) or (chart_15 is None) :
continue
if (chart_daily.empty) or (chart_daily is None):
continue
# Conditions that are on 5 minute timeframe
chart_5min['ema20'] = talib.EMA(chart_5min['close'], timeperiod=20)
chart_5min['ema50'] = talib.EMA(chart_5min['close'], timeperiod=50)
chart_5min['ema100'] = talib.EMA(chart_5min['close'], timeperiod=100)
chart_5min['ema200'] = talib.EMA(chart_5min['close'], timeperiod=200)
# Get previous and current day's data
prev_day = chart_daily.iloc[-2]
curr_day = chart_daily.iloc[-1]
cc_5 = chart_5min.iloc[-1] #pandas completed candle of 5 min timeframe
ema_condition = (cc_5['ema20'] > cc_5['ema50']) and (cc_5['ema20'] > cc_5['ema100']) and (cc_5['ema20'] > cc_5['ema200'])
high_breakout = curr_day['high'] > prev_day['high']
no_repeat_order = stock_name not in traded_wathclist
max_order_limit = len(traded_wathclist) <= max_trades
if high_breakout and ema_condition and no_repeat_order and max_order_limit:
print(stock_name, "is in uptrend, Buy this script")
Hi @Tradehull_Imran Sir
atm_strike, option_chain = tsl.get_option_chain(Underlying="NIFTY", exchange="INDEX", expiry=0, num_strikes=16)
# Find strikes where call price < 40 and put price > 40
call_price = option_chain[option_chain['CE LTP'] < 40]
call_index = call_price['CE LTP'].idxmax()
call_strike = call_price.loc[call_index]['Strike Price']
As call_strike is not a valid symbol name, kindly guide to place order for required call_strike below Rs 40. Pl give syntax for order placement for call_strike
" गुरु चरण में प्रणाम
"
लंबे समय के अंतराल के बाद आज पुनः गुरुजनों के सान्निध्य में आना और साथियों से मिलना ऐसा अनुभव रहा, मानो सूखे मन को बरसात की पहली फुहार मिल गई हो।
गुरु—जिनकी दृष्टि में केवल ज्ञान ही नहीं, करुणा और दिशा भी होती है। उनका आशीर्वाद और सान्निध्य पाकर आत्मा तक तृप्त हो गई। उनके एक-एक वचन में वही ऊर्जा, वही प्रेरणा आज भी जीवंत है।
और साथियों की बात करें, तो जैसे समय ठहर गया था — मुस्कुराहटें वही, अपनापन वही, और वह बिन कहे समझने वाली भावना आज भी जस की तस।
ये पुनर्मिलन सिर्फ मिलना नहीं है। — यह आत्मा का पुनः जुड़ना है।।
शब्द कम हैं, पर हृदय कृतज्ञता से भरा है।
गुरुदेव को कोटि-कोटि प्रणाम।
साथियों को स्नेह और आभार।
i must appreciate your work no doubt dhan is doing extraordinary services listening to their customer customisation . i think this feature is absolutely great where we can know what mutual fund are buying i hope if this can be available on daily closing basis.
BUT SIR EK REQUEST EK SAAL SE PENDING HAI OVERLAPPING INDICATOR OF MOVING AVERAGE ON SO MANY INDICATOR .
@Tradehull_Imran Hi Imran I had a small query.
I want to download intraday historical data for banknifty futures. I understand that Dhan now allows data for upto 5 years. But how to get the security id for the expired contracts.
Doing it for index is straight forward as the security id doesn’t change.
{
“securityId”: “25”,
“exchangeSegment”: “NSE_FNO”,
“instrument”: “INDEX”,
“interval”: “1”,
“oi”: false,
“fromDate”: “2024-09-11 09:30:00”,
“toDate”: “2024-09-15 13:00:00”
}
Help appreciated.
Right now, API returns only 2 days of candle data when timeframe is less than DAY, while on DAY tf, it returns a year of data,
How to fetch more data while working on lower timeframes.?
I have repeatedly requested this too to Imran sir, Hardik sir and other members, I cannot understand why no one is replying yet. Its a big issue because if you want to apply indicator you cannot apply because to apply indicator you need data . 14period is way too low because all algo for that period will not work now thats too old.
Hi team i also facing this similar kind of error
Disconnected from WebSocket feed.
WebSocket connection error: server rejected WebSocket connection: HTTP 400
Reconnecting Again…
Watchlist changed. Reconnecting the feed…
Can anybody help please - I have tried my best but still not working…
@Tradehull_Imran - PLease please help
Hi, I am getting absurd data from the function tsl.get_historical_data(tradingsymbol=“NIFTY”, exchange=“INDEX”, timeframe=“5”).
Screenshot is attached here. Is there any update in fetching historical data ??
@Siyanka @Hardik @Tradehull_Imran … plz help…!!!
Hi Dhan Tradehull Team,
I Am getting data from Dhan Data API, Tradehull
When I receive data for M&MFIN it is showing LTP is 2191.11 but actual LTP is 262 around
attaching screenshot below ( Screenshot from python & Dhan TV)
Please help me to solve this issue.
@Tradehull_Imran
We do have data upto last 5 years available on 1 min or higher timeframes. @Tradehull_Imran do let me know if there is any help required to add it as part of the library.
you ask any algo trader they must be facing this issue because let say i want to apply crossover of 50 avg crossing 200 mavg if you donot have enough candle on multitple timeframe in 5,15,25,60 how the algo will be created the value of crossover will be shown zero , moreover when i am starting at 9:15, why donot the chart consider previous days data candle inbuilt in the system, it shows as mavg value NAn. this is the place i am helpless and stuck, cannot go ahead unless this issue resolve. i have shown in this example please have a look
please take this matter on urgent basis sir. please see the chart i have highlighted it.
Hardik sir , please do let me know why is it so that what i can see on chart but not while coding or fetching data and i have checked , the root cause is we donot have enough candle backward and therefore the system is unable to calculate it.
Hi @Hardik ,
We are trying to fetch data for ACC
stock but it says we can fetch upto 90 days only at time. Attached the screenshot for your reference:
Do check and let me know.
Hi @Chandrapal_Singh ,
Do update to our latest codebase version 3.0.6:
- Open Command Prompt: Press Win, type cmd, and press Enter.
- Install Dhan-Tradehull: Run
pip install Dhan-Tradehull
- Confirm the installation by running
pip show Dhan-Tradehull
Guide to use the updated codebase:
Refer the below pypi link for more details:
https://pypi.org/project/Dhan-Tradehull/
Video reference :
Hey @Tradehull_Imran
Yes, in a single API call, it is only available for 90 days. You can make parallel API calls to fetch for upto 5 years of data.
chart = tsl.get_historical_data(ce_strike, ‘NFO’, ‘25’) sir is function se pehle data aa raha tha kuch changes aya hai kya sir yeh date dalne bol raha hai
tsl.get_historical_data()
This code stopped functioning for some reason for intraday timeframe (5 min, 15 min) but still working for “DAY” timeframe