for every historical data token, there is a delay of nearly 2 seconds instead of 3 token's data/sec?

amandeep179018
def get_login(api_k,api_s):
global kws,kite;
kite = KiteConnect(api_key=api_k)
print("[*] Generate access Token : ",kite.login_url())
request_tkn = input("[*] Enter Your Request Token Here : ");
data = kite.generate_session(request_tkn, api_secret=api_s)
kite.set_access_token(data["access_token"])
kws = KiteTicker(api_k, data["access_token"])


get_login(api_k,api_s);



sec = int(round(time.time()))
ab=(sec/300)

J=0
K= 0
arr_1d = []
arr_positive = []
arr_negative = []


one_time={'first':''}



global trd_portfolio






def on_ticks(ws, ticks):
arr_1d = []
arr_positive = []
arr_negative = []
while True:
abc = datetime.datetime.now()

if int(abc.strftime("%H"))>=9 :
if ("time" not in one_time.values())==True:
one_time['first']="time"
#time.sleep(10)
print("yo")


#time.sleep(10)
global trd_portfolio

trd_portfolio={

'ADANIENT':{'token':6401,'name':'ADANIENT','status':'','order_buy':'','order_sell':''},

'ADANIPORTS':{'token':3861249,'name':'ADANIPORTS','status':'','order_buy':'','order_sell':''},

'AMBUJACEM':{'token':325121,'name':'AMBUJACEM','status':'','order_buy':'','order_sell':''},

'ASIANPAINT':{'token':60417,'name':'ASIANPAINT','status':'','order_buy':'','order_sell':''},

'AXISBANK':{'token':1510401,'name':'AXISBANK','status':'','order_buy':'','order_sell':''},

'BANKBARODA':{'token':1195009,'name':'BANKBARODA','status':'','order_buy':'','order_sell':''},

'BHARTIARTL':{'token':2714625,'name':'BHARTIARTL','status':'','order_buy':'','order_sell':''},

'BPCL':{'token':134657,'name':'BPCL','status':'','order_buy':'','order_sell':''},

'CADILAHC':{'token':2029825,'name':'CADILAHC','status':'','order_buy':'','order_sell':''},

'CANBK':{'token':2763265,'name':'CANBK','status':'','order_buy':'','order_sell':''},

'CHOLAFIN':{'token':175361,'name':'CHOLAFIN','status':'','order_buy':'','order_sell':''},

'CIPLA':{'token':177665,'name':'CIPLA','status':'','order_buy':'','order_sell':''},

'COALINDIA':{'token':5215745,'name':'COALINDIA','status':'','order_buy':'','order_sell':''},

'DLF':{'token':3771393,'name':'DLF','status':'','order_buy':'','order_sell':''},

'EXIDEIND':{'token':173057,'name':'EXIDEIND','status':'','order_buy':'','order_sell':''},

'GAIL':{'token':1207553,'name':'GAIL','status':'','order_buy':'','order_sell':''},

'GRASIM':{'token':315393,'name':'GRASIM','status':'','order_buy':'','order_sell':''},

'HCLTECH':{'token':1850625,'name':'HCLTECH','status':'','order_buy':'','order_sell':''},

'HDFC':{'token':340481,'name':'HDFC','status':'','order_buy':'','order_sell':''},

'HDFCBANK':{'token':341249,'name':'HDFCBANK','status':'','order_buy':'','order_sell':''},

'HINDALCO':{'token':128112644,'name':'HINDALCO','status':'','order_buy':'','order_sell':''},

'HINDPETRO':{'token':359937,'name':'HINDPETRO','status':'','order_buy':'','order_sell':''},

'IBULHSGFIN':{'token':7712001,'name':'IBULHSGFIN','status':'','order_buy':'','order_sell':''},

'INDUSINDBK':{'token':1346049,'name':'INDUSINDBK','status':'','order_buy':'','order_sell':''},

'INFRATEL':{'token':7458561,'name':'INFRATEL','status':'','order_buy':'','order_sell':''},

'INFY':{'token':408065,'name':'INFY','status':'','order_buy':'','order_sell':''},

'IOC':{'token':415745,'name':'IOC','status':'','order_buy':'','order_sell':''},

'ITC':{'token':424961,'name':'ITC','status':'','order_buy':'','order_sell':''},

'JSWSTEEL':{'token':3001089,'name':'JSWSTEEL','status':'','order_buy':'','order_sell':''},

'LT':{'token':2939649,'name':'LT','status':'','order_buy':'','order_sell':''},

'M&M':{'token':519937,'name':'M&M','status':'','order_buy':'','order_sell':''},

'MANAPPURAM':{'token':4879617,'name':'MANAPPURAM','status':'','order_buy':'','order_sell':''},

'NTPC':{'token':2977281,'name':'NTPC','status':'','order_buy':'','order_sell':''},

'ONGC':{'token':633601,'name':'ONGC','status':'','order_buy':'','order_sell':''},

'PNB':{'token':2730497,'name':'PNB','status':'','order_buy':'','order_sell':''},

'POWERGRID':{'token':3834113,'name':'POWERGRID','status':'','order_buy':'','order_sell':''},

'RELIANCE':{'token':738561,'name':'RELIANCE','status':'','order_buy':'','order_sell':''},

'SBIN':{'token':779521,'name':'SBIN','status':'','order_buy':'','order_sell':''},

'SRTRANSFIN':{'token':1102337,'name':'SRTRANSFIN','status':'','order_buy':'','order_sell':''},

'SUNPHARMA':{'token':857857,'name':'SUNPHARMA','status':'','order_buy':'','order_sell':''},

'TATAMOTORS':{'token':884737,'name':'TATAMOTORS','status':'','order_buy':'','order_sell':''},

'TECHM':{'token':3465729,'name':'TECHM','status':'','order_buy':'','order_sell':''},

'TITAN':{'token':897537,'name':'TITAN','status':'','order_buy':'','order_sell':''},

'TVSMOTOR':{'token':2170625,'name':'TVSMOTOR','status':'','order_buy':'','order_sell':''},

'UPL':{'token':2889473,'name':'UPL','status':'','order_buy':'','order_sell':''},

'VEDL':{'token':784129,'name':'VEDL','status':'','order_buy':'','order_sell':''},

'WIPRO':{'token':969473,'name':'WIPRO','status':'','order_buy':'','order_sell':''},

'ZEEL':{'token':975873,'name':'ZEEL','status':'','order_buy':'','order_sell':''}

}
# for company_data in ticks:

for name in trd_portfolio.copy():

token = int(trd_portfolio[name]['token'])
name = str(trd_portfolio[name]['name'])

print("NAME OF THE STOCK__________________",name)
from_date1='2020-04-16'
to_date1='2020-05-16'
interval1="day"
records_pivot = kite.historical_data(token, from_date1, to_date1, interval1)
df1 = pd.DataFrame(records_pivot)
date1=pd.to_datetime(df1['date'])

from_date2='2020-04-16'
to_date2='2020-05-16'
interval2="5minute"
records = kite.historical_data(token, from_date2, to_date2, interval2)
df = pd.DataFrame(records)
date2=pd.to_datetime(df['date'])

## CALCLUATIONS OF STRATERGY ####################

def on_connect(ws, response):
ws.subscribe([6401,3861249,325121,60417,1510401,1195009,2714625,134657,
2029825,2763265,175361,177665,5215745,3771393,173057,1207553,315393,
1850625,340481,341249,128112644,359937,7712001,1346049,7458561,408065,
415745,424961,3001089,2939649,519937,4879617,2977281,633601,2730497,
3834113,738561,779521,1102337,857857,884737,3465729,897537,2170625,
2889473,784129,969473,975873])


ws.set_mode(ws.MODE_FULL,[6401,3861249,325121,60417,1510401,1195009,2714625,134657,
2029825,2763265,175361,177665,5215745,3771393,173057,1207553,315393,
1850625,340481,341249,128112644,359937,7712001,1346049,7458561,408065,
415745,424961,3001089,2939649,519937,4879617,2977281,633601,2730497,
3834113,738561,779521,1102337,857857,884737,3465729,897537,2170625,
2889473,784129,969473,975873])



kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.connect()


I have to rely a lot on historical data for this strategy so if my data connection disables for even 15 min due to any issue then all of my calculations will be affected so I need historical data for every stock but for some reason, there is a delay in getting data. The data I get for every
token has a delay of nearly 2 seconds but the historical data's limit is 3 requests per second so what is causing this delay?
  • rakeshr
    @amandeep179018
    The data I get for every token has a delay of nearly 2 seconds
    Historical data API is not designed to be continuously polled for live usage. You can go through this thread.
  • amandeep179018
    I know that, but what about the claim that Zerodha give of 3 requests per second?
    does this mean that I just have to be okay with a dealy which is nearly six times greater??
    also, I have read a few queries where the latency was reduced to 300 milliseconds. How can I do the same???

    please give some other solution or reason for the delay based on the code that I have provided. I have already suffered enough loss due to wasted days of subscription.
  • sujith
    @amandeep179018,
    Kite Connect is purely an execution platform. We don't provide support or solution for writing or enhancing the strategies. It is outside the scope of this forum.
Sign In or Register to comment.