from functools import cmp_to_key


def sorted_orders_by_exec_priority(orders):
    """Sorts orders by decreasing xrate, breaking ties with larger orders first,
    breaking ties with order id.
    """
    def order_cmp(o1, o2):
        if o1.max_xrate != o2.max_xrate:
            return o2.max_xrate - o1.max_xrate
        if o1.max_sell_amount != o2.max_sell_amount:
            return o2.max_sell_amount - o1.max_sell_amount
        return -1 if o1.id < o2.id else 1

    return sorted(orders, key=cmp_to_key(order_cmp))