estimate_buy_price_decimals

Documentation for eth_defi.uniswap_v2.fees.estimate_buy_price_decimals function.

estimate_buy_price_decimals(uniswap, base_token_address, quote_token_address, quantity, *, fee=30, slippage=0, intermediate_token_address=None)[source]

Estimate how much we are going to need to pay when doing buy.

Much like estimate_buy_price() with the differences of - Tokens are passed as address instead of contract instance - We use base token quantity units instead of cash - We use decimals instead of raw token amounts

Example:

# Create the trading pair and add initial liquidity
deploy_trading_pair(
    web3,
    deployer,
    uniswap_v2,
    weth,
    usdc,
    1_000 * 10**18,  # 1000 ETH liquidity
    1_700_000 * 10**18,  # 1.7M USDC liquidity
)

# Estimate the price of buying 1 ETH
usdc_per_eth = estimate_buy_price_decimals(
    uniswap_v2,
    weth.address,
    usdc.address,
    Decimal(1.0),
)
assert usdc_per_eth == pytest.approx(Decimal(1706.82216820632059904))
Parameters
  • quantity (decimal.Decimal) – How much of the base token we want to buy

  • uniswap (eth_defi.uniswap_v2.deployment.UniswapV2Deployment) – Uniswap v2 deployment

  • base_token – Base token of the trading pair

  • quote_token – Quote token of the trading pair

  • fee (int) – Trading fee express in bps, default = 30 bps (0.3%)

  • slippage (float) – Slippage express in bps

  • base_token_address (HexAddress) –

  • quote_token_address (HexAddress) –

  • intermediate_token_address (Optional[HexAddress]) –

Returns

Expected quote token amount to receive

Raises

TokenDetailError – If we have an issue with ERC-20 contracts

Return type

decimal.Decimal