def cancel_all(self): """Cancels all pending orders regardless of symbol and order type""" while mt5.orders_get(): pos = mt5.orders_get()[ 0] # FIXME Again check if this can be done better without [0] position_id = mt5.TradeOrder(pos).ticket request = { "action": mt5.TRADE_ACTION_REMOVE, "order": position_id, "magic": self.magic } result = mt5.order_send(request) return "No Pending Orders"
def modify_order(self, ticket, open_price): """Modifies a currently pending order""" mt5.initialize() order = mt5.orders_get(ticket=ticket)[0] symbol = mt5.TradeOrder(order).symbol request = { "action": mt5.TRADE_ACTION_MODIFY, "order": ticket, "price": open_price, "sl": self.StopLoss.sl, "tp": self.TakeProfit.tp, "type_time": mt5.ORDER_TIME_GTC, "magic": self.magic, "comment": f"python modify {symbol}" } result = mt5.order_send(request)