Hi I am trying to store tick information into pandas data frame in a continuous manner so that i can plot updated price,volume and averages not on a snap shot, but with live streaming data. I am using multi threading to handle this process in a separate thread. I am doing something like this -
def on_tick(ticks, ws):
#logging.info("on tick - {}".format(json.dumps(ticks))) # Empty dataframe df = pd.DataFrame() for tick in ticks: dict = {"token": tick["instrument_token"],"date":datetime.now().strftime("%d-%m-%y"),"time":datetime.now().strftime(" %H-%M-%S"),"price": tick["last_price"]} df = df.append(dict,ignore_index = True) print(df) # Can I use a counter in the for loop to count the number of ticks received?
But I am getting something like this - date price time token 0 21-11-17 3676.0 23-51-00 53480711 date price time token 0 21-11-17 3677.0 23-51-01 53480711 date price time token 0 21-11-17 3676.0 23-51-10 53480711 date price time token 0 21-11-17 3677.0 23-51-21 53480711
Can somebody help me with a hint / snippet so that I get a continuously updating data frame (in a single frame without repeated column names and, incrementing index corresponding to the number of json record received? (I though understand that print(df) will show me only a snapshot at that particular instant). Regards Pinaki
Need simply some hint... I do not need any strategy , i only need help in data handling as described above.
Thanks a lot. It is really helpful in advancing to next stage.