# Aggregate Balances

Get a consolidated portfolio view — total value across all wallets and chains, broken down by asset and chain.

## Overview

Instead of fetching each wallet's balance individually and summing them yourself, this endpoint does the aggregation server-side. It returns the total portfolio value in EUR and USD, a breakdown by chain, and a breakdown by token — making it ideal for a portfolio dashboard or total balance display.

Use `refresh=true` to bypass the cache and force a fresh fetch from the blockchain. Without it, balances may be up to a few minutes old but will load faster. Use `isTestnet=true` to aggregate testnet wallets instead.

### `GET /v1/wallets/balances/aggregate`

Authentication: bearer token required.

Aggregates total balance across all user wallets, grouped by chain and token.

**Query parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `refresh` | boolean | no | Force fresh blockchain fetch, bypassing cache (default: false) |
| `isTestnet` | boolean | no | Aggregate testnet wallet balances (default: false) |

**Responses**

`200` OK

```json
{
  "summary": {
    "totalInEur": "1250.40",
    "totalInUsd": "1367.30"
  },
  "byChain": {
    "ethereum": {
      "totalInEur": "850.00",
      "totalInUsd": "928.50",
      "nativeBalance": "0.35"
    },
    "polygon": {
      "totalInEur": "400.40",
      "totalInUsd": "438.80",
      "nativeBalance": "122.5"
    }
  },
  "byToken": {
    "USDC": {
      "name": "USD Coin",
      "totalBalance": "800.00",
      "totalInEur": "732.80",
      "totalInUsd": "800.00"
    }
  }
}
```

## Implementation

```javascript
// Load portfolio summary for dashboard
async function getPortfolioSummary(token, forceRefresh = false) {
  const params = new URLSearchParams();
  if (forceRefresh) params.set('refresh', 'true');

  const res = await fetch(
    `https://api.aureahub.com/v1/wallets/balances/aggregate?${params}`,
    { headers: { Authorization: `Bearer ${token}` } }
  );
  if (!res.ok) throw new Error('Failed to fetch portfolio');
  const data = await res.json();

  return {
    totalEur: data.summary.totalInEur,
    totalUsd: data.summary.totalInUsd,
    chains: data.byChain,
    tokens: data.byToken
  };
}

// Example: display total portfolio value
const portfolio = await getPortfolioSummary(token);
console.log(`Total portfolio: €${portfolio.totalEur} / $${portfolio.totalUsd}`);
```

---

Web version: https://docs.aureahub.com/#wallets-aggregate
