I am Very Greatful to Imran Sir!, with your kind teaching and guidance I am able to successfully run option buying algo since two days, when market conditions are really not good for buying, but still able to close few test trades in green with automatic entry/exit, I am still testing it but you this is first success in algo trading so would like to share with all.
Initallly I was not able to run the algo for 6 hours but found the solution for the same.
I am copying example code here so anyone face API rate limit issues, this will help them to manage api rate limit and run algo for whole day till 3:20 PM.
pip install ratelimit
from ratelimit import limits, sleep_and_retry
ONE_MINUTE = 15
LIMIT_DATA_CALLS = 1
LIMIT_LTP_CALL = 3
@sleep_and_retry
@limits(calls=LIMIT_DATA_CALLS, period=ONE_MINUTE)
def limit_fetch_intraday_data(symbol):
# Replace with your API call
return tsl.get_intraday_data(tradingsymbol=symbol, exchange='INDEX', timeframe=2)
@sleep_and_retry
@limits(calls=LIMIT_DATA_CALLS, period=ONE_MINUTE)
def limit_fetch_historical_data(symbol):
# Replace with your API call
return tsl.get_historical_data(tradingsymbol=symbol, exchange='NFO', timeframe='5')
index_chart = limit_fetch_intraday_data('NIFTY')
index_future_chart = limit_fetch_historical_data('NIFTY DEC FUT')
This makes 4*2 = 8 api call per minute