fyers_apiv3 : History vs. Tick data

I wish to retrieve OHLC data of more than 20 symbols on 5 min intervals. Now, History approach fetches data only when I run my app (which I would need to do every five minutes). While Tick data refreshes every second - and that is an overkill in my use case. So how to fetch 5 min OHLC data automatically and continuously? Any thoughts how I should be going about it. Thanks.

Hi @KpinKHNjsr

You can hit histroy API after 5 minutes whenever you need.

Hi @KpinKHNjsr

You should only be using Historical api to fetch OHLC data on 5 min interval. If you try to use LTP (and create your own OHLC based on LTP), it will be firstly not be perfect, secondly you will hit the api limit for the day. Here is a sample code using Historical API for your reference:

def fetchOHLC2(ticker,interval,duration):
    range_from = dt.date.today()-dt.timedelta(duration)
    range_to = dt.date.today()

    from_date_string = range_from.strftime("%Y-%m-%d")
    to_date_string = range_to.strftime("%Y-%m-%d")
    data = {
        "symbol":ticker,
        "resolution":interval,
        "date_format":"1",
        "range_from":from_date_string,
        "range_to":to_date_string,
        "cont_flag":"1"
    }

    response = fyers.history(data=data)['candles']

    # Create a DataFrame
    columns = ['Timestamp','Open','High','Low','Close','Volume']
    df = pd.DataFrame(response, columns=columns)

    # Convert Timestamp to datetime in UTC
    df['Timestamp2'] = pd.to_datetime(df['Timestamp'],unit='s').dt.tz_localize(pytz.utc)

    # Convert Timestamp to IST
    ist = pytz.timezone('Asia/Kolkata')
    df['Timestamp2'] = df['Timestamp2'].dt.tz_convert(ist)

    return (df)

# Fetch OHLC data using the function
response_df = fetchOHLC2("NSE:RELIANCE-EQ","5",250)

Thanks Mr.Singhal. Of course, I use history candles for getting OHLC of 5 min candle.