def cancel_order(self, ClOrdId): # TODO implement if logging.getLevelName('DEBUG') > 1: logging.debug( f'ROFEXClient: Sending cancel message for order {ClOrdId}') try: cancel_order = pyRofex.cancel_order(ClOrdId) lk.acquire() print(dash_line) print(f"----------- Cancel Order Response: ".ljust(width, '-')) pprint(cancel_order) lk.release() order_status = pyRofex.get_order_status(ClOrdId) lk.acquire() print(dash_line) print(f"----------- Cancel Order Status Response: ".ljust( width, '-')) pprint(order_status) lk.release() except Exception as e: if logging.getLevelName('DEBUG') > 1: logging.debug(f'ROFEXClient ERROR: En exception occurred {e}') error_msg = "\033[0;30;47mERROR: Check log file for detailed error message.\033[1;37;40m" print(error_msg) print(dash_line)
def _cancel_if_orders(self): if self.my_order: self.state = States.WAITING_CANCEL for order in self.my_order.values(): pyRofex.cancel_order(order["orderReport"]["clOrdId"]) print("canceling order %s" % order["orderReport"]["clOrdId"])
# 5-If order status is PENDING_NEW then we keep checking the status until # the market accept or reject the order or timeout is reach timeout = 5 # Time out 5 seconds while order_status["order"]["status"] == "PENDING_NEW" and timeout > 0: time.sleep(1) order_status = pyRofex.get_order_status(order["order"]["clientId"]) # Print Order Status print("Recheck Order Status Response: {0}".format(order_status)) timeout = timeout - 1 # 6-If the status is NEW, cancel the order if order_status["order"]["status"] == "NEW": # Cancel Order cancel_order = pyRofex.cancel_order(order["order"]["clientId"]) # Print the response print("Cancel Order Response: {0}".format(cancel_order)) # Check cancel order status cancel_order_status = pyRofex.get_order_status( cancel_order["order"]["clientId"]) print("Cancel Order Status Response: {0}".format(cancel_order_status)) # Check original order status original_order_status = pyRofex.get_order_status( order["order"]["clientId"]) print("Original Order Status Response: {0}".format(original_order_status))