# Balance Updates

Use this stream for private balance snapshots and live balance changes.

### Endpoint

```
wss://wallet-mutator-view.outpoll.com/balance/ws
```

### Authentication

Send this message right after connect.

```json
{
  "t": "AUTH",
  "d": {
    "apiKey": "<API_KEY>",
    "signature": "<SIGNATURE>",
    "timestamp": "<UNIX_EPOCH_SECONDS>"
  }
}
```

Build `signature` from `timestamp + "GET" + "/balance/ws"`.

### Initial snapshot

After auth, the server sends the current balances:

```json
{
  "t": "success",
  "d": {
    "l": [
      {
        "i": "078dcd98-928d-479f-8110-ff6d27e44de2",
        "b": 1250.50,
        "f": 1200.00
      }
    ]
  },
  "r": null
}
```

| Field     | Type   | Description  |
| --------- | ------ | ------------ |
| `d.l[].i` | string | Asset ID     |
| `d.l[].b` | number | Balance      |
| `d.l[].f` | number | Free balance |

### Balance delta

```json
{
  "u": "user-id",
  "a": "asset-id",
  "aop": 0.50,
  "c": 50.00,
  "b": 1200.50,
  "f": 1150.00
}
```

| Field | Type   | Description        |
| ----- | ------ | ------------------ |
| `u`   | string | User ID            |
| `a`   | string | Asset ID           |
| `aop` | number | Average open price |
| `c`   | number | Cost               |
| `b`   | number | Balance            |
| `f`   | number | Free balance       |

### Python example

{% code title="balance\_updates.py" %}

```python
import asyncio, json, websockets

def auth_message(api_key, signature, timestamp):
    return {
        "t": "AUTH",
        "d": {
            "apiKey": api_key,
            "signature": signature,
            "timestamp": timestamp,
        },
    }

async def balance_updates(api_key, signature, timestamp):
    uri = "wss://wallet-mutator-view.outpoll.com/balance/ws"
    async with websockets.connect(uri) as ws:
        await ws.send(json.dumps(auth_message(api_key, signature, timestamp)))

        async for msg in ws:
            print(json.loads(msg))
```

{% endcode %}
