tofield in the /swap/quote response vary?
sellTokenis not set to
WETH), 0x API will always provide a quote that interfaces with the main exchange contract.
sellTokenis set to
ETH, 0x API will always provide a quote that interfaces with forwarder contract.
pricefield provides developers a sense of what the BEST price they could receive, denominated in
gauranteedPriceis the price that developers can expect in a WORST case scenario where all the fallback orders are utilized over the better priced orders.
guaranteedPriceis through the
slippagePercentageparameter. With on-chain sources, prices can vary between the quote being made and settlement. The
slippagePercentageprovides a "upper bound" to how much the price provided by these on-chain sources can slip and remain desirable by the developer.
slippagePercentagecontrols how much worse the price can be for the fallback orders provided in a 0x API quote which influences the
sellTokenis utilized, then any unused
sellTokenwill be refunded to the user.
buyAmountis used, the only guarantee is that at least the amount specified is bought. 0xAPI will not terminate early in the case where one order fills at a better price, so the user can in effect over buy the specified amount. This is somewhat amplified by usage of
slippagePercentagewhich underestimates the on-chain price by a percentage.
buyAmount(i.e Kyber), these sources are ignored when quoting for
buyAmountto get more deterministic behavior.
fastamount of gwei) and any associated fees with the specific liquidity source. By sampling through varying compositions of liquidity sources, 0x API selects the best set of orders to give you the best price. 0x API also creates another set of fallback orders to ensure that the quote can be executed by users.
valuefield. Since we recommended using a high gas price, in the event where the taker fills at a lower gas price, the excess was returned.
sellTokenbalance to execute the swap?
takerAddresshelp with catching issues?
takerAddressparameter, 0x API can provide a more bespoke quote and help catch revert issues:
takerAddressto execute the provided quote.
gasparameter in the quote will be an accurate amount of gas needed to execute the swap.
takerAddressexecuting the quote.
takerAddressto get the quote validated before provided to you, assuring that a number of revert cases will not occur.
valuefield) based on the supplied
fast). But if a gas price of 1 gwei was supplied and the user changes this to any higher amount, the transaction will fail as the
valuehas not been updated to reflect the new gas price for the protocol fee.
gasPriceparameter provided, or defaults to a
fastamount of gwei. When changing the gas price parameter from 1 to 8 gwei one can observe the change in routing.
FillResultsobject that returns the result of executing a 0x swap:
/swap/v1/sourcesto get the liquidity sources per chain. You will need to specify the root-endpoint for the chain you are interested in, for example, https://polygon.api.0x.org/swap/v1/sources for the Polygon Network or https://api.0x.org/swap/v1/sources for Ethereum Mainnet. See the 0x API SwapIntroductionfor a full list of endpoints we support.
buyTokenPercentageFeeparameters in a
/swapAPI request. Set a
buyTokenPercentageFeeon your DEX trades which represents the percentage (between 0 - 1.0) of the
buyAmount(tokens being received) that should be attributed to
feeRecipient(your wallet) as an affiliate fee. Details about these parameters can be found in GET /swap/v1/quote.