Each API request only returns a limited amount of records. To allow users to fetch large amounts of records some of our endpoints implement a system of pagination.
Paginated endpoints currently use cursor pagination. These endpoints will return a cursor next
with each request response. To get the next set of records, the API user has to include the returned cursor on the following API request.
Default time range
Each endpoint includes a default time range which (for example 30 days for Get swaps by pool ). If you want to query data outside of default time range, you need to explicitely provide:
- A start and end date: start_date and end_date
- A time range days and either one of start_date or an end_date
For example:
To paginate further, a user can specify a start_date and an end_date as follows:
/api/swaps/pool/0x5777d92f208679db4b9778590fa3cab3ac9e2168?network=ethereum&start_date=2022-11-01&end_date=2022-12-01
For example, calling the Get recent swaps endpoint:
https://services.blockpour.com/api/swaps/recent
Will return the 50 most recent swaps ordered from the most recent to the oldest:
"statusCode": 200,
"status": true,
"data": [
....,
{
"time": "2022-12-07T07:28:27.000Z",
"pair": "0x8072dcd2ec9d20b0cdacd1f596328711d906bfe7",
"token0": "0x5187816a80a61b67b9879aea87ea0890a493396b",
"token1": "0xc2132d05d31c914a87c6611c10748aeb04b58e8f",
"amount0": -216.06966141020132,
"amount1": 1.057698,
"amount_usd": "1.05777203886",
"slippage": 1.4386992810494261,
"receiver": "0x11ab72cbb42e24310f269c48f9d8355e437e3f63",
"tx": "0x36b50e1c23a6c7d3b803d2e43f9c5a615061272b17ddb3f2d6351a3370075cb4",
"price0": 0.0048955139372938335,
"price1": 1.00007,
"network": 137,
"token0_symbol": "CORIS",
"token1_symbol": "USDT",
"exchange": "0x5757371414417b8c6caad45baef941abc7d3ab32",
}
],
"next": "MTY3MDM5ODEwNywzOTEtMHgzNmI1MGUxYzIzYTZjN2QzYjgwM2QyZTQzZjljNWE2MTUwNjEyNzJiMTdkZGIzZjJkNjM1MWEzMzcwMDc1Y2I0"
}
The next set of recent swaps can be queried with:
https://services.blockpour.com/api/swaps/recent?next=MTY3MDM5ODEwNywzOTEtMHgzNmI1MGUxYzIzYTZjN2QzYjgwM2QyZTQzZjljNWE2MTUwNjEyNzJiMTdkZGIzZjJkNjM1MWEzMzcwMDc1Y2I0
This will return all swaps with a timestamp older than "2022-12-07T07:28:27.000Z"** (the oldest timestamp in the previous returned data).
Ordering
Ordering
Paginated endpoints only support cursors if the order is by time. If ordering by amountusd or amounts, it is recommended to use limits and start / end dates.
To get the largest 10 AAVE trades over the last 7 days by amountusd you can use the following query:
https://services.blockpour.com/api/swaps/token/AAVE?network=ethereum&sort=amount_usd&days=7&limit=10
To see more results, since there is no cursor, you can specify a larger limit to view more of the largest AAVE trades over 7 days. Alternatively, you can specify start_date and end_date with limits to control the number of largest trades for a token you want to fetch
Pagination Direction
By default or if you provide an end_date param, the data will paginate backwards meaning that each new response will return older records.
If you only provide a start_date, the API will paginate forward.
Example 1:
?start_date=2022-01-01&end_date=2022-01-02&limit=100
will return records from the most recent to the oldest. If there are more than 100 records, you can retrieve the next set of records by calling?start_date=2022-01-01&end_date=2022-01-02&limit=100&next={next}
where {next} is returned in the previous query result.Example 2:
?start_date=2022-01-01&limit=100
. There is no end_date so the API responses will be paginated forward. The API will return the records from the oldest (after2022-01-01T00:00:00Z
) to the most recent.
Code Example
const paginate = async () => {
let done = false
let next = ""
let baseUrl = 'https://services.blockpour.com/'
let endpoint = 'api/swaps'
const body = JSON.stringify({ "traders": ["0x6977e753e022f65ebeb170d8267b2ea54a431523"] })
const options = {
method: 'POST',
headers: {
accept: 'application/json',
'content-type': 'application/json',
authorization: 'PUT TOKEN HERE'
},
body
};
let url = new URL(endpoint, baseUrl);
let params = {
start_date: '2023-03-01',
end_date: '2023-03-10'
}
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));
let data = []
while (!done) {
if (next) url.searchParams.append("next", next)
let response = await fetch(url, options)
let result = await response.json()
next = result.next
if (result.data.length === 0) done = true
data.push(...result.data)
}
return data
}