Convert LTT to timestamp

I am able to establish websocket connection and get the data. However, when I convert the LTP time into timestamp, its coming to be a date of 2013. what am I missing? this is the message I got from server today.

[{‘LTP’: 17392.7, ‘LTT’: 1361962826, ‘security_id’: 13, ‘tradable’: 0, ‘mode’: 64, ‘change_absolute’: -73.1, ‘change_percent’: -0.42}]

when I convert this using the below code, I am getting the timestamp as “2013-02-27 19:00:26”

import datetime
timestamp = 1361962826
date = datetime.datetime.fromtimestamp(timestamp)

Hi @shivkumr, the time provided by the Live Data Websocket Streaming API first needs to pass through the below code which will convert it into epoch:

import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
class EpocConverter {
    public static void main(String[] args) {
        try {
            long input_epoch_value = 1339062026;
            final TimeZone utc = TimeZone.getTimeZone("UTC");
            Calendar ninetyEighty = Calendar.getInstance();
            ninetyEighty.set(1980, 0, 1, 0, 0, 0);
            long timenew = ninetyEighty.getTimeInMillis() / 1000;
            long output_epoch_value = input_epoch_value + timenew;
        } catch (Exception e) {

Once you get this epoch timestamp you can convert it into the desired format.

For more details check the API docs for Live Market data WebSocket Streaming

We might have missed adding this converter in the pmclient library and will add it in the next release.

1 Like

I see this is java specific. can you give the function for python?

Hi @shivkumr

Please find below the python implementation for epocConverter -

import datetime

input_epoch_value = 1339062026
utc = datetime.timezone.utc
ninetyEighty = datetime.datetime(1980, 1, 1, tzinfo=utc)
timenew = int(ninetyEighty.timestamp())
output_epoch_value = input_epoch_value + timenew