Balances

The private.user.balances feed provides you with real-time updates on changes to your account balances, including Web3 wallet balances updates.

Updates reflect your balances inclusive of completed, partially completed, or pending transactions, orders, and transfers. For example, a given balance update does reflect outstanding and/or partially filled orders.

Subscribing

Feed name

private.user.balances

// Request -> balances feed
{
    "type": "subscribe", 
    "feeds": ["private.user.balances"]
}

Balances Message

There are 2 types of balances message payloads:

  • Account balances: Your trading/custody account balances (Refer to Get All Balances for payload and balance object details).

  • Web3 wallet balances: Your account's Web3 wallet balances (see below for payload details). Web3 wallet messages can be identified by the type field.

Web3 Wallet Message

Key
Description

address

The web3 wallet address

balance

The total balance of this currency in your web3 wallet

network

The token network

type

Specifies that this is a Web3 balance message. (web3)

// Balances feed message (account balances)
{
  "sequence": 10,
  "recipient": "private.user.balances",
  "timestamp": 1649899310281716289,
  "payload": [{
    "currency": "btc",
    "balance": "0.17572419",
    "available": "0.17572419",
    "held": "0",
    "trading_wallet": "0.17572419",
    "collateral_wallet": "0",
    "borrow_wallet": "0",
    "lending_wallet": "0"
  }, {
    "currency": "usd",
    "balance": "100",
    "available": "100",
    "held": "0",
    "trading_wallet": "100",
    "collateral_wallet": "0",
    "borrow_wallet": "0",
    "lending_wallet": "0"
  }]
}

Example Code

const WebSocket = require('ws')

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

ws.on('open', function() {
  const authMessage = {
   type: 'authenticate',
   apiKey: '<API_KEY>'
  }
  
  ws.send(JSON.stringify(authMessage))
})

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

ws.send(JSON.stringify(subscribeMsg))

Last updated