VWAP only
What is this endpoint for?
This endpoint retrieves aggregated VWAP (volume-weighted average price) history for an instrument on an exchange.
Endpoint
https://<eu|us>.market-api.kaiko.io/v2/data/trades.v2/exchanges/{exchange}/{instrument_class}/{instrument}/aggregations/vwapPath Parameters
region
Yes
Choose between eu and us.
Query Parameters
end_time
No
Ending time in ISO 8601 (exclusive). Automatically included in continuation tokens.
interval
No
The interval parameter is suffixed with s, m, h or d to specify seconds, minutes, hours or days, respectively.
Any arbitrary value between one second and one day can be used, as long as it sums up to a maximum of 1 day. The suffixes are s (second), m (minute), h (hour) and d (day).
Default 1d.
page_size
No
(min: 1, default: 100, max: 100000). See Pagination Automatically included in continuation tokens.
start_time
No
Starting time in ISO 8601 (inclusive). Automatically included in continuation tokens.
sort
No
Return the data in ascending (asc) or descending (desc) order.
Default: desc
Automatically included in continuation tokens.
Fields
timestamp
Timestamp at which the interval begins.
price
VWAP. null when no trades reported.
Request examples
curl --compressed -H 'Accept: application/json' -H 'X-Api-Key: <client-api-key>' \
'https://us.market-api.kaiko.io/v2/data/trades.v1/exchanges/cbse/spot/btc-usd/aggregations/vwap'##### 1. Import dependencies #####
import requests
import pandas as pd
##### 2. Choose the value of the query's parameters #####
# ---- Required parameters ---- #
exchange = "cbse"
instrument_class = "spot"
pair = "btc-usd" #called "instrument" in the documentation
# ---- Optional parameters ---- #
interval = "1d"
sort = "desc"
page_size = 100
start_time= "2023-01-01T00:00:00Z"
end_time= "2023-12-31T23:59:59Z"
# ---- API key configuration ---- #
api_key = "YOUR_API_KEY"
##### 3. Get the data #####
# ---- Function to run an API call ---- #
# Get the data in a dataframe --------- #
def get_kaiko_data(api_key: str, exchange: str, pair: str, instrument_class: str, start_time: str, end_time: str, interval: str, sort: str, page_size: int):
headers = {'Accept': 'application/json', 'X-Api-Key': api_key}
url = f'https://us.market-api.kaiko.io/v2/data/trades.v1/exchanges/{exchange}/{instrument_class}/{pair}/aggregations/vwap'
params = {
"start_time": start_time,
"end_time": end_time,
"sort": sort,
"page_size": page_size,
"interval": interval
}
try:
res = requests.get(url, headers=headers, params=params)
res.raise_for_status()
data = res.json()
if 'data' not in data:
print("No data returned.")
return pd.DataFrame()
df = pd.DataFrame(data['data'])
# Handle pagination with continuation token
while 'next_url' in data:
next_url = data['next_url']
if next_url is None:
break
res = requests.get(next_url, headers=headers)
res.raise_for_status()
data = res.json()
if 'data' in data:
df = pd.concat([df, pd.DataFrame(data['data'])], ignore_index=True)
return df
except requests.exceptions.RequestException as e:
print(f"API request error: {e}")
return pd.DataFrame()
# ---- Get the data ---- #
df = get_kaiko_data(api_key=api_key, exchange=exchange, pair=pair, instrument_class=instrument_class, start_time=start_time, end_time=end_time ,interval=interval, sort=sort, page_size=page_size)Response example
{
"query": {
"page_size": 100,
"exchange": "cbse",
"instrument_class": "spot",
"instrument": "btc-usd",
"interval": "1d",
"sort": "desc",
"aggregation": "vwap",
"data_version": "v1",
"commodity": "trades",
"request_time": "2020-11-12T16:52:36.988Z"
},
"time": "2020-11-12T16:52:37.114Z",
"timestamp": 1605199957114,
"data": [
{
"timestamp": 1605139200000,
"price": "15879.385939106618"
},
{
"timestamp": 1605052800000,
"price": "15664.643871798791"
},
/* ... */
],
"result": "success",
"continuation_token": "55qoNvASfrVdCIjrF8Ygw6TVJ4yamzUyeL9QXAmvWZZur3iaKoPcVBW1V4unNJi2zMjojbsYr9Pgt9XFCUpnAiuBiECm8X4cedvYc9t2WxHXnHKjgAp2wRAeV8ZPUSj8WNgpWTCBVymGaQZPj3oMDZwVeCPyuTLFdVPfTXVjZA94BtHeBmghoPv92JtWxN3yRvCkrw79hJBu",
"next_url": "https://<eu|us>.market-api.kaiko.io/v2/data/trades.v1/exchanges/cbse/spot/btc-usd/aggregations/vwap?continuation_token=55qoNvASfrVdCIjrF8Ygw6TVJ4yamzUyeL9QXAmvWZZur3iaKoPcVBW1V4unNJi2zMjojbsYr9Pgt9XFCUpnAiuBiECm8X4cedvYc9t2WxHXnHKjgAp2wRAeV8ZPUSj8WNgpWTCBVymGaQZPj3oMDZwVeCPyuTLFdVPfTXVjZA94BtHeBmghoPv92JtWxN3yRvCkrw79hJBu",
"access": {
"access_range": {
"start_timestamp": 1546300800000,
"end_timestamp": 1577836800000
},
"data_range": {
"start_timestamp": 1417391000000,
"end_timestamp": 1577836800000
}
}
}Last updated
Was this helpful?
