estimate_buy_quantity

Documentation for eth_defi.uniswap_v2.fees.estimate_buy_quantity function.

estimate_buy_quantity(uniswap, base_token, quote_token, quantity, *, fee=30, slippage=0)[source]

Estimate how many tokens we are going to receive when doing a buy.

Good for doing a price impact calculations.

Calls the on-chain contract to get the current liquidity and estimates the the price based on it.

Example:

# Estimate how much ETH we will receive for 500 USDC.
# In this case the pool ETH price is $1700 so this should be below ~1/4 of ETH
amount_eth = estimate_buy_quantity(
    uniswap_v2,
    weth,
    usdc,
    500*10**18,
)
assert amount_eth / 1e18 == pytest.approx(0.28488156127668085)
Parameters
Returns

Expected base token to receive

Return type

int