How to store/append websocket live streaming data into pandas dataframe

D11458
Hello Forum,

Could anyone please explain how to store/append the live streaming data of multiple nse instruments in pandas dataframe.
  • mukesh_Chaudhary
    I am using python dequeu to store the data and process it. Please have a look at following.
    https://youtu.be/FCshuy9gTOQ
  • EquityOnSMS
    from kiteconnect import KiteConnect
    from kiteconnect import KiteTicker
    import pandas as pd

    #generate trading session here
    .........

    #get dump of all NSE instruments
    instrument_dump = kite.instruments("NSE")
    instrument_df = pd.DataFrame(instrument_dump)

    def tokenLookup(instrument_df,symbol_list):
    """Looks up instrument token for a given script from instrument dump"""
    token_list = []
    for symbol in symbol_list:
    token_list.append(int(instrument_df[instrument_df.tradingsymbol==symbol].instrument_token.values[0]))
    return token_list

    def tickerLookup(token):
    global instrument_df
    return instrument_df[instrument_df.instrument_token==token].tradingsymbol.values[0]

    tickers = ["INFY", "ACC", "ICICIBANK"]

    data = pd.DataFrame(columns=['datetime','ticker', 'ltp', 'oi'])
    def on_ticks(ws,ticks):
    global data
    for tick in ticks:
    s = pd.DataFrame([[tick['last_trade_time'],tickerLookup(tick['instrument_token']),float(tick['last_price']),int(tick['oi'])]], columns = ["datetime","ticker","ltp","oi"])
    data = data.append(s, ignore_index = True)


    def on_connect(ws,response):
    ws.subscribe(tokens)
    ws.set_mode(ws.MODE_FULL,tokens) # Set all token tick in `full` mode.

    kws.on_ticks=on_ticks
    kws.on_connect=on_connect
    kws.connect()
  • D11458
    Hi - This is sorted out long back, thanks. The thread should be close now.
This discussion has been closed.