# Balances

> Intear API balances.get and balances.subscribe: an account's token, NEAR and Rhea balances, fetched once or followed live.

This page is part of the Intear API docs. The Intear API is at `https://api.intea.rs` and `wss://api.intea.rs/ws`, with no API key. https://docs.intear.tech/api/llms-full.txt has all of its pages in one file, and https://docs.intear.tech/llms.txt lists every page of the Intear docs.

See [Balances and holders](https://docs.intear.tech/api/guides/balances-and-holders.md) for how to use them.

## `balances.get`

HTTP: `/balances`.

| Param | Description |
| --- | --- |
| `account` | **Required** |
| `sources` | **Required.** Any of `direct` (the account's own token balances), `native` (its NEAR, not counting what it has staked) and `rhea` (its deposits in Rhea) |
| `tokens` | Only these tokens' balances |
| `token_fields` | These [token fields](https://docs.intear.tech/api/reference/token-fields.md) of each token held come along. Native NEAR's are wrap.near's |

Result:

```json
{
  "height": 219969785,
  "timestamp_millis": 1792003812629,
  "balances": {
    "columns": ["token", "source", "balance"],
    "rows": [["wrap.near", "direct", "2564083907000000000000"], ["near", "native", "1000000000000000000000000"]]
  },
  "unknown": [],
  "errors": {},
  "near_locked_for_storage": "0",
  "tokens": { "columns": ["account_id", "symbol"], "rows": [["wrap.near", "wNEAR"]] }
}
```

- Balances are in the token's smallest units. Native NEAR is token `near`, in yoctoNEAR. Tokens the account held before and has none of now are listed with `"0"`.
- `unknown`: tokens held that this API doesn't know, without their balances.
- `errors`: `{ "<source>": { "code": "upstream_unavailable", "message": "..." } }` for each source that couldn't be read. The others are there all the same. `native` also reports it for an account that doesn't exist, like an unfunded implicit account, instead of a `"0"` balance.
- `near_locked_for_storage`: the part of the `native` balance that the account's storage keeps locked, so it can't spend it: 10^19 yoctoNEAR for each byte the account takes up, less what it has staked, and `"0"` for an account of 770 bytes or less. It's there when `native` was read, and `tokens` is left out or has `near`.
- `tokens`: a table of the `token_fields` of the tokens in `balances`, only with `token_fields`.

The first time an account is asked for, its `direct` balances come from FastNEAR, and are then stored and re-checked against RPC in the background. Once RPC has answered for all of them, they come from this project's own indexed balances, and are re-checked again at most once a day, when the account is asked for. When a re-check doesn't get an answer for every token, they come from FastNEAR again until a re-check a minute later does.

The indexer only counts what happened since it started, so every balance it starts keeping, like a token an account receives for the first time, is re-checked against RPC too, soon after.

## `balances.subscribe`

Takes the params of `balances.get`, and:

| Param | Description |
| --- | --- |
| `token_min_change` | With `token_fields`: [thresholds](https://docs.intear.tech/api/reference/tokens.md#tokenssubscribe) for them |

The result is shaped like `balances.get`'s. It follows `direct` and `native` balances. Each push is:

```json
{ "sub": 1, "height": 219969790, "timestamp_millis": 1792003815000, "balances": { "<token>": "<balance>" }, "set": { ... } }
```

- `balances`: every balance the block changed, after a mint, transfer or burn, gas spent or refunded, or a re-check that corrected it.
- `near_locked_for_storage`: with a new `near` balance, as in `balances.get`.
- `set`: as in [`tokens.subscribe`](https://docs.intear.tech/api/reference/tokens.md#tokenssubscribe), for the held tokens' `token_fields`, with every field of a token held for the first time.

Rhea deposits aren't followed, and the result says so with `"not_live": ["rhea"]`. A connection can follow up to 100 accounts. If the client falls behind, the subscription ends with `too_far_behind`: subscribe again.
