one_delta.price
Documentation for eth_defi.one_delta.price Python module.
1delta price calculations.
See Uniswap v3 historical price estimation tutorial.
Helpers to calculate
Functions
|
Estimate how much we receive for buying with a certain quote token amount. |
|
Estimate how much we receive for selling a certain base token amount. |
Classes
Internal helper class for price calculations. |
- class OneDeltaPriceHelper
Bases:
objectInternal helper class for price calculations.
- __init__(one_delta)
- Parameters
one_delta (eth_defi.one_delta.deployment.OneDeltaDeployment) –
- get_amount_out(amount_in, path, fees, exchange=Exchange.UNISWAP_V3, *, slippage=0, block_identifier=None)
Get how much token we are going to receive.
- Parameters
amount_in (int) – Amount of input asset.
path (list[eth_typing.evm.HexAddress]) – List of token addresses how to route the trade
fees (list[int]) – List of trading fees of the pools in the route
exchange (eth_defi.one_delta.constants.Exchange) – exchange to be used for the swap
slippage (float) – Slippage express in bps
block_identifier (int | None) – A specific block to estimate price
- Return type
- get_amount_in(amount_out, path, fees, exchange=Exchange.UNISWAP_V3, *, slippage=0, block_identifier=None)
Get how much token we are going to spend.
- Parameters
amount_in – Amount of output asset.
path (list[eth_typing.evm.HexAddress]) – List of token addresses how to route the trade
fees (list[int]) – List of trading fees of the pools in the route
exchange (eth_defi.one_delta.constants.Exchange) – exchange to be used for the swap
slippage (float) – Slippage express in bps
block_identifier (int | None) – A specific block to estimate price
amount_out (int) –
- Return type
- estimate_buy_received_amount(one_delta_deployment, 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( one_delta_deployment, weth.address, usdc.address, 1650 * 10**18, 500, ) 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
one_delta_deployment (eth_defi.one_delta.deployment.OneDeltaDeployment) – 1delta deployment
base_token_address (eth_typing.evm.HexAddress) – Base token address of the trading pair
quote_token_address (eth_typing.evm.HexAddress) – Quote token address of the trading pair
target_pair_fee (int) – Trading fee of the target pair in raw format
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
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
- estimate_sell_received_amount(one_delta_deployment, 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 selling a certain base token amount.
See example in
eth_defi.one_delta.price.- Parameters
quantity (decimal.Decimal | int) – How much of the base token we want to sell
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 raw format
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
verbose (bool) – If True, return more debug info
one_delta_deployment (eth_defi.one_delta.deployment.OneDeltaDeployment) –
intermediate_token_address (Optional[eth_typing.evm.HexAddress]) –
intermediate_pair_fee (int | None) –
- Returns
Expected quote token amount to receive
- Raises
TokenDetailError – If we have an issue with ERC-20 contracts
- Return type