# STXWebSocket

> One signed socket for every channel: options and join methods.

Source: https://docs.stxapp.io/sdks/csharp/reference/stx-websocket/

```csharp
public sealed class STXWebSocket : IAsyncDisposable
var ws = client.CreateWebSocket(new STXWebSocketOptions { ... });
```

## STXWebSocketOptions

| Property | Default | Meaning |
|---|---|---|
| `UserId` | from `GET /api/v1/me` | The id the account channels are keyed by |
| `HeartbeatInterval` | 25 s | Socket heartbeat; the server closes a socket silent for 60 s |
| `ChannelPingInterval` | 30 s | Channel `ping` on every joined topic; null turns it off |
| `Reconnect` | `true` | Reconnect after a drop |
| `ReconnectPolicy` | 0.5 s doubling to 30 s, jitter, never gives up | `STXReconnectPolicy` record: `InitialBackoff`, `MaxBackoff`, `MaxAttempts`, `Jitter` |
| `OnReconnect` | none | `Func<Task>` called after each reconnect and rejoin |
| `JoinTimeout` | 10 s | Time to wait for a join or command reply |
| `QueueSize` | 10,000 | Messages buffered per channel for reading; the oldest is dropped when full |

## Members

| Member | Meaning |
|---|---|
| `ConnectAsync()` | Opens the socket; joining connects too |
| `DisposeAsync()` | Leaves every channel and closes the socket |
| `Completion` | Completes when the socket is closed or gives up reconnecting |
| `Connected`, `Reconnects` | State |
| `Channels` | Joined channels by topic |
| `GetUserIdAsync()` | Your user id |

## Join methods

Each returns the joined channel and takes an optional `Action<STXChannelMessage> onMessage` and `CancellationToken ct`.

| Method | Topic | On join |
|---|---|---|
| `OrderbookAsync(marketIds)` | `orderbook` | `book` pushes, each a full book |
| `TickerAsync(sports, competitions)` | `ticker` | no snapshot |
| `TradesAsync(marketIds, eventIds)` | `trades` | no snapshot |
| `MarketsAsync(ruleFilters, messageTypes)` | `markets` | no snapshot; cents converted to dollars |
| `MarketStatsAsync(marketIds, range)` | `market_stats` | the series in `Reply` |
| `MarketUpdatesAsync(watch)` | `market_updates` | nothing until you watch |
| `MarketAsync(marketId)` | `market:<id>` | the market and its book in `Reply` |
| `OrdersAsync(marketIds, cancelOnDisconnect, pingTimeout)` | `orders:<user_id>` | `all_orders` |
| `FillsAsync(marketIds)` | `fills:<user_id>` | `all_trades` |
| `PositionsAsync(marketIds)` | `positions:<user_id>` | `all_positions` |
| `SettlementsAsync(marketIds)` | `settlements:<user_id>` | no snapshot |
| `BalancesAsync(accountId)` | `balances:<user_id>` | `balances` |
| `AccountAsync(marketIds)` | `account:<user_id>` | all four snapshots |
| `UserInfoAsync()` | `user_info:<user_id>` | `user_updated` |
| `AccountViewAsync(marketIds, accountId, onChange, snapshotTimeout, keepFlatPositions, maxFills)` | four channels | returns an [`STXAccountView`](/sdks/csharp/reference/account-view/) |
| `RfqAsync()` | `rfq:<user_id>` | returns an `STXRfqChannel`; see [Combos](/sdks/csharp/reference/combos/) |
| `ComboQuoteAsync()` | `combo_quote:<user_id>` | returns an `STXComboQuoteChannel` |
| `JoinAsync(topic, payload)` | any | |

A topic can be joined once per socket; joining it again throws `STXChannelException`.
