python api does not return UTC times

 

https://www.mql5.com/en/docs/integration/python_metatrader5/mt5copyticksfrom_py


Looking at the Note section of this page, it says that the returned data is in UTC. But it is not, it is in the brokers defined timezone (for me, moscow time +3).

(the same as the charts)


it is exactly 7am UTC right now



I run the python code

from datetime import datetime, timezone
import MetaTrader5 as mt5
# display data on the MetaTrader 5 package
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
 
# import the 'pandas' module for displaying data obtained in the tabular form
import pandas as pd
pd.set_option('display.max_columns', 500) # number of columns to be displayed
pd.set_option('display.width', 1500)      # max table width to display
# import pytz module for working with time zone
 
# establish connection to MetaTrader 5 terminal
if not mt5.initialize():
    print("initialize() failed, error code =",mt5.last_error())
    quit()
 
# create 'datetime' object in UTC time zone to avoid the implementation of a local time zone offset
utc_from = datetime(2021, 8, 12, tzinfo=timezone.utc)
# request 100 000 EURUSD ticks starting from 10.01.2019 in UTC time zone
ticks = mt5.copy_ticks_from("US30", utc_from, 1000000, mt5.COPY_TICKS_ALL)
print("Ticks received:",len(ticks))
 
# shut down connection to the MetaTrader 5 terminal
mt5.shutdown()
 
# display data on each tick on a new line
print("Display obtained ticks 'as is'")
count = 0
for tick in ticks:
    count+=1
    print(tick)
    if count >= 10:
        break
 
# create DataFrame out of the obtained data
ticks_frame = pd.DataFrame(ticks)
# convert time in seconds into the datetime format
ticks_frame['time']=pd.to_datetime(ticks_frame['time'], unit='s')
 
# display data
print("\nDisplay dataframe with ticks")
print(ticks_frame.head(10))  

The exact same code that is in the demo (but calling the US30 symbol instead, and running it from today)


ticks_frame returns this


time bid ask last volume time_msc flags volume_real
0 2021-08-12 01:00:06 35481.6 35483.6 0.0 0 1628730006667 134 0.0
1 2021-08-12 01:00:07 35480.1 35482.1 0.0 0 1628730007200 134 0.0
2 2021-08-12 01:00:07 35481.6 35483.6 0.0 0 1628730007464 134 0.0
3 2021-08-12 01:00:08 35481.2 35483.6 0.0 0 1628730008172 130 0.0
4 2021-08-12 01:00:10 35480.9 35483.3 0.0 0 1628730010988 134 0.0
... ... ... ... ... ... ... ... ...
1749 2021-08-12 10:01:45 35459.4 35461.4 0.0 0 1628762505098 6 0.0
1750 2021-08-12 10:01:48 35457.9 35459.9 0.0 0 1628762508220 6 0.0
1751 2021-08-12 10:02:00 35457.6 35459.6 0.0 0 1628762520195 6 0.0
1752 2021-08-12 10:02:01 35459.1 35461.1 0.0 0 1628762521001 6 0.0
1753 2021-08-12 10:02:02 35457.9 35459.9 0.0 0 1628762522615 6 0.0




as you can see the most recently time_msc is  1628762522615, which if i run in javascripts new Date(1628762522615) it shows

new Date(1628762522615)

Thu Aug 12 2021 19:02:02 GMT+0900 (Japan Standard Time)


Which is impossible, that is 3 hours into the future.

Documentation on MQL5: Integration / MetaTrader for Python / copy_ticks_from
Documentation on MQL5: Integration / MetaTrader for Python / copy_ticks_from
  • www.mql5.com
copy_ticks_from - MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
If this is not the correct place to report bugs, where is
 

Chart times are broker times. Not JST. Not UTC.

 
William Roeder:

Chart times are broker times. Not JST. Not UTC.

read my problem please.


I am not talking about the charts, I am talking about data retrived through the API in the python client. The documentation says the times will be in UTC, but they are not.

 
I am having same problem. Any solutions? Has this been reported?
 
I have the same problem.  I tried a few options but none worked so I have to use time zone offset as a workaround.
 
WorthyVII #:

read my problem please.


I am not talking about the charts, I am talking about data retrived through the API in the python client. The documentation says the times will be in UTC, but they are not.

Read the MQL5 docs please: https://www.mql5.com/de/docs/basis/types/integer/datetime

Datetime provides secunds since 1970  but not milliseconds.

Dokumentation zu MQL5: Grundlagen der Sprache / Datentypen / Ganzzahlige Typen / Typ datetime
Dokumentation zu MQL5: Grundlagen der Sprache / Datentypen / Ganzzahlige Typen / Typ datetime
  • www.mql5.com
Typ datetime - Ganzzahlige Typen - Datentypen - Grundlagen der Sprache - Nachschlagewerk MQL5 - Nachschlagewerk über die Sprache des algothitmischen/automatischen Handels für MetaTrader 5
 
WorthyVII #: read my problem please. I am not talking about the charts, I am talking about data retrived through the API in the python client. The documentation says the times will be in UTC, but they are not.

It seems that the "Python" documentation is in conflict with the "MQL5" documentation. You probably should take the MQL version as being the most correct, and in that case it will always be in Broker server time and not UTC.