Pagination
The Liquidity Hub API supports offset pagination for operations that return multiple data objects in the response. For example, when you call theGET /quotes
, GET /trades
, or GET /balances
operations with a set of query parameters in the request, the response contains an array of data objects. It also includes the totalPages
, first
, last
, and totalElements
fields. If the value of the last
field is false
, it indicates that there are more data objects to fetch. In that case, you can increment the value of the pageNumber
query parameter by 1 in subsequent requests. Continue to make requests until the value of the last
field is true
, which indicates that you have retrieved all available pages of results.Tutorial
This tutorial explains how you can use pagination to retrieve all data objects returned by theGET /quotes
operation.
- Call the
GET /quotes
operation and receive a response containing an array ofQuote
objects. - Examine the value of the
last
field in the response body.- If
last
=true
, you have retrieved all available data objects. No further action is necessary. - If
last
=false
, there are more data objects retrieve. Increment the value of thepageNumber
query parameter by1
and call the endpoint again. For more information, see Retrieve subsequent pages of results.
- If
Call the GET /quotes
operation
Send a GET
request to the /quotes
endpoint, for example:curl -i -X GET \
'<base_url>/api/v0/quotes?startTime=2021-01-01T01:00:00.000Z&endTime=2021-01-01T01:30:00.000Z&pageSize=3&pageNumber=0' \
-H 'Authorization: Bearer <YOUR_TOKEN_HERE>'
startTime
and endTime
query parameters to specify a time period. The response will contain the list of quotes issued during that time period only. Additionally, you specify the following parameters for pagination:Query parameter | Description |
---|---|
pageSize | The number of data objects to return per page. In this case, you request 3 data objects per page. |
pageNumber | The sequence number of the page of results to retrieve. As the first page is numbered zero, specify 0 in the first request. Increment this number in subsequent requests to fetch more pages of results. |
Examine the response
You receive the following response from the/quotes
endpoint:{
"quotes": [
{
...
},
{
...
},
{
...
}
],
"first": true,
"last": false,
"totalElements": 18,
"totalPages": 6
}
Sorting order
The most recently issued quote is listed first.
Quote
objects that represent quotes issued during the time period specified in the request. The response also contains the following fields that provide pagination information:Parameter | Description |
---|---|
first | If true , indicates that the current page of results is the first page. |
last | If false , indicates that there are more pages of results to retrieve. If true , indicates that the current page of results is the last page. |
totalElements | The total number of response objects that match the query parameters you specified. |
totalPages | The total number of pages of response objects. In this case, there are 6 pages of results, starting with page number 0 . |
Retrieve subsequent pages of results
To make sure you have retrieved all the data objects that match your query parameters, call theGET /quotes
operation until last
= true
- that is until there are no more objects to retrieve. In the above response, the value of the last
field is false
, indicating that there are more pages of Quote
objects to retrieve.pageNumber
by 1
Increment To retrieve subsequent pages of results, increment the
pageNumber
query parameter value by 1 in your request. GET
request to the /quotes
endpoint with the following query parameters:Parameter | Value |
---|---|
startTime | 2021-01-01T01:00:00.000Z |
endTime | 2021-01-01T01:30:00.000Z |
pageSize | 3 |
pageNumber | 1 |
Request format
curl -i -X GET \
'<base_url>/api/v0/quotes?startTime=2021-01-01T01:00:00.000Z&endTime=2021-01-01T01:30:00.000Z&pageSize=3&pageNumber=1' \
-H 'Authorization: Bearer <YOUR_TOKEN_HERE>'
Process the data
Once you retrieve all available data objects, your integration can begin processing the data.
Errors and error handling
The/quotes
endpoint may return 400
, 404
, or 500
error codes. For more information, see Errors.