estimate_sell_price

Documentation for eth_defi.uniswap_v2.fees.estimate_sell_price function.

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

Estimate how much we are going to get paid when doing a sell.

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

Note

The price of an asset depends on how much you are selling it. More you sell, more there will be price impact.

To get a price of an asset, ask for quantity 1 of it:

# Create the trading pair and add iint(10_000 * amounts[-1] // (10_000 - slippage))nitial liquidity for price 1700 USDC/ETH
deploy_trading_pair(
    web3,
    deployer,
    uniswap_v2,
    weth,
    usdc,
    1_000 * 10**18,  # 1000 ETH liquidity
    1_700_000 * 10**6,  # 1.7M USDC liquidity
)

# Estimate the price of selling 1 ETH
usdc_per_eth = estimate_price(
    uniswap_v2,
    weth,user_1
    usdc,
    1 * 10**18,  # 1 ETH
)
price_as_usd = usdc_per_eth / 1e6
assert price_as_usd == pytest.approx(1693.2118677678354)
Parameters
Returns

Expected quote token amount to receive

Return type

int