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

# Cancel on Disconnect

> Automatically cancel a wallet's resting orders when its WebSocket connection drops.

Cancel-on-disconnect (COD) automatically cancels a wallet's resting orders,
quotes, and trigger orders when its connection drops — protecting you from stale
orders resting on the book after a network failure. On graceful server shutdown,
COD-enabled connections are cancelled as well.

COD is a **persisted account setting**, not a per-frame flag. Enable or disable
it with `private/set_cancel_on_disconnect`:

<CodeGroup>
  ```typescript TypeScript (SDK) theme={null}
  import { DeriveClient } from '@derivexyz/derive-ts';

  const client = new DeriveClient({
    network: 'mainnet',
    wallet: process.env.PRIVATE_KEY!,
  });
  await client.connect();
  await client.login();

  // Persisted account setting; requires the Trade(All) scope on the session key.
  const result = await client.send('private/set_cancel_on_disconnect', {
    enabled: true,
  });
  console.log(result); // "ok"
  ```

  ```python Python (SDK) theme={null}
  # Coming soon.
  ```

  ```rust Rust (SDK) theme={null}
  // Coming soon.
  ```

  ```bash cURL theme={null}
  # Session auth: TS is the current time in ms; SIG is personal_sign(TS) by the wallet.
  curl -X POST https://api.derive.xyz/v3/private/set_cancel_on_disconnect \
    -H "Content-Type: application/json" \
    -H "X-DeriveWallet: $WALLET_ADDRESS" \
    -H "X-DeriveTimestamp: $TS" \
    -H "X-DeriveSignature: $SIG" \
    -d '{ "enabled": true }'
  ```

  ```json Request theme={null}
  {
    "id": 2,
    "method": "private/set_cancel_on_disconnect",
    "params": { "enabled": true }
  }
  ```

  ```json Response theme={null}
  {
    "id": 2,
    "result": "ok"
  }
  ```
</CodeGroup>

* The setting is stored against the wallet's account settings and **applied to
  every new connection at login** — so once enabled it persists across
  reconnects until you disable it.
* Calling `private/set_cancel_on_disconnect` requires the `Trade(All)` protocol
  scope on the signing session key (see [Authentication](/authentication/session-login)). A
  read-only JWT session cannot toggle it.
* The current value is reported on your account (`cancel_on_disconnect`) via the
  account read methods.

<Info>
  In v2 this was a family of `enable`/`disable`/`set` RPCs. In v3 there is a
  single `private/set_cancel_on_disconnect` method taking an `enabled` boolean,
  gated by the `Trade(All)` scope. If your integration references the older
  method names, migrate to this one.
</Info>


## Related topics

- [Connecting over WebSocket](/connecting.md)
- [Market Maker Protection](/trading/market-maker-protection.md)
- [Enable or disable cancel on disconnect](/api-reference/methods/enable-or-disable-cancel-on-disconnect.md)
