I am trying to make a simple websocket + pandas implementation, my problem is every time stream runs, whole pandas datafram gets updated. I want to just add one row that has been added to dataframe.\
import json
import pandas as pd
import websocket
df = pd.DataFrame(columns=['foreignNotional', 'grossValue', 'homeNotional', 'price', 'side',
'size', 'symbol', 'tickDirection', 'timestamp', 'trdMatchID'])
def on_message(ws, message):
msg = json.loads(message)
msg = msg['data']
global df
df=df.append(msg, ignore_index=True)
df.head()
def on_close(ws):
print("## CLOSED ##")
def on_error(ws, error):
print(error)
def on_open(ws):
return
if __name__ == "__main__":
ws = websocket.WebSocketApp("wss://www.bitmex.com/realtime?subscribe=trade:XBTUSD",
on_open=on_open, on_message=on_message, on_error=on_error, on_close=on_close)
ws.run_forever()