Nasdaq / NasdaqCloudDataService-SDK-Python

Nasdaq Data Link provides a modern and efficient method of delivery for real-time exchange data and other financial information. This repository provides a Python SDK for developing applications using Nasdaq Data Link's real-time data.
https://www.nasdaq.com/solutions/data-link-api
Apache License 2.0
56 stars 25 forks source link

Tracking Number Timestamp #33

Open lsharples1 opened 2 years ago

lsharples1 commented 2 years ago

In the Nasdaq Basic docs, I am seeing that "TrackingNumber/trackingID" for a quote is composed of the Nasdaq internal tracking number and the Timestamp in nanoseconds from midnight. I need to access the unix timestamp of this quote, and wanted to first see if there was a better way to access this than from manipulating the trackingID?

If not, I would like to confirm that the Timestamp in nanoseconds from midnight is assuming UTC?

Thanks.

lsharples1 commented 2 years ago

As a follow up, I would like to see if there is a recommended way within the python SDK to take the trackingID and return the timestamp. I have seen that the Java SDK there is a getTimestamp method. However, upon running this method with a trackingID the getTimestamp() method is returning the same as the trackingID (see attached image).

Alternatively, I have tried a python program to convert the timestamp to hex and attempting to take the 2-7 bytes for the timestamp: example trackingID = 42900650493027, converted to hex bytes 0x270496088463, in bytes 0x63, 0x84, 0x08, 0x96, 0x04, 0x27 where there are only 6 bytes.

Screen Shot 2022-09-20 at 12 20 28 PM
trunghaonguyennasdaq commented 2 years ago

Please see below for converting trackingID to timestamp in python:

def get_timestamp(tracking_id):
    return tracking_id & 0xffffffffffff
def get_counter(tracking_id):
    return tracking_id >> 48

In most cases, the returned value is going to be the same as the trackingID. In addition, the returned value is nanoseconds from midnight in EST (same timezone as New York).