How can i get CLOSE Price on a particular minute by using historical API?

1krishnagupta
I want to fetch CLOSE PRICE by using historical API, on any date or any time. but I don't understand which function should use or how I have to use that function.
Please guide me about this problem.
  • sujith
    You looking for live intraday candles?
  • 1krishnagupta
    1krishnagupta edited February 2022
    @sujith no sujith, i'm looking for historical data.
    assume I want CLOSE PRICE on 12-03-2021 09:50:59 time on (BANKNIFTY 33000 STRIKE DATA / or may be I can use instrument token)
  • sujith
    ok, you need to narrow down the interval and make a historical data api call or make candle data, store it in your db and fetch that.
  • 1krishnagupta
    1krishnagupta edited February 2022
    @sujith, I tried this method, is it correct?
    from_date = datetime.strptime('2021-12-15 10:30:59', '%Y-%m-%d %H:%M:%S')
    to_date = datetime.strptime('2021-12-15 10:31:59', '%Y-%m-%d %H:%M:%S')
    historical_data = kite.historical_data(instrument_token=str(i),from_date=from_date,to_date=to_date,interval='minute', oi=True)
    historical_data
    output -
    [{'date': datetime.datetime(2021, 12, 15, 10, 31, tzinfo=tzoffset(None, 19800)),
    'open': 37324.15,
    'high': 37324.15,
    'low': 37279.6,
    'close': 37279.6,
    'volume': 25,
    'oi': 37175}]
  • SRIJAN
    SRIJAN edited February 2022
    Yes. Actually,the seconds value doesn't matter,so you don't need that. Kite stores data in minute candles. So,you will get minute candles only even if you pass seconds value.
  • vivek_agg
    vivek_agg edited June 24
    Hi,
    I need the price of an option at specific time. In real time, I use kite.ltp for last traded price. For backtest I need historical data and using as below with instrument_token.
    my trade date for which I need data is '2025-06-20 11:45:00'
    calculating from_date by reducing 1 minute like below:

    from_date = trade_date - datetime.timedelta(minutes=1)
    kite.historical_data(15973378, from_date=from_date, to_date=trade_date, interval='minute')


    But getting the exception invalid from date.
    Please suggest.

    Thanks
    Vivek
  • vivek_agg
    Please note, I am taking the datetime data from the value I received from date column of historical data of nifty index for a particular date range. For a particular row/date of values of nifty, I need the price data of some option, for which I identified the instrument token and used the above mentioned call.
    I took to_date as the value received from nifty index data, subtract 1 minute from that data and use than as from value, used 'minute' as interval to fetch price data for 1 minute candle.

    The date value shown in excel sheet for the historical data for nifty is shown as "2025-06-20 11:45:00+05:30"
  • Nivas
    But getting the exception invalid from date.
    You would get this error if the date parameter is not in the expected format. You may check the documentation here to know the parameter format.
Sign In or Register to comment.