> For the complete documentation index, see [llms.txt](https://docs-unified.crypto-chief.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-unified.crypto-chief.com/guides/batch-balances.md). Agents can also search and read this documentation through its [MCP server](https://docs-unified.crypto-chief.com/~gitbook/mcp).

# Balances for Thousands of Addresses

## Balances for Thousands of Addresses

An exchange or a payment service watches thousands of deposit addresses. [`POST /v1/addresses/balances`](https://docs-unified.crypto-chief.com/api-reference/balances.md#batch-balances) reads up to 100 address–network pairs per call, each with its own status, and charges per pair.

### Plan the calls

* **Chunks of 100.** 10,000 addresses are 100 calls.
* **Name the assets.** `assets` per item reads only what you need, for example USDT on TRON, instead of every token.
* **Bounded concurrency.** Run a few chunks at a time, not all of them. Stay under your project's request limit: `X-RateLimit-Remaining` shows how much is left, and a `429` carries `Retry-After`.
* **Retry only the failures.** An item with `status: "error"` is refunded and has its own `retry_after`; resend those items, not the chunk.
* **Do not retry `unsupported`.** The network does not offer balances in that form; it will not change.

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

```javascript
const CHUNK = 100;
const PARALLEL = 4;
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

async function readChunk(items, attempt = 0) {
  const { http, data, headers } = await api("POST", "/addresses/balances", {}, { items });
  if (http === 429 || http === 503) {
    await sleep(1000 * Number(headers.get("retry-after") ?? 1));
    return readChunk(items, attempt + 1);
  }
  if (http !== 200) throw new Error(`${http} ${data.error}: ${data.message}`);

  const failed = data.items.filter((r) => r.status === "error");
  const done = data.items.filter((r) => r.status !== "error");
  if (failed.length && attempt < 3) {
    await sleep(1000 * Math.max(...failed.map((r) => r.retry_after ?? 1)));
    const again = items.filter((i) => failed.some((f) => f.ref === i.ref));
    done.push(...(await readChunk(again, attempt + 1)));
  } else {
    done.push(...failed); // still failing: report them as unknown
  }
  return done;
}

async function readAll(pairs) {
  // pairs: [{ ref, network, address, assets? }]
  const chunks = [];
  for (let i = 0; i < pairs.length; i += CHUNK) chunks.push(pairs.slice(i, i + CHUNK));
  const results = [];
  for (let i = 0; i < chunks.length; i += PARALLEL) {
    const batch = await Promise.all(chunks.slice(i, i + PARALLEL).map((c) => readChunk(c)));
    results.push(...batch.flat());
  }
  return results;
}

const results = await readAll(
  depositAddresses.map((a) => ({
    ref: a.id,
    network: "TRON_MAINNET",
    address: a.address,
    assets: ["TRON_MAINNET/41a614f803b6fd780986a42c78ec9c7f77e6ded13c"],
  })),
);
```

{% endtab %}

{% tab title="Python" %}

```python
import time
from concurrent.futures import ThreadPoolExecutor

CHUNK, PARALLEL = 100, 4

def read_chunk(items, attempt=0):
    status, data, headers = api("POST", "/addresses/balances", body={"items": items})
    if status in (429, 503):
        time.sleep(int(headers.get("Retry-After", "1")))
        return read_chunk(items, attempt + 1)
    if status != 200:
        raise RuntimeError(f"{status} {data.get('error')}: {data.get('message')}")
    failed = [r for r in data["items"] if r["status"] == "error"]
    done = [r for r in data["items"] if r["status"] != "error"]
    if failed and attempt < 3:
        time.sleep(max(r.get("retry_after") or 1 for r in failed))
        refs = {r["ref"] for r in failed}
        done += read_chunk([i for i in items if i["ref"] in refs], attempt + 1)
    else:
        done += failed  # still failing: report them as unknown
    return done

def read_all(pairs):
    chunks = [pairs[i:i + CHUNK] for i in range(0, len(pairs), CHUNK)]
    with ThreadPoolExecutor(PARALLEL) as pool:
        return [r for chunk in pool.map(read_chunk, chunks) for r in chunk]

results = read_all([
    {"ref": a["id"], "network": "TRON_MAINNET", "address": a["address"],
     "assets": ["TRON_MAINNET/41a614f803b6fd780986a42c78ec9c7f77e6ded13c"]}
    for a in deposit_addresses
])
```

{% endtab %}
{% endtabs %}

Results come back in request order with your `ref`, so match them by `ref`, not by position after retries.

### Cost

Each pair costs 2,000 credits; 10,000 pairs cost 20,000,000 credits — $2. Pairs that failed are refunded.

### Balances are not deposits

A balance tells what an address holds now. It does not tell which payment arrived, when, or from whom, and it changes when funds are swept. For crediting deposits, use transfers and EventStream — [Deposit Reconciliation with EventStream](https://docs-unified.crypto-chief.com/guides/deposit-reconciliation.md) — and use batch balances to check that the ledger matches what is on the addresses.
