I was reading the documentation page about the /orders
endpoint
and couldn't find how they are sorted. It's not clear how to avoid requesting all pages to get new orders.
1 Answer
The endpoint is paginated and by default it returns page 1 with 20 orders. You can for instance change this behaviour setting the param page and perPage on the query: An example of fetching on page 2 a total of 50 orders https://api.0x.org/orderbook/v1/orders?makerToken=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2&page=2&perPage=50 .
If you like to inspect code, here you can check the handler that is called by that endpoint: https://github.com/0xProject/0x-api/blob/63fd378c3fd198fd1760cd684763956defccfb55/src/handlers/sra_handlers.ts#L49 as you can see you can pass page and perPage on the query, and filter by any field that the order supports. Looking at code, it seems it is not sorted.
-
it's a pity they didn't implement sorting. it's much to fetch new orders because of it. Jul 12, 2022 at 17:09