> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tplus.cx/llms.txt
> Use this file to discover all available pages before exploring further.

# Bot safe stop

> Stop creating risk, cancel open orders, reconnect streams, and reconcile state.

A safe stop is a client-side workflow: cancel open orders, then stop submitting new creates and replaces. There is no server-side account cancel-only or trading-halt mode. The only cancel-only-style flag in order flow is per-order `reduce_only`, which constrains exposure but does not halt an account.

## Raw workflow

1. Stop local create and replace producers.
2. Record a cutoff `max_ts`.
3. Send cancel-all with that cutoff.
4. Keep the order-control or orders WebSocket open until terminal events arrive.
5. Re-fetch complete account state and reconcile.

```bash theme={null}
curl -X DELETE "https://oms.tplus.cx/orders/cancel-all?max_ts=$STOP_TS_NS" \
  -H "Authorization: Bearer $TOKEN" \
  -H "User-Id: $USER_ID"
```

In-flight creates or replaces that were already accepted before `max_ts` can still race with the cancel. Watch the orders stream and refetch:

```bash theme={null}
curl -H "Authorization: Bearer $TOKEN" -H "User-Id: $USER_ID" \
  "https://oms.tplus.cx/orders/user/$USER_ID?page=0&limit=100"

curl -H "Authorization: Bearer $TOKEN" -H "User-Id: $USER_ID" \
  "https://oms.tplus.cx/inventory/user/$USER_ID"
```

## tpluspy

```python theme={null}
import time

stop_ts = time.time_ns()
disable_strategy_writes()

await client._request("DELETE", "/orders/cancel-all", params={"max_ts": stop_ts})

open_orders, raw_orders = await client.get_user_orders()
inventory = await client.get_user_inventory()
margin = await client.get_user_margin_info(include_positions=True)
```

If using `OrderBookClient(use_ws_control=True)`, send create, replace, and cancel through the same `/control` channel so responses carry the same connection context. On reconnect, do not resume from memory: fetch open orders, positions, inventory, margin, and recent user trades before restarting quoting.

The `/control` channel also accepts `CancelAllOrdersRequest`, `CancelAllOrdersForAssetRequest`, and `BatchCancelRequest` raw messages, or v1 envelopes with `request_id`. Bulk cancel messages are acknowledged as submitted; reconcile individual order state through the orders stream and REST snapshots.

## Reconciliation checklist

| Surface                     | Use                                               |
| --------------------------- | ------------------------------------------------- |
| `/orders/user/{user_id}`    | Remaining open or in-flight orders                |
| `/trades/user/{user_id}`    | Recent confirmed fills                            |
| `/positions/{user_id}`      | Open margin positions                             |
| `/inventory/user/{user_id}` | Spot and margin balances                          |
| `/margin/user/{user_id}`    | IM/MM state after stop                            |
| `/account/events/{user_id}` | Deposits, withdrawals, transfers, position clears |

For market makers on sync books, also watch `/sync/pending_settlements`; a stopped quoting loop can still have settlement obligations for fills that already happened.
