Pagination
For queries that result in a larger dataset than can be returned in a single response, a continuation_token
field is included. Calling the same endpoint again with the continuation_token
query parameter added will return the next result page. For convenience, a next_url
field is also included, containing a URL that can be called directly to get the next page. Paginated endpoints also takes a page_size
parameter that specifies the maximum number of items that should be included in each response. Only the first call should include page_size
, all subsequent calls should only use continuation_token
. Paginating over a request with version set to latest
will preserve the current version across subsequent pagination requests.
Parameters
continuation_token
No
page_size
No
Maximum number of records to return in one response
Browsing pages when using Python
The following script can be used to browse pages in Python. Make sure to update your trade_url
and X-Api-Key
.
import http.client
import json
conn = http.client.HTTPSConnection("us.market-api.kaiko.io")
endpoint = "/v2/data/trades.v1/spot_exchange_rate/btc/usd"
params = "?interval=1h&start_time=2024-09-01T00:00:00.000Z&end_time=2024-09-10T00:00:00.000Z"
headers = {
"X-Api-Key": "XXX",
"Accept": "application/json"
}
all_trades = []
next_url = endpoint + params
while next_url:
conn.request("GET", next_url, headers=headers)
response = conn.getresponse()
data = json.loads(response.read().decode("utf-8"))
all_trades.extend(data.get("data", []))
print(f"Fetched {len(data.get('data', []))} datapoints. Total: {len(all_trades)}")
next_url = data.get("next_url", "").replace("https://us.market-api.kaiko.io", "")
if not next_url:
break
conn.close()
print(f" datapoints fetched: {(all_trades)}")
Last updated
Was this helpful?