Getting Invalid token error after sending 400 requests for GetHistoricalData 1 minute interval

arunkumarr
arunkumarr edited January 5 in API clients
Getting Invalid token error after sending 400 requests for GetHistoricalData for 1minute interval.
Do we need to refresh request token in this case ?

  • arunkumarr
    getting this error without closing session
  • tonystark
    Are you sure it is invalid token? Could you post the error response json?

    If you are sending too many requests you might be getting rate limited. If you are getting status code 429 then it is for rate limits.
  • arunkumarr
    arunkumarr edited January 5
    this error message is thrown by kite connect library. i am not using any other client. "invalid token" is the exception message. I have added 50 milliseconds delay between each request. And this error is coming at request number 411
  • tonystark
    There will be a debug mode flag that you can set in the constructor of the Kite object. And it will print extra logs. Try enabling that to see the full error message.
  • arunkumarr
    already true, kite = new Kite(MyAPIKey, Debug: true);
  • tonystark
    Could you post the logs when the error happened?
  • arunkumarr
    KiteConnect.InputException
    HResult=0x80131500
    Message=invalid token
    Source=KiteConnect
    StackTrace:
    at KiteConnect.Kite.Request(String Route, String Method, Object Params, Dictionary`2 QueryParams, Boolean json)
    at KiteConnect.Kite.GetHistoricalData(String InstrumentToken, DateTime FromDate, DateTime ToDate, String Interval, Boolean Continuous, Boolean OI)


    This exception was originally thrown at this call stack:
  • arunkumarr
    i have posted logs. pls check
  • tonystark
    Is this a GUI app? The logs you posted seem to be internal .net build logs. Is there something along the lines of "Console logs"? Library uses `Console.WriteLine` to write logs.

    If it is an `InputException` that means the access token was set to empty. Do you have multiple KiteConnect objects? If yes you have to set same access token for all of them.
  • arunkumarr
    single KiteConnect object i am using
  • arunkumarr
    arunkumarr edited January 5
    how to print kite logs? do we need to use any kite object to print logs ?
  • arunkumarr
    i don't see anything other than these logs
  • tonystark
    If you have enabled debug mode KiteConnect will automatically print logs to console. The way to see it depends on the IDE you are using and any help with that is out of scope of this forum. If you are using Visual Studio this link might help: https://stackoverflow.com/questions/2542599/having-the-output-of-a-console-application-in-visual-studio-instead-of-the-conso
  • arunkumarr
    Immediate window shows only this
    Exception thrown: 'KiteConnect.InputException' in KiteConnect.dll
  • tonystark
    Could you tell for which stock id you got the exception? This is may be due to the instrument token for that stock being invalid
  • tonystark
    This token doesn't exist. You can get valid instruments using `GetInstruments` function. Or refer to `http://api.kite.trade/instruments` API.
  • arunkumarr
    arunkumarr edited January 5
    for now i am not getting invalid token error after increasing time between 2 requests
  • arunkumarr
    arunkumarr edited January 5
    this historical data is real time data or delayed ?
  • arunkumarr
    i mean if i request for current minute/last minute data, then it is delayed or real time ?
  • sujith
    The historical data API is provided for backtesting purposes only. We suggest creating candles at your end for live market strategies. You may refer to this thread to know more about generating candle data.
  • arunkumarr
    arunkumarr edited January 8
    may i know the delay time ? OR will it be possible from current minute to request for previous(-1) minute. (example at 11:30 am can i request for 11:29 am 1 minute ?)
    Or is there any real time data streaming api ?
  • sujith
    You may refer to this thread.
  • arunkumarr
    Thanks, can you pls provide websocket reference for C# .net ?
  • sujith
    You can refer to this sample project.
  • arunkumarr
    arunkumarr edited January 9
    in latest version with INTERVAL_MINUTE single tick how much stocks we can request/get via websocket streaming ?
  • sujith
    You may get one or you may get 3000 which is the maximum number of tokens allowed for subscription. You can read more about Websocket API behavior on FAQs.
  • arunkumarr
    i have subscription for kite connect api and Addons
    Historical API both, do we need any other subscription for wesocket ?
  • sujith
    The base subscription includes all the features of Kite Connect API except historical data. Only historical data API is an add-on subscription.
  • arunkumarr
    arunkumarr edited January 9
    this json i am getting from INTERVAL_MINUTE tick
    "{\"Mode\":\"quote\",\"InstrumentToken\":1293825,\"Tradable\":true,\"LastPrice\":1136,\"LastQuantity\":15,\"AveragePrice\":1130.81,\"Volume\":79814,\"BuyQuantity\":13478,\"SellQuantity\":21650,\"Open\":1104.3,\"High\":1145.45,\"Low\":1100,\"Close\":1098.8,\"Change\":0,\"Bids\":null,\"Offers\":null,\"LastTradeTime\":null,\"OI\":0,\"OIDayHigh\":0,\"OIDayLow\":0,\"Timestamp\":null}"

    looks it is giving full day volume and not of current minute. Right ?
  • arunkumarr
    arunkumarr edited January 9
    how to get current minute statistics from websocket streaming ?above resulting json is for full day while using INTERVAL_MINUTE
  • sujith
    @arunkumarr,
    Please spend 10 minutes and read the documentation, all these are the covered there and few that are missed are present in the FAQs.
    Websocket API gives day OHLC values. You need to generate candles at your end for live market strategies using Websocket API.
  • arunkumarr
    great, thanks
This discussion has been closed.