velora.quote
Documentation for eth_defi.velora.quote Python module.
Fetching Velora (ParaSwap) price quotes.
See Velora API documentation for more details.
Functions
|
Fetch a Velora price quote for a given token pair. |
Classes
Velora price quote response. |
- class VeloraQuote
Bases:
objectVelora price quote response.
Contains the optimal route and pricing information for a swap.
Example response data:
{"blockNumber": 12345678, "network": 1, "srcToken": "0x...", "srcDecimals": 18, "srcAmount": "1000000000000000000", "destToken": "0x...", "destDecimals": 6, "destAmount": "3500000000", "bestRoute": [...], "gasCostUSD": "5.93", "contractAddress": "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57", "contractMethod": "multiSwap", "srcUSD": "3500.00", "destUSD": "3500.00"}
- buy_token: eth_defi.token.TokenDetails
Token we are going to receive (token out)
- sell_token: eth_defi.token.TokenDetails
Token we are losing (token in)
- data: dict
Raw data from Velora /prices endpoint (the priceRoute)
This is passed to the /transactions endpoint to build the swap tx.
- get_buy_amount()
Get the buy amount from the quote.
- Returns
Amount of buy token we will receive (human-readable decimals)
- Return type
- get_sell_amount()
Get the sell amount from the quote.
- Returns
Amount of sell token we will spend (human-readable decimals)
- Return type
- get_price()
Get the price implied by the quote (buy amount / sell amount).
- Returns
Price as buy_token per sell_token
- Return type
- get_gas_cost_usd()
Get estimated gas cost in USD.
- Returns
Gas cost in USD or None if not available
- Return type
decimal.Decimal | None
- __init__(buy_token, sell_token, data)
- Parameters
buy_token (eth_defi.token.TokenDetails) –
sell_token (eth_defi.token.TokenDetails) –
data (dict) –
- Return type
None
- fetch_velora_quote(from_, buy_token, sell_token, amount_in, api_timeout=datetime.timedelta(seconds=30), partner=None, max_impact=None)
Fetch a Velora price quote for a given token pair.
This calls the Velora /prices endpoint to get the optimal route and pricing for a swap.
Example:
from decimal import Decimal from eth_defi.token import fetch_erc20_details from eth_defi.velora.quote import fetch_velora_quote weth = fetch_erc20_details(web3, "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1") usdc = fetch_erc20_details(web3, "0xaf88d065e77c8cC2239327C5EDb3A432268e5831") quote = fetch_velora_quote( from_=vault_address, buy_token=usdc, sell_token=weth, amount_in=Decimal("0.1"), ) print(f"Price: {quote.get_price()}") print(f"Will receive: {quote.get_buy_amount()} USDC")
- Parameters
from – Address that will execute the swap (for routing optimisation)
buy_token (eth_defi.token.TokenDetails) – Token to receive (destination token)
sell_token (eth_defi.token.TokenDetails) – Token to sell (source token)
amount_in (decimal.Decimal) – Amount of sell_token to swap (human-readable decimals)
api_timeout (datetime.timedelta) – API request timeout
partner (str | None) – Partner name for analytics tracking
max_impact (int | None) – Maximum price impact threshold percentage (default 15%)
from_ (Union[eth_typing.evm.HexAddress, str]) –
- Returns
Quote containing route and pricing information
- Raises
VeloraAPIError – If the API returns an error
- Return type