Removing a pending order (metatrader for PYTHON)

 

I'm trying to remove a previously placed pending order using the below python script but for an unknown reason it returns retcode 10013 which translates to "invalid request"...

import time
import MetaTrader5 as mt5

if not mt5.initialize():
    print("initialize() failed, error code =",mt5.last_error())
    quit()


symbol = "EURUSD"
price = 1.22340  
point = mt5.symbol_info(symbol).point
request = {
    "action": mt5.TRADE_ACTION_PENDING,   
    "symbol": symbol,
    "volume": 10.00,
    "type": mt5.ORDER_TYPE_BUY_STOP,    
    "price": price,
    "sl": price - 200 * point,
    "tp": price + 200 * point,
    "deviation": 0,
    "comment": "python script open",
    "type_time": mt5.ORDER_TIME_GTC,          
    "type_filling": mt5.ORDER_FILLING_RETURN, 
    }

result = mt5.order_send(request)

if mt5.order_check(request) is None:
    print ("error raised: ", mt5.last_error())
    quit()
        
if result.retcode != mt5.TRADE_RETCODE_DONE:
    print ("order_send open failed, retcode: {}".format(result.retcode))
else:
    print ("order_send open DONE!")

    
time.sleep(3)
position_id = result.order
request1={
    "position": position_id,
    "action": mt5.TRADE_ACTION_REMOVE,   
    }
print (mt5.order_check(request1))
mt5.order_send(request1)

mt5.shutdown()
any suggestions would be very appreciated, thank you.
 
Trex pro:

I'm trying to remove a previously placed pending order using the below python script but for an unknown reason it returns retcode 10013 which translates to "invalid request"...

any suggestions would be very appreciated, thank you.
https://www.mql5.com/en/docs/constants/structures/mqltraderequest

You are setting a value for position. As you are trying to close an order.
 
La_patates:
https://www.mql5.com/en/docs/constants/structures/mqltraderequest

You are setting a value for position. As you are trying to close an order.
thank you very much my friend, your comment helped now the problem is solved. 
 

Trex pro:
thank you very much my friend, your comment helped now the problem is solved. 


How did you solve this. l ran into the same issue as well

 
replace 
"position": position_id

on request 1 with 

"order": your_ticket_id
 
Sir_Niac #:
replace 

on request 1 with 

Hello, I've done it (replace position for order in request), I get retcode = 0, but the pending order stays on MT5. Can you help me?

Thanks!

Reason: