Get Pair Bins

Retrieve detailed bin data for a specific trading pair within a given range. This method allows you to inspect liquidity distribution and reserves at each price level.

Prerequisites

Before fetching bin data:

  • Have a valid LBPair object from getPair() or getPairs()

  • Understand bin ID ranges and price relationships

  • Know which bins to inspect (around active bin)

Basic Usage

// First, get the pair
const pair = await sdk.Pair.getPair(pairAddress);

// Fetch bins around the active bin
const activeId = pair.parameters.active_id;
const bins = await sdk.Pair.getPairBins(
  pair, 
  [activeId - 10, activeId + 10]  // 20 bins range
);

// Display bin reserves
bins.forEach((bin, index) => {
  const binId = activeId - 10 + index;
  console.log(`Bin ${binId}:`, {
    reserveX: bin.reserve_x.toString(),
    reserveY: bin.reserve_y.toString()
  });
});

Method Signature

Parameters

  • pair: The LBPair object to query

  • binRange: Tuple of [fromBinId, toBinId] (inclusive start, exclusive end)

Returns

Array of PairBin objects:

Understanding Bin Ranges

Practical Examples

Analyze Liquidity Depth

Find Liquidity Walls

Display Price Levels

Performance Notes

  • Queries use devInspectTransactionBlock (no gas cost)

  • Larger ranges take more time to fetch

  • Maximum practical range depends on RPC limits

  • Consider chunking very large ranges

Common Use Cases

  1. Order Book Visualization: Display liquidity at each price level

  2. Slippage Calculation: Estimate impact before swaps

  3. Liquidity Analysis: Find optimal entry/exit points

  4. Market Depth: Assess pair's ability to handle large trades

Last updated