Available languages: [Python](https://databento.com/docs/api-live/client-control-messages/unsubscribe-request.python.md) · [C++](https://databento.com/docs/api-live/client-control-messages/unsubscribe-request.cpp.md) · [Rust](https://databento.com/docs/api-live/client-control-messages/unsubscribe-request.rust.md) · [Raw](https://databento.com/docs/api-live/client-control-messages/unsubscribe-request.raw.md)

Source: https://databento.com/docs/api-live/client-control-messages/unsubscribe-request


### Unsubscribe request

Remove the specified symbols from the session's subscriptions for a schema.

The symbols don't need to match an earlier [subscription request](https://databento.com/docs/api-live/client-control-messages/subscription-request.md): any subset of the subscribed symbols can be removed, and `ALL_SYMBOLS` removes every symbol for the schema.
An unsubscribe request can be sent before or after the session is [started](https://databento.com/docs/api-live/client-control-messages/session-start.md).

The gateway acknowledges the request with a [system message](https://databento.com/docs/api-live/basics/system-messages.md) with `code=UNSUBSCRIBE_ACK`.
Symbols that aren't subscribed, or that can't be removed with the given `stype_in`, are left in place and reported in an [`ErrorMsg`](https://databento.com/docs/api-live/basics/errors.md).
If there's no subscription for the schema or `stype_in` isn't supported, the gateway sends an `ErrorMsg` with `code=InvalidSubscription`.
None of these errors end the session.

The unsubscribe's `stype_in` must be compatible with the subscription's `stype_in`.

| Subscribed with | Can unsubscribe with |
| `raw_symbol`, `instrument_id`, or `continuous` | `raw_symbol` or `instrument_id` |
| `parent` | `parent` |

To remove a continuous symbol, unsubscribe the raw symbol or instrument ID that it resolved to at subscription time.

As with subscription requests, the symbols can be split across multiple control messages.
All but the last message should include `is_last=0`.

#### Example message

```text
unsubscribe|schema=trades|stype_in=raw_symbol|symbols=SPY,QQQ\n
```

#### Fields

| Field | Required | Type | Description |
| `unsubscribe` | required |  | Identifies the message as an unsubscribe request. Must be the first field. A value can be given, such as `unsubscribe=0`, but it's ignored. |
| `schema` | required | string | The data record [schema](https://databento.com/docs/schemas/whats-a-schema.md) to unsubscribe from. |
| `stype_in` | required | string | The [symbology type](https://databento.com/docs/api-historical/basics/symbology.md) of input `symbols`. Must be one of `raw_symbol`, `parent`, or `instrument_id`. |
| `symbols` | required | string | A comma-separated list of symbols to unsubscribe from. Setting this value to `ALL_SYMBOLS` will remove every symbol for the schema. |
| `is_last` | optional | int8_t | `0` indicates more requests will be sent with the same parameters other than `symbols` and the gateway should wait to process the request. `is_last=1` is the default and instructs the gateway to process the request immediately. |
