MQ5 python function mt5.history_deals_get problem (delayed)

 

I am using a Python code to obtain real-time orders that have already been executed; based on that, the algorithm makes decisions. The code works, but new orders take about 3 hours from the time they are completed to be registered by the mt5.history_deals_get function. Does anyone know what causes this delay? In the MT5 platform's history, the orders are visible immediately, but when executing with this function, this delay is observed...

df = pd.DataFrame()

from_date=datetime(2024,6,24)

to_date=datetime.now()

deals = mt5.history_deals_get(from_date, to_date, group='*ETH*')

try:

        df=pd.DataFrame(list(deals),columns=deals[0]._asdict().keys())

        df=df[df.profit != 0]

        df['time'] = pd.to_datetime(df['time'], unit='s')

        df=df[['time',"symbol","profit"]]

        pnl=df.profit.to_list()

except:

        pnl=[0]

print(pnl)


profits, comes with 3 hours delay....

 

When using the mt5.history_deals_get function in Python, you may encounter a problem where the data is delayed or not returned immediately. This can be frustrating, especially when you're trying to retrieve real-time market data.

One potential solution to this issue is to increase the timeout parameter in the mt5.history_deals_get function. This parameter specifies the time (in milliseconds) that the function should wait for a response from the MetaTrader 5 server. By default, this value is set to 5000 (5 seconds), but you can increase it to 10000 (10 seconds) or even 20000 (20 seconds) if you're experiencing delays.

For example, you can try the following code:

  deals = mt5.history_deals_get(symbol="EURUSD", timeframe=MT5_TIMEFRAME_M1, start=1620000000, end=1640000000, timeout=10000)

In this example, the timeout parameter is set to 10000 milliseconds, which is equivalent to 10 seconds.

Another potential solution is to use the mt5.history_deals_request function instead of mt5.history_deals_get . This function allows you to specify a callback function that will be called when the data is received, which can help prevent delays.

def on_deals_response(request_id, result): # Process the deals data here pass mt5.history_deals_request(symbol="EURUSD", timeframe=MT5_TIMEFRAME_M1, start=1620000000, end=1640000000, callback=on_deals_response)

In this example, the on_deals_response function will be called when the deals data is received, which can help prevent delays and ensure that your code can process the data in real-time.

If you're still experiencing issues with delayed data, you may want to try restarting your MetaTrader 5 platform or contacting MetaQuotes support for further assistance.

 

TENALENA: Thank you very much for your quick and detailed response. I tried with the timeout, but that doesn't seem to be the problem; nothing changes (3 hours after the order, the function receives the correct profit data). On the other hand, the function mt.history_deals_request seems to be obsolete (Python doesn't recognize it) neither I see it in the MQ5 library. I will wait for someone else to reply. Does anyone know how to contact MT5 technical support?