# Channel

> A joined WebSocket channel and the messages it delivers.

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

{/* Generated from the TypeScript source by tools/gen-reference.mjs. Do not edit by hand. */}

## `Channel`

One joined topic.

### Properties

| Property | Type | Description |
|---|---|---|
| `closed` | `boolean` |  |
| `joined` | `boolean` |  |
| `joinPayload` | `Record<string, unknown>` | What the next (re)join sends; updated by the `select*` and `watch` helpers so a reconnect keeps them. |
| `joinRef` | `string \| null` |  |
| `name` | `string` | The topic without the user id, e.g. `orders`. |
| `onMessage` | `MessageHandler \| undefined` |  |
| `pingIntervalMs` | `number \| null` |  |
| `reply` | `Record<string, any>` | The `response` object from the latest join reply, e.g. `{selected_market_ids: null}`. |
| `snapshots` | `Record<string, any>` | The latest snapshot payload per snapshot event name. |
| `topic` | `string` | The wire topic, e.g. `orders:<user_id>`. |
| `watches` | `string[]` | Market ids watched on `market_updates`; re-sent after a reconnect. |

### Methods

#### `[asyncIterator]()`

{/* sdk:Channel.[asyncIterator] */}

```ts
[asyncIterator](): AsyncIterator<ChannelMessage>
```

Returns `AsyncIterator<ChannelMessage>`.

#### `leave()`

```ts
leave(): Promise<void>
```

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

Returns `Promise<void>`.

#### `next()`

```ts
next(timeoutMs?: number | null): Promise<ChannelMessage>
```

The next message on this channel. Rejects with `STXChannelException` if
none arrives within `timeoutMs` or the channel closes.

| Parameter | Type | Description |
|---|---|---|
| `timeoutMs` (optional) | `number \| null` |  |

Returns `Promise<ChannelMessage>`.

#### `ping()`

```ts
ping(): Promise<any>
```

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

Returns `Promise<any>`.

#### `push()`

```ts
push(event: string, payload?: unknown, timeoutMs?: number): Promise<any>
```

Send `event` on this channel and resolve to the reply's `response`. Rejects when the reply status is `error`.

| Parameter | Type | Description |
|---|---|---|
| `event` | `string` |  |
| `payload` (optional) | `unknown` |  |
| `timeoutMs` (optional) | `number` |  |

Returns `Promise<any>`.

#### `requestSeries()`

```ts
requestSeries(marketIds: readonly string[], range?: string): Promise<any>
```

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

| Parameter | Type | Description |
|---|---|---|
| `marketIds` | `readonly string[]` |  |
| `range` (optional) | `string` |  |

Returns `Promise<any>`.

#### `requestSnapshot()`

```ts
requestSnapshot(): Promise<any>
```

`market:<id>`: push the market's current `market_update` and
`order_book_update` again now (after a gap, or to re-read a field).

Returns `Promise<any>`.

#### `selectFilters()`

```ts
selectFilters(filters: Record<string, readonly string[] | null>): Promise<any>
```

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

| Parameter | Type | Description |
|---|---|---|
| `filters` | `Record<string, readonly string[] \| null>` |  |

Returns `Promise<any>`.

#### `selectMarketIds()`

```ts
selectMarketIds(marketIds: readonly string[] | null): Promise<any>
```

Change the `market_ids` filter without rejoining. On `orders`, `fills`,
`positions`, `settlements` and `account`, `null` clears the filter;
`orderbook` and `market_stats` require at least one id.

| Parameter | Type | Description |
|---|---|---|
| `marketIds` | `readonly string[] \| null` |  |

Returns `Promise<any>`.

#### `selectMessageTypes()`

```ts
selectMessageTypes(messageTypes: readonly string[] | null): Promise<any>
```

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

| Parameter | Type | Description |
|---|---|---|
| `messageTypes` | `readonly string[] \| null` |  |

Returns `Promise<any>`.

#### `selectRuleFilters()`

```ts
selectRuleFilters(ruleFilters: readonly string[] | null): Promise<any>
```

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

| Parameter | Type | Description |
|---|---|---|
| `ruleFilters` | `readonly string[] \| null` |  |

Returns `Promise<any>`.

#### `waitSnapshot()`

```ts
waitSnapshot(timeoutMs?: number | null): Promise<Record<string, 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` and `market:<id>` return the join reply, which
carries the series or the whole market. Channels with no snapshot (`settlements`, `ticker`, `trades`,
`orderbook`, `markets`, `market_updates`) throw.

| Parameter | Type | Description |
|---|---|---|
| `timeoutMs` (optional) | `number \| null` |  |

Returns `Promise<Record<string, any>>`.

#### `watch()`

```ts
watch(marketIds: readonly string[]): Promise<any>
```

`market_updates`: start receiving `created`/`updated` for these markets.
Re-sent automatically after a reconnect.

| Parameter | Type | Description |
|---|---|---|
| `marketIds` | `readonly string[]` |  |

Returns `Promise<any>`.

## `ChannelMessage`

One pushed frame.

### Properties

| Property | Type | Description |
|---|---|---|
| `event` | `string` |  |
| `joinRef` | `string \| null` |  |
| `payload` | `any` | The event's JSON as documented for the channel; money and quantities are strings. |
| `ref` | `string \| null` |  |
| `topic` | `string` | The wire topic, e.g. `orders:<user_id>`. |
| `channel` | `string` | The topic without the user id: `"orders"` for `orders:<user_id>`. |
| `isSnapshot` | `boolean` | True for the state-on-join events (`all_orders`, `balances`, ...). |
