# 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 %}
