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

# Subscriptions

> Subscribe to channels with ids and filters.

A subscription is `{ id, channel, confirmed?, filters? }`. The `id` is your own string. The server sends it back on every event, so you can tell your subscriptions apart. `channel` is a channel name. `confirmed` defaults to `true` (the final on-chain feed); set it to `false` for the pending (mempool) feed of the same channel. `filters` are optional and run on the server.

<CodeGroup>
  ```typescript TypeScript theme={null}
  radion.realtime.subscribe({ id: "trading", channel: "trading" });

  radion.realtime.subscribe({
    id: "whales",
    channel: "trading",
    filters: { min_usd: 10_000 },
  });

  radion.realtime.unsubscribe("whales");
  ```

  ```python Python theme={null}
  from radion import ChannelFilters, Subscription

  await radion.realtime.subscribe(Subscription(id="trading", channel="trading"))

  await radion.realtime.subscribe(
      Subscription(id="whales", channel="trading", filters=ChannelFilters(min_usd=10_000))
  )

  await radion.realtime.unsubscribe("whales")
  ```

  ```rust Rust theme={null}
  use radion_sdk::realtime::{Channel, ChannelFilters, Subscription};

  let _trading = radion
      .realtime
      .subscribe(Subscription::new("trading", Channel::Trading))
      .await?;

  let _whales = radion
      .realtime
      .subscribe(Subscription::new("whales", Channel::Trading).with_filters(
          ChannelFilters { min_usd: Some(10_000.0), ..Default::default() },
      ))
      .await?;

  radion.realtime.unsubscribe("whales").await?;
  ```
</CodeGroup>

If you subscribe again with an `id` you already use, the new subscription replaces the old one on that id. To stop, unsubscribe with the same `id`.

## Filters

`ChannelFilters` narrows a channel on the server:

| Filter       | Type       | Used by                                                                                                    |
| ------------ | ---------- | ---------------------------------------------------------------------------------------------------------- |
| `wallets`    | `string[]` | `wallets` (required); `trading`, `fees`, `positions`, `combos`, `transfers`, `accounts`                    |
| `market_ids` | `string[]` | `markets` (one of market/token ids); `trading`, `oracle`, `resolution`, `lifecycle`, `positions`, `combos` |
| `token_ids`  | `string[]` | `markets`; `trading`, `fees`, `lifecycle`, `positions`, `combos`, `transfers`                              |
| `min_usd`    | `number`   | `trading`                                                                                                  |

<Note>
  Only the two filter channels need a filter. `wallets` needs `wallets`.
  `markets` needs at least one of `market_ids` / `token_ids`. If you subscribe
  to either without its filter, you get an [error](/sdks/realtime/errors). On
  topic channels, filters are optional — an empty filter means the whole
  channel.
</Note>

## Pending feed

Set `confirmed: false` on a subscription to get pending transactions before they land in a block. These are not final yet. Every event carries a `confirmed` flag, so you route on that (and tell subscriptions apart by `id`):

<CodeGroup>
  ```typescript TypeScript theme={null}
  radion.realtime.subscribe({
    id: "pending",
    channel: "trading",
    confirmed: false,
  });
  radion.realtime.subscribe({ id: "confirmed", channel: "trading" });

  radion.realtime.onAnyChannel((e) => {
    if (!e.confirmed) {
      // pending
    }
  });
  ```

  ```python Python theme={null}
  await radion.realtime.subscribe(Subscription(id="pending", channel="trading", confirmed=False))
  await radion.realtime.subscribe(Subscription(id="confirmed", channel="trading"))

  @radion.realtime.on_any_channel()
  async def on_any(e):
      if not e.confirmed:
          ...  # pending
  ```

  ```rust Rust theme={null}
  use futures_util::StreamExt;
  use radion_sdk::realtime::{Channel, Subscription};

  radion
      .realtime
      .subscribe(Subscription::new("pending", Channel::Trading).pending())
      .await?;
  radion
      .realtime
      .subscribe(Subscription::new("confirmed", Channel::Trading))
      .await?;

  let mut events = radion.realtime.events();
  while let Some(e) = events.next().await {
      if !e.confirmed {
          // pending
      }
  }
  ```
</CodeGroup>

See the [WebSockets filters](/websockets/filters) and [mempool](/websockets/mempool) references for how this works under the hood.
