Learn Algo Trading with Python | Codes | Youtube Series

Hi @Zee2Zahid @rahulcse56

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

Hi @Kalpeshh_Patel
use this code

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


Hi @Subhajitpanja

:+1: for the detailed solution

Hi @Jyothi_Chilukoti

The error is in authentication,
Do check below link

1 Like

Hi @Deodas_kumar

  1. we don’t need to solve for get_intraday_data

    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.

  2. 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

Hi

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

Hi @SUDIP_NATH
use this file

Hi @Tradehull_Imran ,

after using new file
My problem of multiple errors has been resolved, Thanks for your help and response.

2 Likes

Hi @Himansshu_Joshi
The logic you are trying to implement is correct, Although we do need to simplify the code

Check the pseudocode for the same



import 


while True:

	if entry_condition1 and  entry_condition2 and entry_condition3:
		stoploss_level    = "your calculation"
		target_level      = "your calculation"
		buy_entry_orderid = tsl.order_placement(stock_name,'NSE', 1, 0, 0, 'MARKET', 'BUY', 'MIS')
		sl_orderid        = tsl.order_placement(stock_name,'NSE', 1, 0, stoploss_level, 'STOPMARKET', 'SELL', 'MIS')


	if script_traded == "yes":
		sl_hit = tsl.get_order_status(orderid=sl_orderid) == "COMPLETED"
		tg_hit = ltp > target_level

		if sl_hit:
			print("exit trade")


		if tg_hit:
			tsl.modify_order(orderid=buy_entry_orderid,sl_price=None,price_type="MARKET")
			print("exit trade")
			



1 Like

Hi @Kuldeep_Khaladkar

  1. For Fundamental data Check https://www.alphavantage.co/
  2. For 52 weeks high low use below pseudocode



import datetime

data = tsl.get_historical_data(tradingsymbol='NIFTY', exchange='INDEX', timeframe="DAY")

current_date = datetime.now()
start_date = current_date - datetime.timedelta(weeks=52)

data_52_weeks = data[data['timestamp'] >= start_date]

high_52_week = data_52_weeks['high'].max()
low_52_week = data_52_weeks['low'].min()

1 Like

Hi @Kishore007

  1. Use
    percentage_change = ((current_close - previous_close) / previous_close) * 100
    0.3 <= percentage_change <= 0.4
  1. use
    data['previous_close'] = data['close'].shift(1)
    data['previous_previous_close'] = data['close'].shift(2)
1 Like

Hi @Kalpeshh_Patel

  1. Use below code to get executed price/trade price
    order_price   = tsl.get_executed_price(orderid="order_id")
  1. 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.

Hi @Naga_Rajesh_K

  1. Yes there is some issue in getting data for BFO, I will need to check on this one.

  2. On market holidays, we will not get ltp data… but historical data api will still work
    example below calls will work after after market over also

     tsl.get_historical_data(tradingsymbol='SENSEX', exchange='INDEX', timeframe="DAY")
     tsl.get_historical_data(tradingsymbol='NIFTY 21 NOV 23500 CALL', exchange='NFO', timeframe="5")

Hi @thakurmhn

Historical data issue has been completely solved now since the last update.

  1. Do use the latest codebase file, the last update was 2 day ago.
    use : Learn Algo Trading with Python | Codes | Youtube Series - #827 by Tradehull_Imran

  2. Also make sure that below points are okey
    Learn Algo Trading with Python | Codes | Youtube Series - #706 by Tradehull_Imran

  3. Also do take care that rate limits are not breached
    see : Learn Algo Trading with Python | Codes | Youtube Series - #860 by Tradehull_Imran

Hi @Kalpeshh_Patel

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.

Thank you, sir…

I will check and run the code, thank you once again sir…

Hi
@Tradehull_Imran

Thanks a lot for great backup support

One more querry
Is that considerable
ltp = continuous candles close
means where we get to trade above the -2candle high

buy = cc_2[‘high’] < cc_1[‘close’]

Thank you @Tradehull_Imran sir🙏

THANKS I WILL TRY AGAIN @Tradehull_Imran SIR

Hi Imran sir,

Getting below error while running the code.