Expiration Date - MT5 Python API

 
Hello guys! I created that topic because I am having some issues trying to set an expiration date in my orders. I am using the MT5 Python API, and that´s the structure:

        request = {
            'action': mt5.TRADE_ACTION_PENDING,
            'symbol': [stock symbol],
            'price': [price],
            'sl': [stop loss value],
            'tp': [take profit value],
            'type': mt5.ORDER_TYPE_BUY_LIMIT,
            'volume': [volume],
            'type_time': mt5.ORDER_TIME_SPECIFIED,
            'time_expires': ?????,
            'type_filling': mt5.ORDER_FILLING_IOC,
            'comment': [comment]

            }

No matter what I try, i am receiving the error "Invalid expiration (10022)". I tried some different ways to set that date, just like:

'time_expires': datetime.now(timezone.utc) + timedelta(days=7),


import datetime as dt

expire = dt.datetime.now() + dt.timedelta(delta)

timestamp = int(expire.timestamp())

'time_expires': expiration_time(7),


'time_expires': int(datetime(2024, 2, 28, 13, 30, 0).timestamp()),


Any ideia what´s wrong? Is it something related to the structure of the request? Or the format of the time expired field? The reason why I am asking it is because my orders are being cancelled by MT5 automatically. I was checking some possible reasons and workarounds and I saw something about setting an expiration. I am trying to test it, but with no success.

Thanks in advance!

 
I was able to send the order... The final request:

    request = {
        'action': mt5.TRADE_ACTION_PENDING,
        'symbol': [stock symbol],
        'price': [price],
        'sl': [stop loss value],
        'tp': [take profit value],
        'type': mt5.ORDER_TYPE_BUY_LIMIT,
        'volume': [total volume],
        'type_time': mt5.ORDER_TIME_SPECIFIED_DAY,
        'expiration': int((datetime.now(timezone.utc) + timedelta(days=7)).timestamp()),
        'type_filling': mt5.ORDER_FILLING_IOC,
        'comment': 'comment xxx'
        }

But all orders, as soon as they reach MT5, they are automatically canceled. I talked with the broker company and they are saying that they are not cancelling it. It is the app MT5 that is cancelling. Any idea if it is being cancelled by some wrong or missing parameter?