Just to consider an example: 1) can i generate an access token at say 12:15 am on Apr 10 and use it till midnight 11:59 pm of Apr 10? 2) Does the token automatically expire at 12:00 am on Apr 11 3) can i generate multiple valid tokens for the same day? or is only 1 token allowed and the previous one gets cancelled if a new one is created? 4) How many sessions per API key are allowed? Will I get logged out of one if a new session using the same API key is created?
Disclaimer: Not part of zerodha team but a API user since 2016.
They have mentioned in the FAQ's that access tokens are flushed sometime between 5 to 7:30 am everyday. What I have determined from personal experience since the past 8 years is that one wont have any issues with access token validity if it is created at or after 7:30 am.
To specifically answer your queries.
1) can i generate an access token at say 12:15 am on Apr 10 and use it till midnight 11:59 pm of Apr 10?
12:15 am means 15 minutes past noon. Yes if you create the token at 12:15 am it will be valid for the rest of the day. However I suspect you got your time mixed up and mean 00:15 am Which is 15 minutes past midnight. If so, no the token generated at 15 minutes past midnight will be flushed/invalidated in the morning. Edit: Just checked military time vs regular time and 12:15 am regular time means 00:15 am in military time / 24 hr clock. So you meant 15 minutes past midnight. Token will expire in the morning.
2) Does the token automatically expire at 12:00 am on Apr 11
Token expiry time is sometime between 5:00 am to 7:30 am and not 12:00 am ( You mean 00:00 am again I guess).
3) can i generate multiple valid tokens for the same day? or is only 1 token allowed and the previous one gets cancelled if a new one is created?
One access token per app on developers.kite.trade as each will have unique api_key. So If you have multiple apps, you would need to create a new access token for each app that is active. You cannot create multiple tokens for one app.
4) How many sessions per API key are allowed? Will I get logged out of one if a new session using the same API key is created?
The kiteconnect api has two main components the kite api and the ticker / websocket api. * For the websocket you can create 3 sessions per app/Api key. * For the kiteconnect sessions there is no concept of sessions. You could have 20 different scripts running all authenticating using the same access token at the same time with each script doing different actions. It does not matter if you have your code logic in one script or divided over 100 different scripts. You will instead be bound by the api rate limits mentioned here. If you have multiple scripts running you would need a way to maintain track of the number of requests being made and ensure that you do not exceed rate limits. You would also need to write proper exception handing to handle cases if and when you hit the rate limits and get a 'rate limited exceeded' response.
Thanks for such a detailed reply! And, I forgot to mention that all timings in my query are as per 24 hour clock..so for instance by 12:15 am I meant 15 mins past midnight.
The thing is I use APIs from a lot many different brokers and all of them have varying policies pertaining to token expiry and all that. According to your answer, as far as creating the access token for zerodha is concerned, its best to create it after 7:30 am every morning.
3000*3 = 9000 instruments are allowed to be subscribed via websockets per API key. Suppose I want to subscribe to almost 7000-8000 instruments everyday, how much time will it take to subscribe given that I have only 1 hr 45 mins between 7:30 am and the market opening(9:15 am)? I have been using Icicidirect breeze API for sometime and it takes around 5-8 secs to subscribe to 1 instrument. (Now am an amateur coder and know only how to subscribe to instruments one after the other and maybe professional coders know how to subscribe to as many instruments they want to in one go, all in a matter of a few seconds. Say if you wanted to subscribe to 8000 instruments and obtain data right from 9:15 am, how much time would it take you?). So if I want to subscribe to 5000 instruments, 5000*6 secs = 30000 secs or around 8 hours will be the time required as against the maximum available time of 1hr 45 min. (Icicidirect allows getting the access token right after 12:00 am midnight and that allows me to keep all the scrips subscribed and ready by the time the market opens)
Thanks for such a detailed reply! And, I forgot to mention that all timings in my query are as per 24 hour clock..so for instance by 12:15 am I meant 15 mins past midnight.
Some people refer to midnight as 12 as the clock shows 12. But in terms of computer time / military time, midnight is 00:00. The day starts at 00:00:01 (HH:MM:SS) and ends at 23:59:59 (HH:MM:SS). Since we are talking computers/API/Programming here it would be prudent to use/refer to the correct notation. Don't want to be a PITA about it but using the correct notation always will help avoid errors in translating human time to machine time/military time I almost gave you a wrong answer before I doublechecked, went back and read what you meant against what I understood.
3000*3 = 9000 instruments are allowed to be subscribed via websockets per API key. Suppose I want to subscribe to almost 7000-8000 instruments everyday, how much time will it take to subscribe given that I have only 1 hr 45 mins between 7:30 am and the market opening(9:15 am)?
ws.subscribe( subscriptionlist ) ws.set_mode( ws.MODE_FULL , subscriptionlist ) # set mode for all subscribed instruments
This is about 500 instruments. Checked the logs and it takes about 18 milliseconds for the subscribe call to complete. Another .5 millseconds or 500 microseconds for set_mode call. For 3000 instruments it should take the same time or at worst a second or two. So 1 hour 45 minutes is a long long time.
I have been using Icicidirect breeze API for sometime and it takes around 5-8 secs to subscribe to 1 instrument. (Now am an amateur coder and know only how to subscribe to instruments one after the other and maybe professional coders know how to subscribe to as many instruments they want to in one go, all in a matter of a few seconds. Say if you wanted to subscribe to 8000 instruments and obtain data right from 9:15 am, how much time would it take you?). So if I want to subscribe to 5000 instruments, 5000*6 secs = 30000 secs or around 8 hours will be the time required as against the maximum available time of 1hr 45 min. (Icicidirect allows getting the access token right after 12:00 am midnight and that allows me to keep all the scrips subscribed and ready by the time the market opens)
5-8 seconds is way too long for an api response. You have to check if it's an issue with your code or is their endpoint really taking that long. Also found this very surprising so I couldn't help looking up the ICICI breeze api docs and I found this line script_code = "4.1!1594" #Subscribe more than one stock at a time This indicates that it should allow you to subscribe to more than one instrument at a time. You will have to contact their support to ask about how you can achieve it as it uses a pretty weird notation for the instruments. I suspect it should be a comma separated string. Something like "4.1!1594 , 4.1!1595 , 4.1!1596 , ... , ...". Check with their support and then whether you subscribe to one instrument at a time or a hundred, it should still take the same time - about 5-8 seconds. Computers are fast to an extent that is really incomprehensible to humans. Billions of operations per second. And even in terms of network terms, you could send a request to a server half way across the world and get a response in anything between 2 to10 milliseconds. A distance that would take a human half a day to travel using the fastest mode of transport available. So 5-8 seconds is an eternity - somethings definitely wrong somewhere.
Zerodha Websocket api allows one to provide a list for subscription using the following syntax
thanks a ton for this syntax to subscribe to multiple instruments
This is about 500 instruments. Checked the logs and it takes about 18 milliseconds for the subscribe call to complete. Another .5 millseconds or 500 microseconds for set_mode call. For 3000 instruments it should take the same time or at worst a second or two. So 1 hour 45 minutes is a long long time.
This was exactly what i wanted to know. Currently its taking hours to subscribe to a few thousand feeds and thats just so preposterous.
I couldn't help looking up the ICICI breeze api docs and I found this line script_code = "4.1!1594" #Subscribe more than one stock at a time This indicates that it should allow you to subscribe to more than one instrument at a time. Check with their support and then whether you subscribe to one instrument at a time or a hundred, it should still take the same time - about 5-8 seconds.
Will get in touch with their support team and get it sorted out. Will also post an update here once its all done with. Thanks again.
They have mentioned in the FAQ's that access tokens are flushed sometime between 5 to 7:30 am everyday.
What I have determined from personal experience since the past 8 years is that one wont have any issues with access token validity if it is created at or after 7:30 am.
To specifically answer your queries. 12:15 am means 15 minutes past noon. Yes if you create the token at 12:15 am it will be valid for the rest of the day. However I suspect you got your time mixed up and mean 00:15 am Which is 15 minutes past midnight. If so, no the token generated at 15 minutes past midnight will be flushed/invalidated in the morning.
Edit: Just checked military time vs regular time and 12:15 am regular time means 00:15 am in military time / 24 hr clock. So you meant 15 minutes past midnight. Token will expire in the morning. Token expiry time is sometime between 5:00 am to 7:30 am and not 12:00 am ( You mean 00:00 am again I guess). One access token per app on developers.kite.trade as each will have unique api_key. So If you have multiple apps, you would need to create a new access token for each app that is active. You cannot create multiple tokens for one app. The kiteconnect api has two main components the kite api and the ticker / websocket api.
* For the websocket you can create 3 sessions per app/Api key.
* For the kiteconnect sessions there is no concept of sessions. You could have 20 different scripts running all authenticating using the same access token at the same time with each script doing different actions. It does not matter if you have your code logic in one script or divided over 100 different scripts. You will instead be bound by the api rate limits mentioned here. If you have multiple scripts running you would need a way to maintain track of the number of requests being made and ensure that you do not exceed rate limits. You would also need to write proper exception handing to handle cases if and when you hit the rate limits and get a 'rate limited exceeded' response.
The thing is I use APIs from a lot many different brokers and all of them have varying policies pertaining to token expiry and all that. According to your answer, as far as creating the access token for zerodha is concerned, its best to create it after 7:30 am every morning.
3000*3 = 9000 instruments are allowed to be subscribed via websockets per API key. Suppose I want to subscribe to almost 7000-8000 instruments everyday, how much time will it take to subscribe given that I have only 1 hr 45 mins between 7:30 am and the market opening(9:15 am)?
I have been using Icicidirect breeze API for sometime and it takes around 5-8 secs to subscribe to 1 instrument. (Now am an amateur coder and know only how to subscribe to instruments one after the other and maybe professional coders know how to subscribe to as many instruments they want to in one go, all in a matter of a few seconds. Say if you wanted to subscribe to 8000 instruments and obtain data right from 9:15 am, how much time would it take you?).
So if I want to subscribe to 5000 instruments, 5000*6 secs = 30000 secs or around 8 hours will be the time required as against the maximum available time of 1hr 45 min.
(Icicidirect allows getting the access token right after 12:00 am midnight and that allows me to keep all the scrips subscribed and ready by the time the market opens)
subscriptionlist = [ 10046978 , 10047234 , 10046210 , 10046466 , 10048514 , 10048770 , 10043394 , 10045186 , 10049026 , 10049282 , 10019074 , 10019330 , 10049538 , 10049794 , 10007298 , 10007554
, 10052098 , 10052354 , 10006786 , 10007042 , 10053122 , 10053890 , 10006274 , 10006530 , 10054146 , 10054402 , 10005762 , 10006018 , 10054658 , 10054914 , 10055682 , 11641602 , 11642626 , 11641090 , 11641346 , 11637250 , 11639810 , 11635714 , 11635970 , 11633666 , 11633922 , 11633154 , 11633410 , 10860802 , 10861058 , 10860290 ,
...
...
9773058 , 9772290 , 9772546 , 9770754 , 9771010 , 9350402 , 9350658 , 9349634 , 9349890 , 9349122 , 9349378 , 9348610 , 9348866 , 9347842 , 9348098 , 9304322 , 9304834 ]
ws.subscribe( subscriptionlist )
ws.set_mode( ws.MODE_FULL , subscriptionlist ) # set mode for all subscribed instruments
This is about 500 instruments. Checked the logs and it takes about 18 milliseconds for the subscribe call to complete. Another .5 millseconds or 500 microseconds for set_mode call. For 3000 instruments it should take the same time or at worst a second or two.
So 1 hour 45 minutes is a long long time. 5-8 seconds is way too long for an api response. You have to check if it's an issue with your code or is their endpoint really taking that long. Also found this very surprising so I couldn't help looking up the ICICI breeze api docs and I found this line
script_code = "4.1!1594" #Subscribe more than one stock at a time
This indicates that it should allow you to subscribe to more than one instrument at a time. You will have to contact their support to ask about how you can achieve it as it uses a pretty weird notation for the instruments. I suspect it should be a comma separated string. Something like "4.1!1594 , 4.1!1595 , 4.1!1596 , ... , ...". Check with their support and then whether you subscribe to one instrument at a time or a hundred, it should still take the same time - about 5-8 seconds.Computers are fast to an extent that is really incomprehensible to humans. Billions of operations per second. And even in terms of network terms, you could send a request to a server half way across the world and get a response in anything between 2 to10 milliseconds. A distance that would take a human half a day to travel using the fastest mode of transport available. So 5-8 seconds is an eternity - somethings definitely wrong somewhere.
thanks a ton for this syntax to subscribe to multiple instruments
This is about 500 instruments. Checked the logs and it takes about 18 milliseconds for the subscribe call to complete. Another .5 millseconds or 500 microseconds for set_mode call. For 3000 instruments it should take the same time or at worst a second or two.
So 1 hour 45 minutes is a long long time.
This was exactly what i wanted to know. Currently its taking hours to subscribe to a few thousand feeds and thats just so preposterous.
I couldn't help looking up the ICICI breeze api docs and I found this line
script_code = "4.1!1594" #Subscribe more than one stock at a time This indicates that it should allow you to subscribe to more than one instrument at a time. Check with their support and then whether you subscribe to one instrument at a time or a hundred, it should still take the same time - about 5-8 seconds.
Will get in touch with their support team and get it sorted out. Will also post an update here once its all done with.
Thanks again.