Managing orders and closing positions
Replace or cancel one order, pull every order in a market with mass cancel, and cancel everything automatically with the dead-man switch.
On this page
Replacing or cancelling an order never closes a position; to close one, see Closing positions below. To stop a TWAP, see Cancel a TWAP.
Any key bound to the account can cancel its orders. While your margin is being liquidated, cancel, replace and mass cancel on it are rejected; the liquidation has already cancelled those orders.
Replace
A replace swaps a resting order for a new one in one step, never leaving a moment with no order or both live. See Trading API.
The new order gets a new ID and goes to the back of the queue. You can change price, quantity, post-only and reduce-only. It is a GTC limit, checked like a new order, and can trade at once; a Reduce Only key must keep it reduce-only. If anything fails, nothing changes. An attached TP/SL follows it.
Cancel
A cancel pulls one live order by order ID or client order ID; cancelling a filled, cancelled or another account's order is rejected (see Trading API). Cancel then place can briefly leave no quote or both orders live; a replace avoids this.
Mass cancel
Mass cancel pulls every resting order of an account in one market, whichever key placed it, including fired TP or SL exits and unfilled entries with their TP/SL; positions and active TP and SL stay. No daily cap beyond the rate limits (see Trading API). Each lands on its own, so an order in another market can fill meanwhile. It doesn't stop a running TWAP, and is a first step if a key leaks.
Dead-man switch
The dead-man switch cancels an account's resting orders if your program goes quiet: keep posting a timeout, and if none arrives in time, ATLAS cancels them and turns the switch off. There is no separate cancel-on-disconnect.
| Setting | Rule |
|---|---|
| Timeout | 5 to 86,400 seconds. 0 turns it off. Any other value is rejected |
| Suggested | A 60-second timeout, posted every 15 to 20 seconds |
| Cancels | Every resting order on the account, as mass cancel does, in every market |
Each post arms the switch or restarts its countdown. The cancel runs shortly after the deadline; in that gap orders can still fill and a post is rejected.
- All keys on an account share one clock, so one live program keeps another's orders alive; use a sub-account per process for separate clocks.
- A Reduce Only key can arm or refresh it, never with a longer timeout, but not turn it off.
- After it fires, new orders are unprotected: re-arm it before you quote again.
- Mass cancel, a close or going flat don't turn it off.
Closing positions
A close is a Market or Limit order with reduce-only on, on the side that reduces your position. You choose the quantity, a Limit price, and GTC or IOC; FOK is rejected.
- A close larger than your position is cut to your live position, if within the market's maximum order size (and, for Market, value).
- A close covers one position. There is no close-all or flip instruction: to reverse, close, then after a short gap order the other side.
How a close works
- A resting Limit close isn't resized later and can still flip you (see What reduce-only doesn't do).
- A full close skips the minimum order value.
- Older resting orders on that side then shrink or are cancelled, oldest first (see Your older orders make room).
- A close can't fill past your bankruptcy price: a Market close is capped there, and a Limit close priced past it is rejected.
- Orders that would add to the position stay on the book: a resting buy on a long can still fill after you close and open a new position. Pull such orders with mass cancel.
Your take profit and stop loss
A partial close keeps your TP and SL, which close the rest when they fire. A full close cancels any unfired side. If a close and a stop loss land together, each is capped at the position left, and the second is rejected if the first flattens you.
Close all positions
A front end's Close all sends one Market IOC close per position, in its margin mode, optionally after a mass cancel. Some can fill in part or be rejected, and prices move between them, so check your positions again. Main and each sub-account are closed separately.