Wrong Data from Historical Data API

deep_perfect
I am getting wrong 5 minute candle data for all the symbol.
I am fetching the 5minute candle data every 5 minutes, I am getting wrong data for the last candle every time.

Code for fetching the Data:
data = pd.DataFrame(
kite.historical_data(instrument, dt.date.today() - dt.timedelta(4), dt.date.today(), "5minute"))

Log :
Sys Date: 2020-06-15 10:45:00.012289 Fetching OHLC 5minute data: AXISBANK
2020-06-15 10:45:03.039695 AXISBANK
open high low close volume
date
2020-06-15 10:35:00+05:30 392.60 392.85 392.0 392.25 382664
2020-06-15 10:40:00+05:30 392.20 393.35 392.0 392.65 394518
2020-06-15 10:45:00+05:30 392.65 392.65 392.6 392.60 322
===============================
Sys Date: 2020-06-15 10:50:00.013289 Fetching OHLC 5minute data: AXISBANK
2020-06-15 10:50:01.058491 AXISBANK
open high low close volume
date
2020-06-15 10:40:00+05:30 392.20 393.35 392.00 392.65 394518
2020-06-15 10:45:00+05:30 392.65 393.30 390.60 391.00 803446
2020-06-15 10:50:00+05:30 391.00 391.00 390.55 390.55 25445
===============================

Is Zerodha's API reliable?
I have spend 2000 for the Historical Data API.

Can someone guide me, what is going wrong here ?
  • rakeshr
    Sys Date: 2020-06-15 10:45:00.012289 Fetching OHLC 5minute data: AXISBANK
    2020-06-15 10:45:03.039695 AXISBANK
    You seems to be requesting at wrong time to fetch latest formed 5 minute candle. You can go through this thread.
    Historical data isn't meant to be polled continuously for the live market, it's designed for backtesting. You can use Websocket Streaming data for the same. You can have look at this thread.
  • deep_perfect
    Thanks for the reply.
    Now I am comparing the 5 minute candle historical data immediately when we pass absolute to_date time in the API as 2020-06-17 09:55:00 v/s the system time.

    It was expected that when passing closed candle time, the last candle will not change.
    However, the values still changes even after 55 seconds after closing the candle.
    In short, historical data quality is poor.

    I can understand that tick data is more reliable but to collect the ticks and form the 5 minute candle myself requires a lot of infrastructure and code because I am deciding the symbol to trade on runtime.

    First record - passed as system time; second record as absolute time: 2020-06-17 09:55:00 as Datetime object in python.

    Logs:
    ===============================
    Sys Date: 2020-06-17 09:55:50.807117 Fetching OHLC 5minute data: AXISBANK
    2020-06-17 09:55:51.924181 AXISBANK
    open high low close volume
    date
    2020-06-17 09:55:00+05:30 385.4 385.6 385.4 385.6 2339
    open high low close volume
    date
    2020-06-17 09:55:00+05:30 385.4 385.75 385.4 385.75 8128
    ===============================
    Sys Date: 2020-06-17 09:55:52.942239 Fetching OHLC 5minute data: AXISBANK
    2020-06-17 09:55:54.031301 AXISBANK
    open high low close volume
    date
    2020-06-17 09:55:00+05:30 385.4 385.6 385.4 385.6 2339
    open high low close volume
    date
    2020-06-17 09:55:00+05:30 385.4 385.75 385.4 385.75 8128
    ===============================
    Sys Date: 2020-06-17 09:55:55.050360 Fetching OHLC 5minute data: AXISBANK
    2020-06-17 09:55:56.595448 AXISBANK
    open high low close volume
    date
    2020-06-17 09:55:00+05:30 385.4 386.4 385.4 385.85 175105
    open high low close volume
    date
    2020-06-17 09:55:00+05:30 385.4 386.4 385.4 385.7 172701
    ===============================
    Sys Date: 2020-06-17 09:55:57.616507 Fetching OHLC 5minute data: AXISBANK
    2020-06-17 09:55:58.688568 AXISBANK
    open high low close volume
    date
    2020-06-17 09:55:00+05:30 385.4 386.4 385.4 385.85 175105
    open high low close volume
    date
    2020-06-17 09:55:00+05:30 385.4 386.4 385.4 385.7 172701
    ===============================
  • rakeshr
    However, the values still changes even after 55 seconds after closing the candle.
    In short, historical data quality is poor.
    As explained above Historical data APIs, weren't meant for live polling. DB write operation can take a few seconds sometimes. You can go through similar thread here.
This discussion has been closed.