Skip to main content
This tutorial shows you how to use the Vaults.fyi SDK to power a data analytics workflow: fetching and filtering vault listings, pulling historical time-series data, comparing APY against benchmark rates, and assembling the results into a report or chart. This pattern is useful for dashboards, research tools, protocol monitoring, and any application that needs standardized DeFi yield data across multiple protocols.
All code examples use the TypeScript SDK (@vaultsfyi/sdk). The Python SDK exposes the same functionality using snake_case method names. See the SDK Reference for both.

Initialize the client

analytics.js

Step 1: Fetch and filter vault listings

Use getAllVaults to retrieve available vaults. Apply filters to narrow results by network, protocol, asset, or TVL range. Use page and perPage to paginate through large result sets.
analytics.js
Each vault in the response includes its protocol name, asset, network, current APY, TVL, and whether transactional support is available. Use these fields to build filters, sort orders, or summary tables.
Set minTvl to exclude low-liquidity vaults from analytics. Vaults with very low TVL often have volatile APY data that can skew aggregated metrics.

Step 2: Fetch historical APY and TVL data

Once you have a vault of interest, use the historical data methods to pull time-series metrics. Choose between the combined endpoint or the lighter focused endpoints depending on what you need.

Fetch combined APY and TVL history

analytics.js
The apyInterval parameter controls the smoothing window for APY values. Use '1day' for precise daily readings, '7day' for a weekly moving average, or '30day' for a longer-term trend line.

Fetch APY-only history

Use getVaultHistoricalApy when you only need APY data and want a lighter API response.
analytics.js

Fetch TVL-only history

Use getVaultHistoricalTvl to track capital flow into and out of a vault over time.
analytics.js

Step 3: Compare against benchmark rates

Benchmark rates let you put vault APY in context. Use getBenchmarks to retrieve the current reference rate, and getHistoricalBenchmarks to overlay it on your APY chart.

Fetch current benchmarks

analytics.js

Fetch historical benchmarks

analytics.js
Use the benchmark series as a baseline series in your chart alongside vault APY, making it easy to see when a vault outperforms or underperforms the reference rate.

Step 4: Assemble a vault report

Combine the methods above to build a complete snapshot for a single vault. The example below fetches current data, 30-day APY history, and the benchmark comparison in parallel.
analytics.js
Use Promise.all to fetch independent data in parallel. Fetching vault details, APY history, and benchmarks concurrently cuts total latency by up to two-thirds compared to sequential calls.

Step 5: Handle errors and pagination

Wrap API calls in error handling and iterate over pages for large data sets.

Error handling

analytics.js

Paginating through all vaults

analytics.js

What to build next

With vault listings, historical data, and benchmarks in hand, you can:
  • Render an APY chart — plot apyHistory as a line series with historicalBenchmarks as a reference line using any charting library (Recharts, Chart.js, Observable Plot).
  • Build a protocol leaderboard — sort vaults by 30-day average APY or by TVL growth to identify top-performing strategies.
  • Track historical share price — use getVaultHistoricalSharePrice to calculate compounded returns over any period for a more accurate performance metric than raw APY.
  • Export to CSV or JSON — serialize the assembled report into a flat file for use in spreadsheets, notebooks, or downstream data pipelines.
See the SDK Reference for the full parameter and response documentation for every method used in this tutorial.