estimate_sell_received_amount_raw
Documentation for eth_defi.uniswap_v2.fees.estimate_sell_received_amount_raw function.
- estimate_sell_received_amount_raw(uniswap, base_token_address, quote_token_address, quantity_raw, *, fee=30, slippage=0, intermediate_token_address=None)[source]
Estimate how much cash we receive for a certain quantity of tokens sold.
Example:
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 ) # Sell 50 ETH usdc_received = estimate_sell_received_amount_raw( uniswap_v2, weth.address, usdc.address, 50 * 10**18, ) usdc_received_decimals = usdc_received / 10**18 assert usdc_received_decimals == pytest.approx(80721.05538886508) # Calculate price of ETH as $ for our purchase price = usdc_received / (50*10**18) assert price == pytest.approx(Decimal(1614.4211077773016))
- Parameters
quantity – 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 (eth_typing.evm.HexAddress) –
quote_token_address (eth_typing.evm.HexAddress) –
quantity_raw (decimal.Decimal) –
intermediate_token_address (Optional[eth_typing.evm.HexAddress]) –
- Returns
Expected quote token amount to receive
- Raises
TokenDetailError – If we have an issue with ERC-20 contracts
- Return type