The initial subscription is the first step of the balance subscription. You send one signed subscribe message on the balances topic, and the server immediately responds with an initial-balance
The initial subscription is the first step of the balance subscription. You send one signed subscribe message on the balances topic, and the server immediately responds with an initial-balance message — a complete snapshot of every account that matches your filter. This snapshot is your baseline; every later balance-updated message is applied on top of it.
Subscribe request
Send a signed subscribe message. Every message must be authenticated — see Authentication.
| Field | Type | Required | Description |
|---|---|---|---|
messageType | string | ✅ | subscribe |
topic | string | optional | balances for the balance feed |
useMultiChainAssetFormat | boolean | optional | Include the chain in asset names. Defaults to false. |
key | string | ✅ | Your API public key |
passphrase | string | ✅ | Your API passphrase |
timestamp | string | ✅ | Unix epoch seconds (the same value used to compute the signature) |
signature | string | ✅ | Base64-encoded HMAC-SHA256 signature |
body | object | ✅ | Filter object — must be present, but may be empty ({}) for all accounts |
Example request:
{
"messageType": "subscribe",
"topic": "balances",
"useMultiChainAssetFormat": false,
"key": "API_PUBLIC_KEY",
"passphrase": "API_PASSPHRASE",
"timestamp": "1720000000",
"signature": "base64_encoded_hmac",
"body": { "filter": {} }
}Use the
body.filterobject to scope the snapshot to a specific participant, account group, account type, or asset. An empty filter ({}) returns all accounts you can access. See Subscription Filters.
initial-balance response
initial-balance responseOn a successful subscription, the server sends an initial-balance message containing a snapshot record for each match
| Field | Type | Description |
|---|---|---|
account_id | string | Unique account identifier |
participant_code | string | Owning participant code |
account_group | string | Account group assignment |
account_label | string | Label for the account (usable for filtering) |
account_type | string | One of: available, collateral, payable, receivable, collateral_deficiency |
asset | string | Asset code (e.g. USD) |
balance | string | Current account balance |
run_id | int | Unique run identifier |
run_type | string | Run type |
Example response:
{
"messageType": "initial-balance",
"body": {
"account_id": "abc123",
"participant_code": "ABC123",
"account_group": "00SCXM",
"account_label": "general",
"account_type": "available",
"asset": "USD",
"balance": "10000.00",
"run_id": 987654,
"run_type": "settlement"
"run_type": "settlement"
}
}Handling the snapshot
- Treat it as your baseline. Load every
initial-balancerecord into your local state before processing incrementa - Re-request on reconnect. After any disconnect, resubscribe and replace your local state with the fresh
initial-balancesnapshot — do not assume the old state is still accurate. - Then stream updates. Once the snapshot is loaded, apply each [
balance-updated](https://docs.zerohash.com/refereas it arrives, and keep the connection alive with apingevery 20 seconds (MaintainingSubscription).
Next steps
- Balance Updates — the
balance-updatedmessage fields - Subscription Filters — scoping the snapshot and updat
- Maintaining Subscription — the 20-second heartbeat