historical_data api returns the same data while calling in a loop.

rjv17
rjv17 edited July 2018 in Python client
I have get_historical_data call in the on_ticks function with 15minute interval. It doesnt seem to update the data accordingly.
For example, If I start the code at 1:05 PM, I will have data until 1:00 PM candle. This is fine.
But when time crosses 1:15PM, I expect to see the data refreshed with the new candle, which is not happening.
To test it, I left the execution on for whole day yesterday and last candle recorded was 10:00 AM candle ,the time when I started the script.

But when I exit the script and restart it will have the latest data. But this doesnt work in a loop
  • rjv17
    @rakeshr : Please help me with this.
  • rakeshr
    @rjv17
    You don't seem to be storing historical data requests properly.Can you paste here historical APIs call part of code?
  • rjv17
    rjv17 edited July 2018
    @rakeshr :
    to_date = date.now() //#psuedo code
    from_date = to_date - 100 //#psuedo code
    def on_ticks(ws, ticks):
    for i in range(0,len(planned_trades_df)):# Multiple instruments are stored in planned_df
    symbol = planned_trades_df.loc[i]['Symbol']
    instrument_token = planned_trades_df.loc[i]['Instrument Token']
    interval = planned_trades_df.loc[i]['Interval']
    records = get_historical_data(kite,instrument_token,interval,from_date,to_date)
    print("Got Historical Data")

    This records is sent to a strategy function
  • rjv17
    @rakeshr :
    I found the issue, I was using date.today() instead of date.now() of datetime package ,which was also giving me time stamp at the time of execution and to_date is limiting the time period.
  • rjv17
    @rakeshr :

    I have seen that you were recommending people not to use historical_data api for live trading.
    Would this be a problem even if I am planning to use 15min time frame?
  • Guhan
    Guhan edited August 2018
    @rjv17, what is 100 in from_date = to_date -100, is it 100 minutes?
    Whatever the time_frame is, trading using historical api is not recommended because of huge latency. Due to which you will have trouble filling your orders at desired price point, which in turn defeats the purpose of algo trading
  • rjv17
    My purpose of coding my trading strategy is to avoid staring at the screen whole day.
    And all my orders are coded to be MARKET. Will it work?
  • rakeshr
    @rjv17
    I have seen that you were recommending people not to use historical_data api for live trading.
    Would this be a problem even if I am planning to use 15min time frame?
    No, it should not be a problem for longer time frame.
Sign In or Register to comment.