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"))
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.
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 ===============================
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.
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.
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
===============================