0

I have a WEBsocket that works fine, and have been working with websockets before with no problems. Im drawing data from Bybit API but i just cant seem to parse the timestamp correctly, any ideas on how i can fix this, or point me towards direction that could help.

This is my code:

    live_D = []
    def on_open(ws):
        print('streamopen')
        ws.send('{"op":"ping"}');
        ws.send('{"op":"subscribe","args":["candle.1.BNBUSDT"]}')
    def on_message(ws, message):
        print('Message here:')
        # print(message)
    
    msg = json.loads(str(message))
    kline = msg['data'][0]
    klineT = kline['timestamp']
    # print(klineT)
    open = kline['open']
    high = kline['high']
    low = kline['low']
    close = kline['close']
    volume = kline['volume']
    
    
    live_D.append(klineT)
    live_D.append(float(open))
    live_D.append(float(high))
    live_D.append(float(low))
    live_D.append(float(close))
    live_D.append(float(volume))

    live_Df = pd.DataFrame(live_D)
    live_Df.columns = ['date', 'open', 'high', 'low', 'close', 'volume']

    datee = []
    for time in live_Df['date'].unique():
        readable = datetime.utcfromtimestamp(int(time / 1000))
        datee.append(readable)

Heres my full dataframe:

           date    open    high    low  close  volume
0  1.641482e+15  466.85  466.85  466.2  466.2   12.84

this is date on its own:

1641482192430132.0

I have also tried to divide my timestamp with 1000, since its in miliseconds but i still get the Errno 22 error

Then the timestamp looks like this: it is new data so looks different from the first two pastes above:

1641486480430.115

I hope you can help me.

Thanks. Best regards.

Mathias.

1 Answers1

0

Okay so bybit has really high time resolution so dividing my timestamp with 1000000 did the trick and gave the right date. GL hope you can use it.