API rate limiting

Vivek
Vivek edited October 2016 in General
We've noticed a growing abuse of the APIs (by our own paying Kite Connect users) over the last few weeks. This pertains primarily to pulling market quotes (/instruments) and historical data. Some users have incessantly sent up to 30,000 requests in 10 minutes polling the same market quote API, with no regard for fair use best practices. As a result, we've imposed strict rate limiting procedures.

/instruments (market quote call) - max 60 requests per minute
/instruments/historical - max 120 requests per minute (2 requests/sec)

If you exceed the limit, you'll get a 429 (Too many requests) error temporarily until the threshold is cleared. Your account, for now, is not affected.

The correct way to retrieve a live quote is to use the WebSocket API (there are Python and Java clients available) which offers live streaming ticks, and not poll the /instruments API which is only meant for passive, one-off calls.

Thanks for your cooperation.
  • pankajiit_cse
    I am getting 429 consistently......any fix for the same
  • pankajiit_cse
    after how much time the account is cleared of the limits??
  • pankajiit_cse
    please provide minute wise request to historic data api for my account because I am getting this error consistently
  • Kailash
    @pankajiit_cse If you are consistently getting this error, that means you are sending more than 60 requests per minute. The historical API is not meant to be polled every second. How many requests are you sending?

    PS: For live data, you should use the WebSocket API.
  • muke5hy
    @Kailash @vivek
    1. Is the rate limit is Per API basis or per instrument Basis for historical data.
    2. My Algoritham requires to read all data points for each instrument. Hence I am trying to call API every .5 sec interval. For different instruments. Am I doing it correct?
    3. What would be the ideal way to download last 2 years of data for all instruments ?

  • Kailash
    1) @muke5hy It's per API.
    2) For live data points (you can compute candles from ticks), you should use the WebSocket API.
    3) We have close to a billion rows in the historical data store, so there's no easy way as of now. We're contemplating how to make to make the availability better.
  • anupshinde
    @Kailash @vivek My 2 cents..
    This is a good step. However, please improve your web-sockets documentation and please make it include links to the python ws client and/or some sample code.
    From my experience, it is quite geeky for an average developer to fetch and decrypt that binary dataframe correctly.
  • cosmik
    cosmik edited July 2016
    @vivek You have a bug which might be making this worse. It seems anyone can call https://api.kite.trade/instruments with just the api_key, without having the api_secret. api_key is public so they can be obtained easily.

    I tested it just now and it works. It's possible that API abusers are using others' api_key. With rate-limiting in place, now genuine users will get penalized for no fault of theirs (for eg, some genuine user who was calling this API only 100 times a minute, but his API key was being abused by others 10000 times a minute).

    Fix would be to make api_secret mandatory for the instruments API.

    PS: Do you have a bug-bounty program? :)
  • Vivek
    @cosmik currently we are rate limiting based on IP rather than api_key so even if people abuse your api key your app won't be rate limited.

    We don't have bounty program yet but we welcome feedbacks and bug reports :smile:
  • Kailash
    @cosmik I'd like to correct @vivek by adding that we have both api_key and IP address based rate limiting.

    Also /instruments is in a different limit zone. It should not affect standard API calls.

    Finally, yes, we'll make access_token mandatory.
  • sameer
    sameer edited October 2016
    Although I agree on imposing limits, I think if u can address deficiency in your API, u can very much reduce number of requests per second hitting your server.
    I had mentioned it earlier but would like mention it again.

    Let user specify list of symbols and minute range Index(like 18 to 23) where index 1 corresponds to 9:16am, 2 corresponds to 9:17am etc IN ONE API REQUEST
    and u can return all 1-minute candles for those 5 minutes for each symbol in list
  • Kailash
    @sameer This is on our to-do list.
  • lazydragonfist
    Hi,
    I am working with 1 Min Candles, So I need to pull 1500 Stocks every min (In First 5 Sec) for Recent 1 Min Candle, How i can do this with out abusing API Rate Limits. I don't Need historical data. I Just need last 1 Min. Hope I am clear,
  • sujith
    Hi @lazydragonfist,
    As of now, we don't have time-based historical data fetch feature, we will provide it in future. For now, the feasible solution will be to make your own candles using websocket ticks.
  • lazydragonfist
    Hi @sujith,
    I was concern about Rate Limit, Can I open 1500 Sockets or get Historical data Requests 1500/Min .
  • sujith
    Hi @lazydragonfist,
    A Kite Connect app can open three websocket connections simultaneously. You can subscribe up to 600 scrips.
    Can you let me know about your use case?
  • lazydragonfist
    Hi @sujith,
    Its not clear about what you said "Kite Connect App". I was expecting API to use in my Custom Build PHP Application for NSE Stock Scanner.
  • sujith
    Hi @lazydragonfist,
    Users can subscribe for upto 200 scrips with one Websocket connection.
    You can check out https://screener.smallcase.com/welcome
  • lazydragonfist
    That mean I can get 600 (3 Websocket Connections) Stock Prices live and i should build 1 Min Candles with Them,
    Can I open More than 3 Websocket connections with my Own .Net project ?
  • sujith
    Hi @lazydragonfist,
    There is a soft limit for 3 connections for an api_key, soon we will be setting a hard limit for this.

    You can listen to 600 scrips and store data with 3 connections. Please note that if you subscribe for a 201st token then there won't be error message as of now, it will just not give you data. We will provide error message from next version of websockets.

    Make sure not to block the thread which listens to ticks otherwise you may miss data in between.
    I am not sure if this will fit your purpose but I would suggest using something like, the main thread for listening to ticks and spawn a worker thread which will process all your calculations and do IO operations.
  • ravikumar555
    Hi,

    Can we get quotes for a list of Scrips in a single API? Pls share details if so
  • sujith
    Hi @ravikumar555,
    Fetching quote for multiple scrips in one API call is not available yet. We will include it in next version of Kite Connect.
    You can fetch quote for single scrip in one API call. You can check out documentation here.
  • ayyaz
    if i am pulling 15 min historical candles for 100 instruments , then also i will get too many request which is not fair . this rate limit should be cummulative
  • kavanlimbasiya
    @sujith rate limit for historical api at 2 requests/second is very restrictive. Please remember we pay specifically Rs. 2000 per month for this single API. The API itself does not allow multiple tokens at once. My use case requires me to send 200 API requests at a particular time during trading hours. Only once in a day. That is not overshooting fair use. What is the alternative I can use?
  • kavanlimbasiya
    You guys even don't mention that in the API documentation.
  • sujith
    @kavanlimbasiya,
    The historical data API is provided for backtesting purposes only. For live market strategies, we suggest you to generate candles at your end using the live market data provided via Websocket API.
    You can get started here.
Sign In or Register to comment.