It looks like you're new here. If you want to get involved, click one of these buttons!
the code works fine on main thread but when i put it in thread mode, after some time it shows error 1006 , reconnection happens but after some time again shows same error
tokens_list = [779521,784129,348929]
tick_df = pd.DataFrame(columns=['name','Datetime','Open','High','Low','Close','ltp'])
df_cols = ["Timestamp", "Token", "LTP"]
data_frame = pd.DataFrame(data=[],columns=df_cols, index=[])
def on_ticks(ws, ticks):
# print(ticks)
global data_frame, df_cols
data = {}
for company_data in ticks:
token = company_data["instrument_token"]
ltp = company_data["last_price"]
timestamp = company_data['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')
candles=ggframe.groupby(['Token']).resample('1min').agg({'LTP':'ohlc'})
candles.columns=['open','high','low','close']
print (candles)
def on_connect(ws, response):
ws.subscribe(tokens_list)
ws.set_mode(ws.MODE_FULL,tokens_list)
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.connect()
#kws.connect(threaded=True)
# while True:
# def on_ticks(ws, ticks):
# helper_method(ticks)
# def helper_method(ticks):
# global data_frame, df_cols
# data = {}
# for company_data in ticks:
# token = company_data["instrument_token"]
# ltp = company_data["last_price"]
# timestamp = company_data['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')
# candles=ggframe.groupby(['Token']).resample('1min').agg({'LTP':'ohlc'})
# candles.columns=['open','high','low','close']
# print (candles)
# kws.on_ticks=on_ticks