← Work

brokerclock

I built brokerclock to convert MetaTrader 5 broker server time to UTC and back. It finds the broker's daylight-saving rule from bar history and never imports the MetaTrader5 package.

  • Python
  • IANA time zones
  • pandas
  • MetaTrader 5
  • PyPI
pip install brokerclock

The problem

MetaTrader 5 returns bar, tick, deal and order times as the broker's server clock written as epoch seconds, not UTC. Many brokers run GMT+2 in winter and GMT+3 in summer, switching on US dates.

A fixed offset is wrong for part of every year, and a European daylight-saving rule is wrong for about three weeks in March and one week around the start of November. Query dates and order expirations are read on the same server clock.

The approach

I model the server clock in ServerZone as an IANA time zone plus a shift in 15-minute steps, so every conversion uses the rule in force at that moment. The repeated hour needs an explicit choice, and the skipped hour raises an error.

detect() reads the Friday 17:00 New York weekly close from M1 to H1 bars, scores fixed, US, EU and Australian clocks, and returns its evidence: matched weeks, outliers and ties.

check() and measure_offset() confirm the clock against live ticks and refuse stale ones. brokerclock.pandas converts whole columns and the arrays copy_rates_* returns.

The result

I published brokerclock 0.1.0 on PyPI for Python 3.10 to 3.14, with 260 tests. It needs only the standard library, plus tzdata on Windows, so it also runs on Linux and macOS, where the MetaTrader5 package does not install.