0x API hosts an Orderbook of 0x Limit Orders that anyone can provide liquidity to or take liquidity from
The 0x API is the liquidity and data endpoint for DeFi. It lets you access aggregated liquidity from tens of on-chain and off-chain decentralized exchange networks, across multiple blockchains. It comes with many parameters to customize your requests for your application and your users.
While the 0x Labs Team hosts a version of the 0x API (subject to the 0x Terms of Service), all the code is open source and available at the 0x-API GitHub repo. If you run into a problem, don't hesitate to open an issue.
We offer hosted versions for different Ethereum networks. Requests for more networks, and questions/feedback in general should be directed at our Discord. 0x API has an Orderbook on the following chains:
Binance Smart Chain
Each 0x HTTP API
pathis versioned independently using URI versioning. The format is:
For example, you can request
quoteendpoint in the
swappath. URLs not adhering to this format are not supported.
A major version bump occurs whenever a backwards incompatible change occurs to an
endpoint, in which case every
pathwill be on the next version. Old versions of the API will be deprecated and new features will be rolled out to them on a best-effort basis.
Requests that return potentially large collections are paginated and respond to the
Any endpoint that follows this convention will display the following:
This endpoint is paginated.
And will only document the objects in the
recordsfield. By default, a request returns page 1 with 20 orders. It is possible to change which page and how many records are returned per page via the query parameters. For example, to fetch page 3 with 50 records per page:
(Optional, defaults to "1") The page index (1-indexed) requested in the collection.
(Optional, defaults to "20") The amount of records to return per page. The maximum is "1000".
The page index (1-indexed) of returned in the response (same as request if provided).
The amount of
The total amount of
If a query provides an unreasonable (ie. too high)
perPagevalue, the response can return a validation error as specified in the errors section. If the query specifies a
pagethat does not exist (ie. there are not enough
records), the response will return an empty
Some interactions with 0x require or are improved by setting token allowances, or in other words, giving 0x's smart contracts permission to move certain tokens on your behalf. Some examples include -
- Submitting a 0x API quote selling ERC20 tokens, you will need to give an allowance to the contract address. This address can be found either as the value of
allowanceTargetreturned in the quote response or in the ExchangeProxy Address column in the "Addresses by Network" table below.
- Trading ERC20 tokens using the Exchange contract, you will have to give an allowance to the ERC20Proxy contract.
- Note: For swaps with "ETH" as sellToken, wrapping "ETH" to "WETH" or unwrapping "WETH" to "ETH" no allowance is needed, a null address of
0x0000000000000000000000000000000000000000is then returned instead.
The following table includes commonly used contract addresses. For a full list of our smart contract deployments address, see the0x Cheat Sheet .
Binance Smart Chain
Unless the spec defines otherwise, errors to bad requests should respond with HTTP 4xx or status codes.
Bad Request – Invalid request format
Too many requests - Rate limit exceeded
Internal Server Error
Server Error - Too many open connections
"reason": "Validation failed",
"reason": "Invalid address"
Order submission disabled
Address not supported
Value out of range
Invalid signature or hash
Invalid 0x order
Token is not supported
Field is invalid
This section outlines API JSON objects that are common to many endpoints.
A 0x Limit Order with additional fields and ready to be consumed by our tooling and sent to the 0x exchange proxy contract.
The address of the party that creates the order. The maker is also one of the two parties that will be involved in the trade if the order gets filled.
The address of the party that is allowed to fill the order. If set to a specific party, the order cannot be filled by anyone else. If left unspecified, anyone can fill the order.
The address of the ERC20 token the maker is selling to the taker.
The address of the ERC20 token the taker is selling to the maker.
The amount of makerToken being sold by the maker
The amount of takerToken being sold by the taker
Timestamp in seconds of when the order expires. Expired orders cannot be filled.
A value that can be used to guarantee order uniqueness. Typically it is set to a random number.
The address of the entity that will receive any fees stipulated by the order. This is typically used to incentivize off-chain order relay.
The staking pool to attribute the 0x protocol fee from this order. Set to zero to attribute to the default pool, not owned by anyone.
Amount of takerToken paid by the taker to the feeRecipient.
An advanced field that doesn't need to be set. It allows the maker to enforce that the order flow through some additional logic before it can be filled (e.g., a KYC whitelist) -- more on the ability to extend 0x later.
Address of the contract where the transaction should be sent, usually this is the 0x exchange proxy contract.
The ID of the Ethereum chain where the
A JSON object with the signature of the fields above using the private key of
A number representing the signature method used for signing the order, EIP712 (2) and EthSign (3) are supported.
A hexadecimal string with signature data.
A hexadecimal string with signature data.
An integer number with signature data.
- All requests and responses should be of "application/json" content type.
- All token amounts are sent in amounts of the smallest level of precision (base units). (e.g if a token has 18 decimal places, selling 1 unit of the token would show up as selling
1000000000000000000base units by this API).
- All addresses are sent as lower-case (non-checksummed) Ethereum addresses with the
- All parameters should use lowerCamelCase.