WebSocket data miss match

taif
@sujith , hello hoping you would help trying to stream data from a web socket with the following code
on_ticks(ws, ticks):
for single_company in ticks:
token = single_company['instrument_token']
time = single_company['timestamp']
temp[token][time] = single_company['last_price']
try:
df = pd.DataFrame.from_dict(temp[token], orient='index')
ohlc = df.resample('1Min').ohlc()
df_one.loc[time.strftime("%d/%m/%y %H:%M")] = tuple(ohlc.iloc[-1])
df_one.sort_index(inplace=True)
df_one.to_csv(os.path.join(path,f'{str(token)}.csv'))
except Exception as e:
logger.info(e)


def on_connect(ws, response):
ws.subscribe(self.subscribe)
ws.set_mode(ws.MODE_FULL,subscribe)

def connect():
kws.on_ticks = on_ticks
self.kws.on_connect = on_connect


kws.connect()


I am getting a few points difference from the real value. No other error apart from that.



Thank You
  • rakeshr
    I am getting a few points difference from the real value.
    What is your source of comparison?
    on_ticks(ws, ticks)
    We see you are performing some computation inside the on_tick thread. That can be a reason for the delay. Maybe you can debug further on this on your end.
  • taif
    ok will try
  • taif
    the main problem is not delaying but the difference in price
  • sujith
    sujith edited January 2021
    @taif,
    When you generate candles from Websockets, it won't match exactly but it will be near.
    You can know the reason here.
Sign In or Register to comment.