Skip to main content

Prime REST API Pagination

The Coinbase Prime REST API uses cursor pagination for most requests that return arrays. Endpoints that support pagination have a cursor query parameter, for example List Portfolio Allocations.

Cursor pagination lets you fetch additional results after the current page of results, and is well suited for realtime data. To retrieve more results, subsequent requests should specify which direction to paginate based on the data previously returned.

The JSON response for all relevant endpoints includes a pagination object with cursor information. If your initial request returns a pagination value with a non-null next_cursor, you can retrieve the next page of results by sending the same request with the cursor=<next_cursor> query parameter appended. Repeat until is next_cursor=''.

Pagination Object in Response

next_cursorCursor to navigate to next page
sort_directionThe page sorting direction, either ASC (ascending) or DESC (descending)
has_nextA boolean flag indicating whether there is more data available to page through

Pagination Query Parameters

ParameterDescriptionDefault if not specified
cursorCursor to navigate to next page using next_cursor from response
sort_directionThe page sorting direction, either ASC (ascending) or DESC (descending)DESC


For example, if you make this request to get all orders in the month of January:

GET /v1/portfolios/85874114-c465-4df7-a1bd-e4b17b4d3ddf/orders?product_ids=BTC-USD&product_ids=ETH-USD&start_date=2022-01-01T00%3A00%3A00Z&end_date=2022-01-31T23%3A59%3A00Z

You might get a response with information such as:

{'orders': [...], 'pagination': {'next_cursor': '2022-01-08T20:26:28.122357Z', 'sort_direction': 'DESC', 'result_count': 324}}

In which case you should repeat your request adding the cursor=<next_cursor> such as:

GET /v1/portfolios/85874114-c465-4df7-a1bd-e4b17b4d3ddf/orders?product_ids=BTC-USD&product_ids=ETH-USD&start_date=2022-01-01T00%3A00%3A00Z&end_date=2022-01-31T23%3A59%3A00Z&cursor=2022-01-08T20:26:28.122357Z

Cursor pagination can be unintuitive at first. The cursor argument should not be confused with records ordered by chronology, using timestamps.

Most paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first. To get older information you would request next pages with cursor=<next_cursor>.

Was this helpful?