CFDs are complex instruments and come with a high risk of losing money rapidly due to leverage. 64 % of retail investor accounts lose money when trading CFDs with this provider. You should consider whether you understand how CFDs work and whether you can afford to take the high risk of losing your money.

Millis and Timestamp

Hi there!

Millis/Timestamp are returned when I ask for /closestrategy and for /quotes, but I can’t understand how they can be read.
I see… [1501621140000,100.0] in the first data… so the number 1501621140000 how can be used to know the day/month/year ? TIA (I’m not a programmer but just a “techie” so don’t be surprised if the question is very simple)

2 Likes

That timestamp number is the number of milliseconds elapsed since a certain set time point, usually called epoch if I’m not mistaken. I believe standard is Jan 1, 1970 00:00:00.

So you probably should search for ways to convert “milliseconds timestamp to datetime in your programming language of choice”. Or write what language/tool you intend to automate this process with, and perhaps we can help you further!

Edit: For practical demonstration https://currentmillis.com/

3 Likes

Correct! The timestamp returned is an epoch timestamp and you can find conversions in almost any programming language.
I know this type of format for datetimes is not the standard in JSON / REST, as it should follow the standard ISO 8601. Example: “2018-10-19T18:25:43.511Z” but … it might be faster in performance to deal with epoch timestamps than with the standard datetime format. What do you think?

3 Likes

@GAlbano76 - As @jesusbc mentioned, a timestamp is simply the number of seconds (milliseconds) since the unix epoch -> January 01, 1970 UTC.

Conversions to human-readable dates can be done as follows
(examples in Python, R and MS Excel):

Python:
import pandas as pd
pd.to_datetime(1501621140000, unit=‘ms’, utc=True)

R: (processes timestamps in seconds, divide ms by 1000)
as.POSIXct(1501621140000 / 1000, origin=“1970-01-01”, tz=“UTC”)

MS Excel:

  1. Enter your timestamp (1501621140000) in let’s say, cell A1

  2. Remember it’s seconds from 01-01-1970, so you need to:

  • Divide by 1000 to convert to seconds,
  • Then divide by 86,400 (the number of seconds in 1 calendar day)
  • Then add the date (January 01, 1970) to the result

… to get the date corresponding to the timestamp.

You can do this easily by pasting the following formula in a cell (in this case C1, with the timestamp in A1):
=(A1/1000)/86400+DATE(1970,1,1)

This will first give you a numeric value in your cell. You’ll need to convert the cell format to Date in Cell -> Format Cells, to get this:

4 Likes

Thanks everyone!

I use Excel 2007 VBA (and maybe I will use VB6 if I need to…) but I had to change the formula that you gave me (; instead of , ):

= (A1/1000)/86400+DATE(1970**;1;**1) OR = (A1 / 86400000) + 25569

1 Like