Yes the calculations are correct, you can us sleep of 2.25 seconds.
Also there are other methods to optimize for rate limits.
Like you can request for ltp in bulk,
also we need to have adjust code so that we don’t call data when it is not needed.
example : when the entry is completed we don’t need to call for historical data
import pandas_ta as ta
index_chart = tsl.get_historical_data(tradingsymbol='NIFTY NOV FUT', exchange='NFO', timeframe="15")
indi = ta.supertrend(index_chart['high'], index_chart['low'], index_chart['close'], 7, 3)
index_chart = pd.concat([index_chart, indi], axis=1, join='inner')
print(index_chart)
cc = index_chart.iloc[2] # completed_candle
cc_supertrend_color = completed_candle['SUPERTd_7_3.0']
# example entry
if cc_supertrend_color == 1:
print("buy")
if cc_supertrend_color == -1:
print("buy")
# 'Column1 SUPERT_7_3.0 = this will give full supertrend line values' trend
# 'Column2 SUPERTd_7_3.0 = this will show if supertrend is red or green' direction
# 'Column3 SUPERTl_7_3.0 = show values only for green None for red' long
# 'Column4 SUPERTs_7_3.0 = show values only for red None for green' short
get_intraday_data gives data from today 9:15 till current time
get_historical_data gives data from from 3rd last working day till current time
So basically get_intraday_data gives us too less of data when compared to get_historical_data,
In next codebase release we will deprecate get_intraday_data.
To get ema calculations at 9:15 also we need previous data as well, so simple use get_historical_data it gives data from 3rd last working day till current time
Following error shows means todays data API limit is over???
#How can we get to know which time of limit is breached
In error message shows
throttling API calls.'}, ‘data’: {‘errorType’: 'Rate_Limit
Means data api
but which time rate limit How to know
Then we can try after that time
C:\Algo Practice\Api Upgrade>py Demo.py
Codebase Version 2.1
-----Logged into Dhan-----
reading existing file all_instrument 2024-11-20.csv
Got the instrument file
available_balance 115348.39
Exception in Getting OHLC data as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: ‘DH-904’, ‘error_type’: ‘Rate_Limit’, ‘error_message’: ‘Too many requests on server from single user breaching rate limits. Try throttling API calls.’}, ‘data’: {‘errorType’: ‘Rate_Limit’, ‘errorCode’: ‘DH-904’, ‘errorMessage’: ‘Too many requests on server from single user breaching rate limits. Try throttling API calls.’}}
Exception in Getting OHLC data as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: ‘DH-904’, ‘error_type’: ‘Rate_Limit’, ‘error_message’: ‘Too many requests on server from single user breaching rate limits. Try throttling API calls.’}, ‘data’: {‘errorType’: ‘Rate_Limit’, ‘errorCode’: ‘DH-904’, ‘errorMessage’: ‘Too many requests on server from single user breaching rate limits. Try throttling API calls.’}}
Traceback (most recent call last):
File “Demo.py”, line 49, in
chart_15[‘ema’] = talib.EMA(chart_15[‘close’], timeperiod=5)
TypeError: ‘NoneType’ object is not subscriptable
for splitting positions you may modify the SL order to half of the quantity.
on how to take candle low as SL and trailing stop loss using Supertrend, this exact case will be covered in upcoming video.
How can we get to know which time of limit is breached
This we cannot know for sure, as of now dhanhq has no direct method for it.
Try your code again after 1 hour, if rate limits are not reset even then, then todays data API limit is over.