MT5 Python copying ticks not working properly

 

I'm trying to copy the last X ticks from a given currency, but am left with sporadic results.

for currency in currency_pairs:
    server_time = mt5.symbol_info_tick(currency).time
    ticks = mt5.copy_ticks_from(currency, server_time, 50, mtmain.COPY_TICKS_INFO)
    logging.info(f"{currency} {ticks}\n")

Here I should be retrieving the last 50 ticks starting from the current server time. It partially works; the following output shows the correct tick (bid and ask), as they line up with what I see in MetaTrader. The problem is the number of ticks varies - sometimes only a single tick, other times 4, or 9, etc. instead of 50.

2024-01-25 12:29:23,648 - INFO - XAUUSD.sml [(1706218162, 2017.825, 2017.925, 2017.875, 0, 1706218162083, 6, 0.)]

2024-01-25 12:29:23,648 - INFO - XAGUSD [(1706218161, 22.86, 22.865, 22.8625, 0, 1706218161395, 2, 0.)]

2024-01-25 12:29:23,648 - INFO - GER30.sml [(1706218162, 16909.5, 16911.2, 16910.4, 0, 1706218162186, 2, 0.)]

2024-01-25 12:29:23,648 - INFO - UK100 [(1706218159, 7570.4, 7572., 7571.2, 0, 1706218159765, 4, 0.)]

2024-01-25 12:29:23,648 - INFO - FRA40 [(1706218159, 7522.2, 7523.9, 7523.1, 0, 1706218159185, 4, 0.)
 (1706218159, 7522.2, 7523.4, 7522.8, 0, 1706218159429, 4, 0.)]

2024-01-25 12:29:23,648 - INFO - EU50 [(1706218162, 4593.4, 4595.8, 4594.6, 0, 1706218162192, 4, 0.)
 (1706218162, 4593.4, 4594.8, 4594.1, 0, 1706218162691, 4, 0.)]

2024-01-25 12:29:28,653 - INFO - EURUSD.sml [(1706218167, 1.08283, 1.08289, 1.08286, 0, 1706218167228, 6, 0.)
 (1706218167, 1.08283, 1.0829 , 1.08287, 0, 1706218167610, 4, 0.)
 (1706218167, 1.08285, 1.08291, 1.08288, 0, 1706218167631, 6, 0.)
 (1706218167, 1.08286, 1.08292, 1.08289, 0, 1706218167870, 6, 0.)]

2024-01-25 12:29:28,654 - INFO - EURAUD [(1706218167, 1.64619, 1.64629, 1.64624, 0, 1706218167043, 6, 0.)
 (1706218167, 1.6462 , 1.64629, 1.64625, 0, 1706218167137, 2, 0.)
 (1706218167, 1.64621, 1.64629, 1.64625, 0, 1706218167228, 2, 0.)
 (1706218167, 1.64622, 1.6463 , 1.64626, 0, 1706218167248, 6, 0.)
 (1706218167, 1.64625, 1.64635, 1.6463 , 0, 1706218167396, 6, 0.)
 (1706218167, 1.64622, 1.64632, 1.64627, 0, 1706218167631, 6, 0.)
 (1706218167, 1.64622, 1.64631, 1.64627, 0, 1706218167686, 4, 0.)
 (1706218167, 1.6462 , 1.6463 , 1.64625, 0, 1706218167753, 6, 0.)
 (1706218167, 1.64621, 1.6463 , 1.64626, 0, 1706218167803, 2, 0.)]

2024-01-25 12:29:28,655 - INFO - EURGBP.sml [(1706218167, 0.85294, 0.85303, 0.85299, 0, 1706218167241, 4, 0.)
 (1706218167, 0.85295, 0.85303, 0.85299, 0, 1706218167270, 2, 0.)
 (1706218167, 0.85294, 0.85302, 0.85298, 0, 1706218167732, 6, 0.)]

If I retrieve the last 50 ticks not from server time, but from local time (2h behind), then I get 50 ticks every time.

Another weird thing is that the server time retrieved from the last tick (mt5.symbol_info_tick(currency).time) is 7h behind GMT+2, or 7h behind what is shown in the MetaTrader5 terminal. These problems persist for all broker servers I have tried.