Live 5 Minute OHLC for multiple symbols

Snischal
Hi, Is it possible to retrieve live 5 Minute OHLC for multiple symbols or do i need to convert tick data into OHLC. Request guide on the possible methods.
Regards
Tagged:
  • SRIJAN
    SRIJAN edited January 2022
    You can use historical data or make candles using ticks .
    https://kite.trade/forum/discussion/2604/convert-ticks-to-candle
  • Snischal
    Hi, My overall requirement is to get 5 min close for Banknifty and 5 min OHLC data for ITM CE and PE(1 each). I'm trying the undermentioned code to get the historical data along with ticks for Banknifty, however this returns an empty string for historical data.
    Kindly suggest a workable method


    def on_ticks(self,ws,ticks):
    self.ticks_queue.put(ticks)



    def on_connect(self,ws, response):
    print("Connected")
    ws.subscribe(self.tracker_token)
    ws.set_mode(ws.MODE_FULL,self.tracker_token)


    def on_close(self,ws,code,reason):
    print('Socket closed')

    def track(self):

    c = self.ticks_queue.get()
    print(c)
    global data_frame, df_cols
    data = dict()
    for d in c:
    token = d['instrument_token']
    ltp = d['last_price']
    timestamp = d['exchange_timestamp']

    data[timestamp] = [timestamp,token,ltp]
    tick_df = pd.DataFrame(data.values(), columns=df_cols, index=data.keys())
    data_frame = data_frame.append(tick_df)

    ggframe = data_frame.set_index(['Timestamp'],['Token'])
    print(ggframe)
    gticks=ggframe.loc[:,['LTP']]
    candles = gticks['LTP'].resample('5min').ohlc().dropna()
    print(candles)
    print('Printing from track')
    historic_df = pd.DataFrame()
    historic_df = self.kite.historical_data(11186434, "2021-01-06", "2021-01-07", "5minute")
    print(historic_df.to_string(index = False))
  • Snischal
    I missed out on mentioning above that in addition to 5 min ohlc for options, 5 min close for banknifty, i also need historical data for the ITM option. So overall i need the following data simultaneously:
    1. 5 min close for Banknifty
    2. 5 min OHLC for CE
    3. 5 min OHLC for PE
    4. Historical data for CE (even 1 day is sufficient)
    5. Historical data for PE (even 1 day is sufficient)
    Note: The catch is that the strike price for the historical data is not fixed for the day, it can vary, so ill have to call historical data whenever the strike price changes.

    Request please help guys.
  • SRIJAN
    If you just need last 5 min data and 1 day historical data,i would say it's better to use historical data api rather than websocket. About your historical data being empty,you are passing wrong dates, it's 2022 :p ,you're passing 2021 :D . And if you have to call data for different strikes every time ,just download the instruments file and use csv module to get the instrument token of the strike(s) you want.
  • Snischal
    :D :D and i spent hours trying to sort that shit out!!
    thanks a ton
Sign In or Register to comment.