How to close Pending orders in Mt5 with python

 

Hello,


I would like to close all pending orders in same time.

i tried with open positions and succeeded but dont now how to do with open pending orders.

this is my code for open positions:


    
    num_positions=mt.positions_total()
    symbol_info=mt.symbol_info("EURUSD")
    symbol="EURUSD"
    volume=0.1
    positions=mt.positions_get()
    m=(5,6,7)
    x=mt.symbol_info_tick("EURUSD").ask
    z=mt.symbol_info_tick("EURUSD").bid 

       


    if num_positions in m :
        def  close_position_sell(position):
            tick=mt.symbol_info_tick(position.symbol)  
            request={ 
                "action": mt.TRADE_ACTION_DEAL, 
                "symbol":position.symbol, 
                "volume":position.volume,
                "type":mt.ORDER_TYPE_SELL,    
                "position":position.ticket,       
                "price":mt.symbol_info_tick("EURUSD").bid,
                "deviation":0,
                "comment": "python script close",
                "type_time": mt.ORDER_TIME_GTC,
                "Type_filling":mt.ORDER_FILLING_IOC,
            }

            result=mt.order_send(request)
            return result

        for position in positions:
            close_position_sell(position)



    if num_positions in m :
        def  close_position_sell(position):
            tick=mt.symbol_info_tick(position.symbol)  
            request={ 
                "action": mt.TRADE_ACTION_DEAL, 
                "symbol":position.symbol, 
                "volume":position.volume,
                "type":mt.ORDER_TYPE_BUY,    
                "position":position.ticket,       
                "price":mt.symbol_info_tick("EURUSD").ask,
                "deviation":0,
                "comment": "python script close",
                "type_time": mt.ORDER_TIME_GTC,
                "Type_filling":mt.ORDER_FILLING_IOC,
            }

            result=mt.order_send(request)
            return result

        for position in positions:
            close_position_sell(position)
Reason: