# Channel

> A joined WebSocket channel and the messages it delivers.

Source: https://docs.stxapp.io/sdks/python/reference/channel/

{/* Generated from the Python source by tools/gen_reference.py. Do not edit by hand. */}

## `Channel`

One joined topic.

### Attributes

| Attribute | Type | Description |
|---|---|---|
| `reply` | `Dict[str, Any]` |  |
| `snapshots` | `Dict[str, Any]` |  |
| `watches` | `List[str]` |  |
| `join_ref` | `Optional[str]` |  |

### Methods

#### `leave()`

```python
leave() -> None
```

Leave the topic. The channel stops receiving and its iterator ends.

#### `next()`

```python
next(timeout: Optional[float] = None) -> ChannelMessage
```

The next message on this channel. Raises `asyncio.TimeoutError`.

| Parameter | Type | Description |
|---|---|---|
| `timeout` | `Optional[float]` |  |

#### `ping()`

```python
ping() -> Any
```

Channel `ping`. On `orders` with cancel-on-disconnect armed this
resets the cancel deadline; on `account` and `orders` it keeps the
session alive.

#### `push()`

```python
push(event: str, payload: Any = None, timeout: Optional[float] = None) -> Any
```

Send `event` on this channel and return the reply's `response`.

Raises `STXChannelException` when the reply status is `error`.

| Parameter | Type | Description |
|---|---|---|
| `event` | `str` |  |
| `payload` | `Any` |  |
| `timeout` | `Optional[float]` |  |

#### `request_series()`

```python
request_series(market_ids: Sequence[str], range: str = 'all') -> Any
```

`market_stats`: fetch history at `range` (`day`, `week`,
`month`, `all`) without changing the subscription.

| Parameter | Type | Description |
|---|---|---|
| `market_ids` | `Sequence[str]` |  |
| `range` | `str` |  |

#### `select_filters()`

```python
select_filters(**filters: Optional[Sequence[str]]) -> Any
```

`ticker` (`sports`, `competitions`) and `trades`
(`market_ids`, `event_ids`): change filters without rejoining.

| Parameter | Type | Description |
|---|---|---|
| `filters` | `Optional[Sequence[str]]` |  |

#### `select_market_ids()`

```python
select_market_ids(market_ids: Optional[Sequence[str]]) -> Any
```

Change the `market_ids` filter without rejoining.

On `orders`, `fills`, `positions`, `settlements` and
`account` `None` clears the filter; `orderbook` and
`market_stats` require at least one id. Returns the reply, whose
`selected_market_ids` is what the server applied.

| Parameter | Type | Description |
|---|---|---|
| `market_ids` | `Optional[Sequence[str]]` |  |

#### `select_message_types()`

```python
select_message_types(message_types: Optional[Sequence[str]]) -> Any
```

`markets`: receive `market_created`, `market_updated` or both.

| Parameter | Type | Description |
|---|---|---|
| `message_types` | `Optional[Sequence[str]]` |  |

#### `select_rule_filters()`

```python
select_rule_filters(rule_filters: Optional[Sequence[str]]) -> Any
```

`markets`: change the `rules` filter; `None` disables it.

| Parameter | Type | Description |
|---|---|---|
| `rule_filters` | `Optional[Sequence[str]]` |  |

#### `wait_snapshot()`

```python
wait_snapshot(timeout: Optional[float] = 10.0) -> Dict[str, Any]
```

Wait for the state-on-join and return it as `{event: payload}`.

`orders` gives `{"all_orders": {...}}`; `account` waits for all
four of its snapshots. `market_stats` returns the join reply, which
carries the series. Channels with no snapshot (`settlements`,
`ticker`, `trades`, `orderbook`, `markets`,
`market_updates`) raise `ValueError`.

| Parameter | Type | Description |
|---|---|---|
| `timeout` | `Optional[float]` |  |

#### `watch()`

```python
watch(market_ids: Sequence[str]) -> Any
```

`market_updates`: start receiving `created`/`updated` for
these markets. Re-sent automatically after a reconnect. Returns the
reply, whose `subscriptions.watches` lists what is watched.

| Parameter | Type | Description |
|---|---|---|
| `market_ids` | `Sequence[str]` |  |

## `ChannelMessage`

One pushed frame.

`payload` is the event's JSON object as documented for the channel,
with money and quantities as strings. `channel` is the topic without
the user id (`"orders"` for `orders:<user_id>`).

### Attributes

| Attribute | Type | Description |
|---|---|---|
| `topic` | `str` |  |
| `event` | `str` |  |
| `payload` | `Any` |  |
| `ref` | `Optional[str]` |  |
| `join_ref` | `Optional[str]` |  |
| `channel` | `str` |  |
| `is_snapshot` | `bool` | `True` for the state-on-join events (`all_orders`, `balances`...). |
