Hi all, I’m new bee for python. For KITE API (Pyhon), is it possible to transfer websocket data directly to pandas dataframes or panels. I’d like to access live data using dataframes / panels to execute my code. Can someone focus your light and help me in this issue. How far panels useful in accessing data from websocket. Pls help me with your knowledge.
def on_tick(ticks, ws): global data_frame, df_cols
data = dict() #keeps extracted tick data
for tick in ticks: token = tick["instrument_token"] ltp = tick["last_price"] volume = tick["volume"] timestamp = str(datetime.datetime.now().time())
data[timestamp] = [token, ltp, volume]
tick_df = pd.DataFrame(data.values(), columns=df_cols, index=data.keys()) #convert data to a DataFrame data_frame = data_frame.append(tick_df) # append to existing
print "DataFrame: \n", data_frame
def on_connect(ws): print "Connected" ws.subscribe([53480455]) #subscribe for ticks
@tonystark 1) what if there are multiple scrips? what should I change in the above code? 2) how to use this data stored in dataframes to create ohlc 15min candles
You can use pandas data frames to store tick data for further processing. Here is a basic example to convert ticks to panda DataFrame:
2) how to use this data stored in dataframes to create ohlc 15min candles
ws.subscribe([53480455, 256265])
The above works for multiple instruments also. This is outside the scope of Kite Connect. I am afraid we can't help you with that.