get_liquidity

Documentation for eth_defi.uniswap_v2.liquidity.get_liquidity function.

get_liquidity(web3, pair_address)[source]

Measure Uniswap v2 pool liquidity.

Returns

The current liquidity in the pool as (token0 liquidity, token1 liquidity) tuple.

Parameters
  • web3 (web3.main.Web3) –

  • pair_address (Union[HexAddress, str]) –

Return type

eth_defi.uniswap_v2.liquidity.LiquidityResult

Example:

liquidity_result = get_liquidity(web3, pair_address)

assert liquidity_result.token0 == weth.address
assert liquidity_result.token1 == usdc.address

assert liquidity_result.get_liquidity_for_token(weth.address) == 10 * 10**18
assert liquidity_result.block_number > 0
Parameters
  • web3 (web3.main.Web3) – Web3 connection

  • pair_address (Union[HexAddress, str]) – Uniswap v2 pair contract address

Return type

eth_defi.uniswap_v2.liquidity.LiquidityResult