Issue with get history data frame

  • Tnaagar8
    I am facing an issue with get history when running in a continuous loop where the latest price in the data frame is inaccurate and keeps referencing the previous candle special after the formation of new candle
    you can see the screen shot pasted above
    the snippet of the code that I am ruining is below


    while True:
    for name in watchlist:
    df = get_historical_data('NSE:' ,name,'5minute', 60)
    time.sleep(1)
    df = df.set_index(df['date'])
    df.index.astype('str')



    zrd_name = 'NSE:' + name
    ltp = kite.ltp(zrd_name)[zrd_name]['last_price']

    ct = (datetime.datetime.now().replace(microsecond=0))
    df.one = df.index[-1]
    one = pd.Timestamp(df.one).tz_localize(None)
    diffrence = (ct - one)
    diff1 = (ct.minute - df.one.minute)



    print("waiting to meet the conditions ",datetime.datetime.now())
    print("ltp ",ltp)
    print("diffrence ",diffrence)
    print("diff1 ",diff1)
    print(df)
  • rji_rji
    Even I faced the same issue and I am not sure why there is this inconsistency in the data frame while getting history ....hence cant apply a proper algo logic since the last reference candle is changing after refreshing to the latest candle....can someone look into this issue?

    Will post my screenshot in the next message
  • rji_rji
    Screenshot of my error attached
  • rakeshr
    @Tnaagar8 @rji_rji
    For the above scenario, it looks are you are fetching the respective candle data before candle completion. You can go through this thread to understand possible scenerio.
  • rakeshr
    Historical Data APIs are meant only for backtesting. For live strategy, you need to generate a candle at your end. Go through this thread.
Sign In or Register to comment.