# Price slippage (snapshot)

{% hint style="info" %}
"Snapshots" show a point-in-time view generated every 30 seconds, whereas "aggregations" show an aggregation of all 30-second snapshots from the period requested.
{% endhint %}

## What is this endpoint for?

This endpoint uses our [raw-order-book-snapshot](https://docs.kaiko.com/rest-api/data-feeds/level-1-and-level-2-data/level-2-aggregations/raw-order-book-snapshot "mention") as source data and enhances its raw data with the Price Slippage metric.

Price Slippage calculates the potential slippage for a market buy order if it were placed at the time the Order Book Snapshot was taken.

### Endpoint

{% code overflow="wrap" %}

```http
https://us.market-api.kaiko.io/v2/data/order_book_snapshots.v1/exchanges/{exchange}/{instrument_class}/{instrument}/snapshots/slippage
```

{% endcode %}

### Path Parameters

<table><thead><tr><th width="203">Parameter</th><th>Required?</th><th>Description</th></tr></thead><tbody><tr><td><code>region</code></td><td>Yes</td><td>Choose between <code>eu</code> and <code>us</code>.</td></tr><tr><td><code>exchange</code></td><td>Yes</td><td><p>Exchange <code>code.</code> </p><p><br>See <a data-mention href="../../reference-data/basic-tier/exchange-codes">exchange-codes</a></p></td></tr><tr><td><code>instrument_class</code></td><td>Yes</td><td>Instrument <code>class</code>. <br><br>See <a data-mention href="../../reference-data/basic-tier/exchange-trading-pair-codes-instruments">exchange-trading-pair-codes-instruments</a></td></tr><tr><td><code>instrument</code></td><td>Yes</td><td>Instrument <code>code</code>.<br><br>See <a data-mention href="../../reference-data/basic-tier/exchange-trading-pair-codes-instruments">exchange-trading-pair-codes-instruments</a></td></tr></tbody></table>

### Query Parameters

<table><thead><tr><th width="240">Parameter</th><th width="109">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>continuation_token</code></td><td>No</td><td>See <a data-mention href="../../../general/getting-started/pagination">pagination</a></td></tr><tr><td><code>page_size</code></td><td>No</td><td>Number of snapshots to return data for. <br><br>Default: <code>10</code><br>Max: <code>100</code><br><br>See <a data-mention href="../../../general/getting-started/pagination">pagination</a><br> <br><em>Automatically included in continuation tokens.</em></td></tr><tr><td><code>sort</code></td><td>No</td><td>Return the data in ascending (asc) or descending (desc) order. <br><br>Default: <code>desc</code><br><br><em>Automatically included in continuation tokens.</em></td></tr><tr><td><code>start_time</code></td><td>No</td><td>Starting time in ISO 8601 (inclusive).<br><br><em>Automatically included in continuation tokens.</em></td></tr><tr><td><code>end_time</code></td><td>No</td><td>Ending time in ISO 8601 (exclusive).<br><br><em>Automatically included in continuation tokens.</em></td></tr><tr><td><code>slippage</code></td><td>No</td><td>Order size (in quote asset) for which to calculate the percentage of slippage. <br><br>Default: <code>0</code>. <br><br>When <code>null</code> is returned, not enough volume is present on the order book to execute the order.</td></tr><tr><td><code>slippage_ref</code></td><td>No</td><td>Price point for which to calculate slippage from. Either from the mid price (<code>mid_price</code>) or from the best bid/ask (<code>best</code>). <br><br>Default: <code>mid_price</code>.</td></tr></tbody></table>

### Fields

<table><thead><tr><th width="272">Field</th><th>Description</th></tr></thead><tbody><tr><td><code>poll_timestamp</code></td><td>The timestamp at which the raw data snapshot was taken.</td></tr><tr><td><code>poll_date</code></td><td>The date at which the raw data snapshot was taken.</td></tr><tr><td><code>timestamp</code></td><td>The timestamp provided by the exchange. <code>null</code> when not provided.</td></tr><tr><td><code>ask_slippage</code></td><td>The percentage price slippage for a market buy order placed at the time that the order book snapshot was taken.</td></tr><tr><td><code>bid_slippage</code></td><td>The percentage price slippage for a market sell order placed at the time that the order book snapshot was taken.</td></tr></tbody></table>

### Request examples

{% tabs %}
{% tab title="cURL" %}
{% code overflow="wrap" %}

```url
curl --compressed -H 'Accept: application/json' -H 'X-Api-Key: <client-api-key>' \
  https://us.market-api.kaiko.io/v2/data/order_book_snapshots.v1/exchanges/krkn/spot/btc-usd/snapshots/slippage?end_time=2019-12-09T00:00:00Z&slippage_ref=best&start_time=2019-12-01T00:00:00Z&slippage=1000000&page_size=10'
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code overflow="wrap" %}

```python
##### 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-03-03T00:00:00Z"
end_time= "2025-03-05T00:00:00Z"

# ---- 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):
    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}/snapshots/slippage'
    params = {
        "start_time": start_time,
        "end_time": end_time,
        "sort": sort,
        "page_size": page_size
    }

    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))
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Response example

{% code overflow="wrap" %}

```json
{
    "query": {
        "page_size": 10,
        "exchange": "krkn",
        "instrument_class": "spot",
        "instrument": "btc-usd",
        "slippage": 100000,
        "limit_orders": 0,
        "slippage_ref": "best",
        "sort": "desc",
        "metric": "slippage",
        "data_version": "v1",
        "commodity": "order_book_snapshots",
        "request_time": "2020-05-26T14:42:17.053Z"
    },
    "time": "2020-05-26T14:42:17.123Z",
    "timestamp": 1590504137123,
    "data": [
        {
            "poll_timestamp": 1590504124917,
            "poll_date": "2020-05-26T14:42:04.917Z",
            "timestamp": null,
            "ask_slippage": "0.0001057219873253085790064266041007855",
            "bid_slippage": "0.0001581287020485902479395059349031256"
        },
        {
            "poll_timestamp": 1590504075786,
            "poll_date": "2020-05-26T14:41:15.786Z",
            "timestamp": null,
            "ask_slippage": "0.00001534073225141691226479256404443437",
            "bid_slippage": "0.0002555856086571344339622641509433962"
        },
      /* ... */
    ],
    "result": "success",
    "continuation_token": "Z8Fj1yUWjj3uvv1U2d8fASeGLm4jZ4iHCopdsZLKUyDJE8KrBaDXwQQWXHJQxm",
    "next_url": "https://us.market-api.kaiko.io/v2/data/order_book_snapshots.v1/exchanges/cbse/spot/btc-usd/snapshots/slippage?continuation_token=Z8Fj1yUWjj3uvv1U2d8fASeGLm4jZ4iHCopdsZLKUyDJE8KrBaDXwQQWXHJQxm",
    "access": {
        "access_range": {
            "start_timestamp": null,
            "end_timestamp": null
        },
        "data_range": {
            "start_timestamp": null,
            "end_timestamp": null
        }
    }
}
```

{% endcode %}
