Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert epoch to date in plotly

I receive ohlc data from Kraken with EPOCH time in ms. Es: 1599651300

When I plot the data, I see the epoch number, but I would like to see a date (es: 10-Sep-2020 12:23).

How can I do it?

ohlc, last = k.get_ohlc_data("BCHEUR", 5)

# plot candlestick chart
candle = go.Candlestick(
    x = ohlc['time'],
    open = ohlc['open'],
    close = ohlc['close'],
    high = ohlc['high'],
    low = ohlc['low'],
    name = "Candlesticks")

data = [candle]

# style and display
layout = go.Layout()
fig = go.Figure(data = data, layout = layout)
plot(fig)

enter image description here

like image 339
FabioDev Avatar asked Oct 29 '25 15:10

FabioDev


1 Answers

For this answer, I am assuming that ohlc is a dataframe. In that case, before plotting you can convert ohlc['time'] to regular readable datetime as the following:

ohlc['time'] = pd.to_datetime(ohlc['time'],unit='s')

Or

ohlc['time'] = ohlc['time'].map(lambda x : pd.Timestamp(x, unit='s'))

Input :

>>> ohlc
         time
0  1599651300

Output :

>>> ohlc
                 time
0 2020-09-09 11:35:00
like image 185
Grayrigel Avatar answered Oct 31 '25 05:10

Grayrigel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!