MetaTrader5 Python history_orders_get/history_deals_get — authoritative time semantics

 

Dear MetaQuotes Technical Support,

We request an authoritative technical clarification of the time semantics used by the official MetaTrader5 Python package. This is a specification question, not account troubleshooting. The requesting environment uses MetaTrader5 Python package 5.0.5735 with MetaTrader 5 terminal build 6140.

Please answer each question separately:

  1. For history_orders_get(date_from, date_to) and history_deals_get(date_from, date_to), when date_from and date_to are supplied as integer seconds since 1970-01-01, what timezone or time reference do those integers represent: UTC, trading-server time, local terminal or operating-system time, or another convention?
  2. For returned historical order fields ORDER_TIME_SETUP and ORDER_TIME_DONE, and historical deal field DEAL_TIME, what timezone or time reference do the integer or datetime values represent?
  3. For ORDER_TIME_SETUP_MSC, ORDER_TIME_DONE_MSC and DEAL_TIME_MSC, are the millisecond values based on the same absolute time basis as the corresponding seconds fields? If so, what is that basis?
  4. Is date_to inclusive or exclusive for history_orders_get and history_deals_get? If it is inclusive, what exact precision or granularity applies at the upper boundary?
  5. Do history_orders_total and history_deals_total use exactly the same time-boundary semantics as history_orders_get and history_deals_get?
  6. Are these semantics invariant across brokers and trading servers, or can a broker or trading-server configuration influence the request boundaries or the returned order and deal time values?
  7. If broker or server configuration can affect these semantics, what official method should a Python integration use to determine the convention applicable to a specific trading server?
  8. Please identify any official documentation page or specification governing your answers, if one is available.

For audit purposes, please state explicitly when a question is outside MetaQuotes’ authority or requires confirmation from the broker.

Thank you.


 
Savane Oumar:

We request an authoritative technical clarification of the time semantics used by the official MetaTrader5 Python package. This is a specification question, not account troubleshooting. The requesting environment uses MetaTrader5 Python package 5.0.5735 with MetaTrader 5 terminal build 6140.

Forum on trading, automated trading systems and testing trading strategies

Timezones in Metatrader 5: unclear Python documentation

Anthony Eric Gillon Dawson, 2024.01.31 17:45

Well it seems a bit of a mess... in my case ticks are coming out in proper Unix time UTC while M10, H1 and so on come out with a Unix timestamp shifted by broker time, in my case UTC + 2. As python thinks all Unix stamps are in UTC this causes all sorts of problems in trying to convert them back to UTC particularly if they are also subject to daylight saving! What's the best solution to convert these back to UTC with daylight savings awareness? Or perhaps I should just resample the tick data into M10 & H1 timeframes?


Forum on trading, automated trading systems and testing trading strategies

Timezones in Metatrader 5: unclear Python documentation

Anil Varma, 2025.07.23 13:48

I thought this might be useful information to forum members.

I have used following code to get Brokers time (Check with your broker, which time zone its data represented) and returned by copy_rates_range() or similar methods.

    def _downloadData(self, symbol: str, tfEnum: MT5TimeFrame, UTCFrom: datetime, UTCTo: datetime) -> pd.DataFrame:

        rates = mt5.copy_rates_range(symbol, tfEnum.value, UTCFrom, UTCTo) # <class 'numpy.ndarray'>

        if rates is None or len(rates) == 0:
            raise ValueError(f"No data returned from MT5 for {symbol} {tfEnum.name} between {UTCFrom} and {UTCTo}")

        df = pd.DataFrame(rates)

        # PepperStone: Cyprus timezone (DST-aware, same as broker/server time)
        tzPepperStone = pytz.timezone("Europe/Nicosia")

        # Convert timestamp (MT5 server time) to aware datetime
        df['DateSVR'] = pd.to_datetime(df['time'], unit='s').dt.tz_localize(tzPepperStone)
        # Also add UTC and New York time columns for clarity
        df['DateUTC'] = df['DateSVR'].dt.tz_convert('UTC')
        df['DateNYC'] = df['DateSVR'].dt.tz_convert('America/New_York')

        df = df.drop(columns=['time', 'real_volume'])
        df.set_index('DateNYC', inplace=True)
        return df

And it has given the correct results

Regards


 
Ryan L Johnson #:


Thank you for the references.

For this particular case, I need an authoritative MetaQuotes specification or official confirmation for the Python API semantics, especially for history_orders_get() / history_deals_get(), the returned ORDER_TIME_* / DEAL_TIME fields, and the date_to boundary.

Do you know of any official MetaQuotes documentation or statement that defines these semantics explicitly?