> ## Documentation Index
> Fetch the complete documentation index at: https://kamino.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Market Reserve APYs

> Fetch Kamino market reserve borrow and supply APY data using the API or SDK

## Borrow & Supply APY Calculation

A reserve is a single asset lending pool within a market. All deposits of an asset enter the same reserve, and all borrowing draws from that pool.

Variable rates are driven by utilization, the fraction of deposits currently borrowed:

```
Utilization = Borrowed / Total Deposited
```

As utilization increases, borrow rates rise. As utilization decreases, borrow rates fall.

Supply APY is derived from borrower interest and depends on both the borrow rate and utilization:

```
Supply APY ≈ Borrow Rate × Utilization × (1 − Protocol Spread)
```

Not all deposited capital is borrowed at any given time, so supply APY is always lower than the borrow rate. Higher utilization means more of the pool is earning interest, which increases lender yield.

Reserves are isolated pools. The same asset in different markets has different borrowers, collateral, and risk profiles, and therefore different rates.

<Tabs>
  <Tab title="API">
    <Steps>
      <Step>
        ### Fetch All Markets

        Retrieve the list of all lending markets on Kamino.

        ```typescript theme={null}
        const API_BASE_URL = 'https://api.kamino.finance';
        const response = await fetch(`${API_BASE_URL}/v2/kamino-market`);
        const markets = await response.json();
        ```

        <Info>
          The `/v2/kamino-market` endpoint returns all lending markets including Main Market, JLP Market, Altcoins Market, and Prime Market.
        </Info>
      </Step>

      <Step>
        ### Get Reserve APYs for Each Market

        For each market, fetch the APY metrics for all reserves (USDC, SOL, wETH, etc.).

        ```typescript theme={null}
        const allMarketReserves = await Promise.all(
          markets.map(async (market) => {
            const response = await fetch(
              `${API_BASE_URL}/kamino-market/${market.lendingMarket}/reserves/metrics`
            );
            const reserves = await response.json();
            return { market, reserves };
          })
        );

        allMarketReserves.forEach(({ market, reserves }) => {
          console.log(`\n${market.name}:`);

          reserves.forEach((reserve) => {
            console.log(`\n${reserve.liquidityToken}:`);
            console.log(`  Supply APY: ${(reserve.supplyApy * 100).toFixed(2)}%`);
            console.log(`  Borrow APY: ${(reserve.borrowApy * 100).toFixed(2)}%`);
            console.log(`  Total Deposits: $${reserve.totalSupplyUsd}`);
            console.log(`  Total Borrowed: $${reserve.totalBorrowUsd}`);
          });
        });
        ```

        <Info>
          The `/kamino-market/{pubkey}/reserves/metrics` endpoint returns comprehensive metrics for each reserve including APYs, total deposits, and borrows.
        </Info>
      </Step>
    </Steps>
  </Tab>

  <Tab title="SDK">
    <Steps>
      <Step>
        ### Import Dependencies

        Import the required packages for Solana RPC communication and Kamino SDK.

        ```typescript theme={null}
        import { createSolanaRpc } from '@solana/kit';
        import { address } from '@solana/kit';
        import { KaminoMarket, DEFAULT_RECENT_SLOT_DURATION_MS } from '@kamino-finance/klend-sdk';
        ```
      </Step>

      <Step>
        ### Get Current Slot

        Fetch the current Solana slot (block number) for APY calculations.

        ```typescript theme={null}
        const rpc = createSolanaRpc('https://api.mainnet-beta.solana.com');
        const slot = await rpc.getSlot().send();

        console.log(`Current slot: ${slot}`);
        ```

        <Info>
          **What is a slot?**

          A slot is Solana's block number — like a timestamp but for blockchain state. The SDK uses it to calculate APY based on the current on-chain state. Think of it as "calculate APY as of right now."
        </Info>
      </Step>

      <Step>
        ### Load a Market

        Load a specific lending market using its public key.

        ```typescript theme={null}
        const marketAddress = address('7u3HeHxYDLhnCoErrtycNokbQYbWGzLs6JSDqGAv5PfF');
        const market = await KaminoMarket.load(rpc, marketAddress, DEFAULT_RECENT_SLOT_DURATION_MS);
        ```
      </Step>

      <Step>
        ### Get All Reserves

        Retrieve all reserves (asset pools) in the market.

        ```typescript theme={null}
        const reserves = market.getReserves();
        ```
      </Step>

      <Step>
        ### Calculate APYs for Each Reserve

        Loop through each reserve and calculate its borrow and supply APYs.

        ```typescript theme={null}
        for (const reserve of reserves) {
          // Get the reserve's token symbol
          const symbol = reserve.stats.symbol || reserve.stats.mintAddress.toString().slice(0, 8);

          // Calculate APYs using current slot (convert to percentage form)
          const borrowAPY = reserve.totalBorrowAPY(slot) * 100;
          const supplyAPY = reserve.totalSupplyAPY(slot) * 100;

          // Get additional metrics (utilization as a percentage)
          const utilization = reserve.calculateUtilizationRatio();
          const totalDeposits = reserve.getDepositTvl();
          const totalBorrows = reserve.getBorrowTvl();

          console.log(`\n${symbol}:`);
          console.log(`  Supply APY: ${supplyAPY.toFixed(2)}%`);
          console.log(`  Borrow APY: ${borrowAPY.toFixed(2)}%`);
          console.log(`  Utilization: ${utilization.toFixed(2)}%`);
          console.log(`  Total Deposits: ${totalDeposits.toFixed(2)}`);
          console.log(`  Total Borrowed: ${totalBorrows.toFixed(2)}`);
        }
        ```

        <Info>
          The `reserve.totalBorrowAPY(slot)` and `reserve.totalSupplyAPY(slot)` methods calculate APY based on the current interest rate, utilization, and compounding frequency at the specified slot.
        </Info>

        <Check>
          You've successfully calculated borrow and supply APYs across all reserves using the Kamino SDK.
        </Check>
      </Step>
    </Steps>
  </Tab>
</Tabs>
