estimate_buy_received_amount
Documentation for eth_defi.uniswap_v3.price.estimate_buy_received_amount function.
- estimate_buy_received_amount(uniswap, base_token_address, quote_token_address, quantity, target_pair_fee, *, slippage=0, intermediate_token_address=None, intermediate_pair_fee=None, block_identifier=None, verbose=False)
Estimate how much we receive for buying with a certain quote token amount.
Example:
# Estimate the price of buying 1650 USDC worth of ETH eth_received = estimate_buy_received_amount( uniswap_v3, weth.address, usdc.address, 1650 * 10**18, # Must be raw token units 500, # 100 Uniswap v3 fee units = 1 BPS, this is 5 BPS ) assert eth_received / (10**18) == pytest.approx(0.9667409780905836) # Calculate price of ETH as $ for our purchase price = (1650 * 10**18) / eth_received assert price == pytest.approx(Decimal(1706.7653460381143))
- Parameters
quantity (decimal.Decimal | int) –
How much of the base token we want to buy.
Expressed in raw token.
uniswap (eth_defi.uniswap_v3.deployment.UniswapV3Deployment) – Uniswap v3 deployment
base_token_address (Union[eth_typing.evm.HexAddress, str]) – Base token address of the trading pair
quote_token_address (Union[eth_typing.evm.HexAddress, str]) – Quote token address of the trading pair
target_pair_fee (int) –
Trading fee of the target pair in Uniswap v3 fee units.
100 units = 1 BPS.
slippage (float) – Slippage express in bps. The amount will be estimated for the maximum slippage.
block_identifier (int | None) –
A specific block to estimate price.
Either block number or a block hash.
verbose (bool) – If True, return more debug info
intermediate_token_address (Optional[eth_typing.evm.HexAddress]) –
intermediate_pair_fee (int | None) –
- Returns
Expected base token amount to receive
- Raises
TokenDetailError – If we have an issue with ERC-20 contracts
- Return type