Different api timeouts for different api calls

krishna_mfjones
Hi everyone

I see that the default timeout is 7s for all api calls inside connect.py [ correct me if I am wrong]
Is it possible to call the api's with a custom timeout and different one for each?
Eg: while I am fetching quotes I want to keep a timeout of say 3s when I use kite.quote
and while I am placing orders I want to keep a timeout of 10s kite.place_order

So one partial solution I can think of is to make the default value 1s and keep a wait/retry mechanism mechanism for each api with whatever wait time I want before I retry as shown below

##############Sample code##############
tries =3
for attempt in range(tries):
try:
#Call your function [ has a timeout of 1s]
except Exception as e:
print(e)
logging.info(e)
logging.info('Retrying....')
time.sleep(1) # here I can sleep for the stipulated time before I retry [ 3s, 10s ,etc]
continue
else:
break
else:
print('All retries have failed')
print('Program will stop')
print('Please handle manually')
raise SystemExit
#######################################

@sujith Is there any other better way ? Because technically the timeout has already happened and I am just waiting on my end. Is there a way where I can actually wait for a response dynamically?
  • tahseen
    Use timeout context

    https://gist.github.com/TySkby/143190ad1b88c6115597c45f996b030c
Sign In or Register to comment.