API & Developers

How to Pull Portfolio Data From a Crypto API

A practical walkthrough of fetching multi-chain wallet balances, protocol positions and transaction history from a crypto portfolio API, with worked examples.

Octav Team1 min read
Banner: Pull a multi-chain portfolio in one request

Most teams that end up buying portfolio data start by trying to build it. The build usually stalls at the same place: enumerating positions is easy on one chain and miserable on fifteen.

What a portfolio API actually has to return

A wallet address is not a portfolio. A useful response resolves an address into every position it controls, priced and categorised:

FieldWhy it matters
chainPositions must be attributable per network
protocolAn LP token is meaningless without its protocol context
balanceRaw units, so you can re-derive value yourself
valuePriced at a stated timestamp, not "now"
categoryWallet, lending, staking, LP, vesting

The last two are what separate a portfolio API from a block explorer. A balance without a timestamped price is not something you can put in a report.

Fetching a portfolio

A single request should resolve an address across every supported chain:

curl -s https://api.octav.fi/v1/portfolio \
  -H "Authorization: Bearer $OCTAV_API_KEY" \
  -G --data-urlencode "addresses=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"

Handling the response in TypeScript:

type Position = {
  chain: string;
  protocol: string | null;
  symbol: string;
  balance: string;
  value: number;
  category: "wallet" | "lending" | "staking" | "lp" | "vesting";
};
 
const res = await fetch(url, {
  headers: { Authorization: `Bearer ${process.env.OCTAV_API_KEY}` },
});
 
if (!res.ok) {
  throw new Error(`Portfolio request failed: ${res.status}`);
}
 
const { positions } = (await res.json()) as { positions: Position[] };
 
// Exposure by chain — the aggregate most teams want first.
const byChain = positions.reduce<Record<string, number>>((acc, p) => {
  acc[p.chain] = (acc[p.chain] ?? 0) + p.value;
  return acc;
}, {});

Three mistakes that show up in production

  • Treating the response as live state. Prices move. Store the timestamp alongside the value, or your reports will not reconcile with each other.
  • Summing LP tokens at face value. An LP position's value is a function of the pool's composition, not of the token's own price.
  • Paginating naively. Addresses with long histories return large result sets; handle the cursor rather than assuming one page.

Where to go next

The API documentation covers authentication, rate limits and the full response schema.

Keep reading

  • Banner: How to choose a crypto portfolio API
    API & Developers

    How to Choose a Crypto Portfolio API

    A buyer's guide to evaluating crypto portfolio APIs — the tests to run, the questions vendors dislike, and the trade-offs between coverage, cost and latency.

    2 min read

  • Banner: Every Octav API endpoint, with credits and limits
    API & Developers

    Crypto Portfolio API Endpoint Reference

    Every Octav API endpoint with its parameters, credit cost and response, plus authentication, rate limits and caching behaviour for building on portfolio data.

    2 min read

  • Banner: A live portfolio in one iframe
    API & Developers

    Embed a Live Crypto Portfolio Widget

    Add a live multi-chain portfolio view to any site with one iframe, no frontend build required, and when to use the raw API instead of a widget.

    1 min read