Pagination
The API implements cursor-based pagination for large collections, such as assets or markets. Those collections are split into pages that can be traversed by subsequently sending the cursor retrieved from previous responses.
Each cursor-paginated response will include the following information:
{
"cursor": {
"last": "eyJsYXN0SUQiOjUwM30K",
"hasMore": true
}
}
The
last
field contains the actual cursor value - a pointer to the next set of results.last
is always present, even for the last page of a collection. It's an opaque value.The
hasMore
boolean indicates whether there are more results remaining after the returned page. When a collection has been completely traversed, it will be set to false
.Every cursor-paginated endpoint accepts two optional parameters, in addition to those specific to the endpoint:
cursor
- The exact value of a previously received"cursor"."last"
field. If a value isn't passed, the first page of the collection will be returned.limit
- The amount of elements to be returned by the API. Each endpoint has an internal default limit (used when nolimit
parameter is specified) and a maximum limit allowed, both reflected in their specific documentation. It's possible to receive fewer results than the specifiedlimit
Passing an invalid
limit
(e.g negative numbers or strings) or cursor
(e.g. tempering its value) will result on a HTTP 404 Bad Request error.To correctly range over a paginated collection, initially make a request without specifying a
cursor
:curl https://api.cryptowat.ch/markets
If you don't want to use the default limit, you can specify one:
curl https://api.cryptowat.ch/markets?limit=100
Either way, after receiving the response, inspect the top level
cursor
object:{
"result": [],
"cursor": {
"last": "eyJsYXN0SUQiOjF9Cg==",
"hasMore": true
},
"allowance": {}
}
As seen by the
hasMore
field, there are more results to be requested. Take the last
value, and use it as cursor
for the next request:curl https://api.cryptowat.ch/markets?cursor=eyJsYXN0SUQiOjF9Cg==&limit=100
And that's it. If you want to fetch the entire collection, keep repeating the last step until you encounter a
hasMore
set to false
.This table describes the default & maximum limits unless specified by the
limit
parameter.Endpoint | Default Responses Limit | Maximum Responses |
---|---|---|
markets | 20,000 | 20,000 |
markets/prices | 20,000 | 20,000 |
markets/summaries | 20,000 | 20,000 |
pairs | 15,000 | 15,000 |
assets | 5,000 | 5000 |
Last modified 1yr ago