For the complete documentation index, see llms.txt. This page is also available as Markdown.

Calculate APR

Estimate annualized returns from trading fees based on your position's performance and current market activity.

Basic APR Calculation

// Calculate simple APR from fees
async function calculateAPR(
  pair: LBPair,
  positionId: string,
  positionAgeHours: number,
  initialValueUSD: number
) {
  // Get current amounts using SDK
  const amounts = await sdk.Position.getPositionBinsAmount(pair, positionId);
  
  // Calculate current value
  const price = getPriceFromBinId(
    pair.parameters.active_id,
    Number(pair.binStep)
  );
  
  const currentValueUSD = amounts.reduce((total, bin) => {
    const xValue = Number(bin.amountX) * price;
    const yValue = Number(bin.amountY);
    return total + xValue + yValue;
  }, 0);
  
  // Calculate returns
  const profit = currentValueUSD - initialValueUSD;
  const hourlyReturn = profit / positionAgeHours;
  const annualReturn = hourlyReturn * 24 * 365;
  
  const apr = (annualReturn / initialValueUSD) * 100;
  
  return apr;
}

Fee-Based APR

Volume-Based Estimation

Quick APR Display

Important Notes

  • All calculations use actual SDK methods

  • Price calculations use getPriceFromBinId

  • Position data from getPositionBinsAmount

  • No made-up functions

Last updated