> For the complete documentation index, see [llms.txt](https://docs.sfox.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sfox.com/connect/websocket-api/end-users/users-1.md).

# Balances

The balances feed tracks account balance updates across all of your users' accounts.&#x20;

{% hint style="info" %}
A balance update from this feed will include the `user_id` of the user to use to identify which user's account the update is for as well as this user's current balances across all currencies in the account.
{% endhint %}

### Subscription Instructions

| Feed Name                               |
| --------------------------------------- |
| **`private.enterprise.users.balances`** |

<table><thead><tr><th width="239.71345029239765">Key</th><th width="484">Description</th></tr></thead><tbody><tr><td><strong><code>user_id</code></strong></td><td>Unique shared ID you generated for the End User account</td></tr><tr><td><strong><code>currency</code></strong></td><td>The currency</td></tr><tr><td><strong><code>balance</code></strong></td><td>Total balance of this currency in your account across all wallets outlined below</td></tr><tr><td><strong><code>available</code></strong></td><td>Portion of the balance that is available for trading or withdrawals</td></tr><tr><td><strong><code>held</code></strong></td><td>Potion of the balance that is currently on hold and unavailable for trading or withdrawals<br>e.g. an ACH deposit that has yet to settle</td></tr><tr><td><strong><code>trading_wallet</code></strong></td><td>Amount of the currency in your trading wallet</td></tr><tr><td><strong><code>borrow_wallet</code></strong></td><td>Amount of the currency , represented as the borrow wallet balance</td></tr><tr><td><strong><code>collateral_wallet</code></strong></td><td>Amount of the current being held as collateral in your collateral wallet</td></tr><tr><td><strong><code>lending_wallet</code></strong></td><td>Amount of the currency in your lending wallet</td></tr></tbody></table>

### Example Code

{% tabs %}
{% tab title="NodeJS" %}

```javascript
const WebSocket = require('ws')

const ws = new WebSocket('wss://ws.sfox.com/ws')

ws.on('open', function() {
  const authMessage = {
   type: 'authenticate',
   apiKey: `${process.env.ENTERPRISE_API_KEY}`,
   enterprise: 'true'
  }
  
  ws.send(JSON.stringify(authMessage))
})

// After successful authentication, subscribe to user balances feed
const subscribeMsg = {
  type: 'subscribe',
  feeds: ['private.enterprise.users.balances']
}

ws.send(JSON.stringify(subscribeMsg))
```

{% endtab %}

{% tab title="Python" %}
{% code overflow="wrap" %}

```python
import asyncio
import json
import websockets
import os

async def main(uri):
    async with websockets.connect(uri) as ws:
        await ws.send(json.dumps({
            "type": "authenticate",
            "apiKey": f"{os.environ['ENTERPRISE_API_KEY']}",
            "enterprise": "true"
        }))

        # After successful authentication message, subscribe to the user balances feed
        await ws.send(json.dumps({
            "type": "subscribe",
            "feeds": ["private.enterprise.users.balances"]
        }))
        async for msg in ws:
            print(msg)


asyncio.run(main("wss://ws.sfox.com/ws"))
```

{% endcode %}
{% endtab %}

{% tab title="Example Message" %}

```json
{
    "sequence": 22,
    "recipient": "private.enterprise.users.balances",
    "timestamp": 1710367225302228171,
    "payload": {
        "user_id": "test3",                        //Unique shared ID you generated for the End User account
        "updates": [
            {
                "currency": "btc",            
                "balance": "9.99850081",          //Total balance in the account
                "available": "9.99850081",        //Balance available for trading / withdrawals
                "held": "0",                      //Funds locked in the account
                "trading_wallet": "9.99850081",   //Balance in the trading wallet of the account
                "collateral_wallet": "0",         //Balance in the collateral wallet of the account
                "borrow_wallet": "0",             //Balance borrowed by the account
                "lending_wallet": "0",            //Balance lent by the account
                "staking_wallet": "0"             //Balance staked by the account
            },
            {
                "currency": "eth",
                "balance": "0.01826367",
                "available": "0.01826367",
                "held": "0",
                "trading_wallet": "0.01826367",
                "collateral_wallet": "0",
                "borrow_wallet": "0",
                "lending_wallet": "0",
                "staking_wallet": "0"
            },
            {
                "currency": "usd",
                "balance": "100035.33054742",
                "available": "100035.33054742",
                "held": "0",
                "trading_wallet": "100035.33054742",
                "collateral_wallet": "0",
                "borrow_wallet": "0",
                "lending_wallet": "0",
                "staking_wallet": "0"
            }
        ]
    }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sfox.com/connect/websocket-api/end-users/users-1.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
