akapur / pyiqfeed

Python LIbrary for reading DTN's IQFeed
GNU General Public License v2.0
168 stars 108 forks source link

timestamp human readable #49

Closed sinaak closed 2 years ago

sinaak commented 3 years ago

I have a probem converting the timestamp to human-readable format. in [example.py] line 416 (https://github.com/akapur/pyiqfeed/blob/master/example.py#L416) when i print what i get is

res = [ ('2021-02-03', 14640000000, 382.94, 383.09, 382.94, 383.09, 9223, 1100, 0), ...]

The first element is a date, the second element should be time. I cannot translate this UNIX timestamp to a human-readable timestamp. Can you please tell me what is its format. how can I see the hour:minute:second:millisecond

karunkrishna commented 3 years ago

I do the following

from pandas import to_timedelta

def _to_datetime(iq_date, iq_time):
        return iq_date + to_timedelta(int(iq_time / 1000000), 's')
vinogradov-m commented 3 years ago

This is the number of microseconds passed since the beginning of the day.

import numpy as np

# res is a variable from your example
data = res[0]
date = data[0]  # np.datetime64['D']
time = data[1]  # int

dt = date + np.timedelta64(time, "us")

btw, here is an example of working with these timestamps: https://github.com/akapur/pyiqfeed/blob/master/pyiqfeed/field_readers.py#L259-L272

akapur commented 2 years ago

Not a problem with pyiqfeed.