# AccountView

> The live view of your balance, open orders, fills and positions.

Source: https://docs.stxapp.io/sdks/typescript/reference/account-view/

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

A live view of your account. Get one with `ws.accountView()`:

```ts
const ws = await client.websocket().connect();
const view = await ws.accountView({ onChange: (c) => render(c.view.state()) });
view.balance?.available_balance; // "123.4500"
view.openOrders;                 // [{id, market_id, status, price, ...}]
```

## Properties

| Property | Type | Description |
|---|---|---|
| `onChange` | `(change: AccountChange) => void \| undefined` |  |
| `seeds` | `Record<string, number>` | Join snapshots applied so far, per channel: 1 after the first seed, more after reconnects. |
| `ws` | `STXWebSocket` |  |
| `balance` | `Record<string, any> \| null` | The latest balance summary, or `null` before the first snapshot. |
| `closed` | `boolean` |  |
| `fills` | `Record<string, any>[]` | Fills, newest first. |
| `openOrders` | `Record<string, any>[]` | Open orders, newest first. |
| `positions` | `Record<string, any>[]` | Positions, one per market. |
| `ready` | `boolean` | True once every channel has delivered its join snapshot. |

## Methods

### `apply()`

```ts
apply(msg: ChannelMessage | { channel?: string; event: string; payload: any }): AccountChange | undefined
```

Apply one channel message. The view calls this for the channels it
joined; call it yourself to feed messages from an `account:` channel or a
channel you joined elsewhere. Unknown events are ignored.

| Parameter | Type | Description |
|---|---|---|
| `msg` | `ChannelMessage \| { channel?: string; event: string; payload: any }` |  |

Returns `AccountChange \| undefined`.

### `close()`

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

Leave the four channels. The socket stays open.

Returns `Promise<void>`.

### `state()`

```ts
state(): AccountState
```

The whole view as plain data.

Returns `AccountState`.
