How to Square off or Exit order?

I wanted to know how to Square off/ Exit trade

In cancel order i get this error in postman
{"status":"error","errors":[{"errorCode":"UDAPI100040","message":"Cancel of already cancelled/rejected/completed order is not allowed","propertyPath":null,"invalidValue":null,"error_code":"UDAPI100040","property_path":null,"invalid_value":null}]

There is no particular method for executing a square-off order. To square off an order, you must use the same method Place Order originally used for placing the order.

To perform the square-off, you need to modify the transaction_type parameter based on the type of your initial leg. The square-off transaction_type will be the opposite of the order type that was initially placed.

Cancel order can be used to cancel orders currently in an open or pending status.