Price slippage (aggregation)
What is this endpoint for?
This endpoint returns the average price slippage for the requested period. Read more about how the aggregation period works here: .
Endpoint
https://us.market-api.kaiko.io/v2/data/order_book_snapshots.v1/exchanges/{exchange}/{instrument_class}/{instrument}/ob_aggregations/slippagePath 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 1h.
page_size
No
Number of snapshots to return data for. (default: 10, max: 100). See Pagination Automatically included in continuation tokens.
sort
No
Return the data in ascending asc or descending desc order. Default desc
Automatically included in continuation tokens.
start_time
No
Starting time in ISO 8601 (inclusive). Automatically included in continuation tokens.
slippage
No
Order size (in quote asset) for which to calculate the percentage of slippage. 
Default: 0. 
When null is returned, not enough volume is present on the order book to execute the order.
slippage_ref
No
Price point for which to calculate slippage from. Either from the mid price (mid_price) or from the best bid/ask (best). 
Default: mid_price.
Fields
poll_timestamp
The timestamp at which the interval begins.
ask_slippage
The average percentage of price slippage for a market buy order over a specified interval.
bid_slippage
The average percentage of price slippage for a market sell order over a specified interval.
Request examples
 'https://us.market-api.kaiko.io/v2/data/order_book_snapshots.v1/exchanges/krkn/spot/btc-usd/ob_aggregations/slippage?page_size=10&slippage=100000&interval=1h'##### 1. Import dependencies #####
import requests
import pandas as pd
##### 2. Choose the value of the query's parameters #####
# ---- Required parameters ---- #
exchange = "krkn" 
instrument_class = "spot"
pair = "btc-usd" #called "instrument" in the documentation
# ---- Optional parameters ---- #
sort = "desc"
page_size = 100
start_time= "2025-01-03T00:00:00Z"
end_time= "2025-03-05T00:00:00Z"
slippage = 1000  
slippage_ref = "mid_price"  
# ---- 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, sort: str, page_size: int, slippage: int, slippage_ref: str):
    headers = {'Accept': 'application/json', 'X-Api-Key': api_key}
    
    url = f'https://us.market-api.kaiko.io/v2/data/order_book_snapshots.v1/exchanges/{exchange}/{instrument_class}/{pair}/ob_aggregations/slippage'
    params = {
        "start_time": start_time,
        "end_time": end_time,
        "sort": sort,
        "page_size": page_size,
        "slippage": slippage,
        "slippage_ref": slippage_ref
    }
    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 ,sort=sort, page_size=int(page_size), slippage=slippage, slippage_ref=slippage_ref)message = "hello world"
puts messageResponse example
{
    "query": {
        "page_size": 10,
        "exchange": "krkn",
        "instrument_class": "spot",
        "instrument": "btc-usd",
        "interval": "1h",
        "slippage": 100000,
        "slippage_ref": "mid_price",
        "sort": "desc",
        "aggregation": "slippage",
        "data_version": "v1",
        "commodity": "order_book_snapshots",
        "request_time": "2020-05-26T15:07:06.840Z"
    },
    "time": "2020-05-26T15:07:07.260Z",
    "timestamp": 1590505627260,
    "data": [
        {
            "poll_timestamp": 1590505200000,
            "ask_slippage": "0.00012513598764468878",
            "bid_slippage": "0.0003678539692963374"
        },
        {
            "poll_timestamp": 1590501600000,
            "ask_slippage": "0.00030969034268815156",
            "bid_slippage": "0.00024353107110561094"
        },
      /* ... */
    ],
    "result": "success",
    "access": {
        "access_range": {
            "start_timestamp": null,
            "end_timestamp": null
        },
        "data_range": {
            "start_timestamp": null,
            "end_timestamp": null
        }
    }
}Last updated
Was this helpful?
