To square off, you must execute an order for the second leg. If your initial action is a purchase, then your square-off should be a sell order, and the reverse applies if you start with a sell. After consulting the position API for all the necessary details to place the second leg order, you should be all set.