Balance Subscription

The balance subscription streams your zerohash account balances in real time over the Private WebSocket API. Instead of polling GET /accounts on the REST API, you open one authenticated connection and receive balances as they change — ideal for keeping ledgers, dashboards, and risk systems continuously in sync.

How it works

The balance subscription delivers data in two phases:

  1. Snapshot — Immediately after you subscribe, the server sends an initial-balance message: a complete snapshot of every account that matches your subscription filter.
  2. Incremental updates — From then on, the server sends balance-updated messages whenever a matching account's balance changes. Each update also includes the underlying movements[] that caused the change.

Together these let you build and maintain an accurate local view of balances: load the snapshot as your baseline, then apply each incremental update on top.

connect → subscribe (topic: balances) → initial-balance snapshot
        → balance-updated → balance-updated → …  (ongoing)
        → ping every 20s to keep the connection alive

Connection endpoints

EnvironmentWebSocket URL
Productionwss://ws.zerohash.com
Certification (testing)wss://ws.cert.zerohash.com

Subscribing

Send a signed subscribe message on the balances topic. Every message must be authenticated — see Authentication.

FieldTypeRequiredDescription
messageTypestringsubscribe
topicstringoptionalbalances for the balance feed
useMultiChainAssetFormatbooleanoptionalInclude the chain in asset names. Defaults to false.
keystringYour API public key
passphrasestringYour API passphrase
timestampstringUnix epoch seconds (same value used to sign)
signaturestringBase64-encoded HMAC-SHA256 signature
bodyobjectFilter object — must be present, but may be empty ({}) for all accounts

Example subscribe message:

{
  "messageType": "subscribe",
  "topic": "balances",
  "useMultiChainAssetFormat": false,
  "key": "API_PUBLIC_KEY",
  "passphrase": "API_PASSPHRASE",
  "timestamp": "1720000000",
  "signature": "base64_encoded_hmac",
  "body": { "filter": {} }
}

Scoping what you receive

By default (an empty filter) you receive balances for all accounts you can access. To narrow the stream — for example, to a single participant, account group, account type, or asset — pass a filter object in the body. See Subscription Filters.

⚠️

The filter is part of the signed body. If you change the filter, recompute the signature over the new body.

Message types on this feed

messageTypeDirectionMeaning
subscribeclient → serverOpen the balances subscription
initial-balanceserver → clientFull snapshot of matching accounts, sent once on subscribe
balance-updatedserver → clientIncremental change to a matching account
pingclient → serverHeartbeat — required every 20 seconds

Keeping the subscription alive

Send a signed ping every 20 seconds or the server will close the connection. Because long-lived connections can drop due to network or ISP issues, build in a reconnection / resubscription routine — on reconnect, resubscribe and treat the fresh initial-balance snapshot as your new source of truth. See Maintaining Subscription.

Next steps