1 Week Data is Wrong

kpushp
Hey,
I have tried multiple time to extract the 1week data but the date that the api gives back is of Tuesdays closing candle, but the 1week candle never closes on Tuesdays.
  • rakeshr
    Can you paste here the request log or the historical data request params?
  • kpushp
    kpushp edited October 2023
    @rakeshr

    from = datetime.datetime.now() - datetime.timedelta(days=270*7)
    to = datetime.datetime.now()

    data = kite.historical_data(instrument_token=256265, from_date=from, to_date=to, interval='week', continuous=False, oi=False)

    df = pd.DataFrame(i for i in data)

    df.to_csv("Data.csv")

    Output:
    date open high low close volume
    0 2018-06-14 00:00:00+05:30 10832.90 10834.00 10701.20 10772.05 0
    1 2018-06-21 00:00:00+05:30 10808.45 10837.00 10652.40 10671.40 0
    2 2018-06-28 00:00:00+05:30 10660.80 10777.15 10557.70 10769.90 0
    3 2018-07-05 00:00:00+05:30 10786.05 10976.65 10726.25 10948.30 0
    4 2018-07-12 00:00:00+05:30 11006.95 11078.30 10925.60 10980.45 0
    .. ... ... ... ... ... ...
    275 2023-09-21 00:00:00+05:30 19840.55 19848.75 19554.00 19716.45 0
    276 2023-09-28 00:00:00+05:30 19761.80 19766.65 19333.60 19436.10 0
    277 2023-10-05 00:00:00+05:30 19521.85 19839.20 19480.50 19811.35 0
    278 2023-10-12 00:00:00+05:30 19822.70 19849.75 19635.30 19671.10 0
    279 2023-10-19 00:00:00+05:30 19545.20 19681.80 19257.85 19281.75 0
  • rakeshr
    from = datetime.datetime.now() - datetime.timedelta(days=270*7)
    to = datetime.datetime.now()
    Any interval candle starts from the requested from timestamp. You can request the from time accordingly.
  • kpushp
    But when I run this program, the data that I get is correct for first few runs but after the 3rd or 4th time I run this it starts to give the candles of Tuesdays.
    I also tried changing the `from` timestamp to Monday, but still the same result.
  • rakeshr
    data = kite.historical_data(instrument_token=256265, from_date=from, to_date=to, interval='week', continuous=False, oi=False)
    I just ran this historical data fetch multiple times. All the runs gave the same start and end date candles.
    {'date': datetime.datetime(2018, 8, 28, 0, 0, tzinfo=tzoffset(None, 19800)),
    'open': 11731.95, 'high': 11760.2, 'low': 11567.4, 'close': 11582.35, 'volume': 0, 'oi': 0}
    ........
    {'date': datetime.datetime(2023, 10, 30, 9, 15, tzinfo=tzoffset(None, 19800)),
    'open': 19053.4, 'high': 19083.7, 'low': 18940, 'close': 18962.15, 'volume': 0, 'oi': 0}
Sign In or Register to comment.