0x API’s Smart Order Routing

Free Bitcoins: FreeBitcoin | BonusBitcoin

Coins Kaufen: Bitcoin.deAnycoinDirektCoinbaseCoinMama (mit Kreditkarte)Paxfull

Handelsplätze / Börsen: Bitcoin.de | KuCoinBinanceBitMexBitpandaeToro

Lending / Zinsen erhalten: Celsius NetworkCoinlend (Bot)

Cloud Mining: HashflareGenesis MiningIQ Mining


Integrate with 0x API here to see smart order routing in action!

More liquidity means better pricing for the end-user. With 0x API, we prioritize liquidity to maximize returns on quotes, even if it means having to venture outside of the 0x ecosystem. With the advent of the 0x Protocol’s ERC-20 bridge asset proxies, we now have the ability to fill against other on-chain decentralized exchanges (DEXes) through the 0x Exchange contract. Requesting a quote from 0x API will not only scan limit orders from the protocol’s networked liquidity, but will also check on-chain DEXes such as Uniswap, Curve, Oasis, and Kyber. The API’s order routing algorithm will then use this information to split your fills up across the different sources to maximize the overall return on your swap.

There’s a lot of diversity among existing DEX models, so liquidity can look very different between them. Some exchanges offer better rates but at high slippage while others offer worse rates for lower slippage. Below are real-world quotes taken from 2 DEXes to illustrate this common scenario.

A sampling of increasing ETH->DAI quotes from Oasis and Kyber.

What’s more, these markets continue to evolve with trading activity, making it difficult for a typical user to know where to get the best rate at any given moment. So simply providing the overall best source for a swap would be valuable, but 0x API goes a step further by also splitting your swap across different DEXes.

Larger area under curve = better output.

Because slippage often increases non-linearly with fill size, this approach allows us to keep the overall rate of a swap near optimum by incurring less slippage. The generated quote can then be passed into the 0x Exchange contract, which will perform all the trades in a single, atomic transaction.

Echoing the principles of the 0x Protocol, we rely on a mix of on-chain and off-chain components when generating swap quotes. Quotes are generated off-chain (via 0x API), to be consumed on-chain. In a high level overview of this process, we have three distinct phases: Sampling, Optimization, and Settlement.

We start by pulling relevant native orders from the 0x Mesh network and our exclusive market maker partners. We then use a custom contract to collect many quotes from each DEX for increasing fill sizes, up to the taker’s desired token amount. Critically, this contract also allows us to batch operations into a single RPC call. This keeps the API highly responsive.

Pooling all liquidity sources into an offline model.

Both native orders and DEX samples are then converted to “fill paths,” which are just directed acyclic graphs where each node represents a small fill on a DEX. The optimal solution is the (valid) combination of these fills that results in the greatest output token amount for a given input token amount. 0x API will intelligently merge each successive path with the next until we end up with a single, unified path with the highest overall return rate, accounting for fees/gas.

Merging quotes from different sources together to maximize the area under the curve.

The final optimized path is then converted into individual 0x orders. DEX fills are wrapped in “bridge orders,” which are orders we generate just-in-time to instruct the 0x Exchange contract to perform a trade against a DEX during settlement. 0x API encodes the entire call to the Exchange contract (which includes the orders to fill) as a hex blob which the taker can simply sign and submit to the blockchain. The Exchange contract then will fill each order sequentially until the required number of tokens have been bought or sold. During this process, gas tokens will also be burned to reduce the final transaction cost to the taker.

Joe Taker executing an on-chain swap for tokens A -> B, crafted by 0x-API.

And that’s it in a nutshell! Of course, the devil is in the details, so for a deeper dive into our routing algorithm, stop by the 0x API repo and the 0x monorepo, where all this code is open source.

We’re continuously working on ways to improve the performance of the quote service to provide the best pricing for users. Here are a few, related things on our immediate roadmap.

Free Bitcoins: FreeBitcoin | BonusBitcoin

Coins Kaufen: Bitcoin.deAnycoinDirektCoinbaseCoinMama (mit Kreditkarte)Paxfull

Handelsplätze / Börsen: Bitcoin.de | KuCoinBinanceBitMexBitpandaeToro

Lending / Zinsen erhalten: Celsius NetworkCoinlend (Bot)

Cloud Mining: HashflareGenesis MiningIQ Mining

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close