# Derivative liquidation events

## What is this endpoint for?

This endpoint returns all derivative liquidation events for a given instrument on an exchange. It includes all details available for the event like price and position. Data is available for futures and perpetual futures.\
\
For exchange coverage, see [Cefi derivative markets](/coverage/cefi-derivative-markets.md).

### Endpoint

{% code overflow="wrap" %}

```url
https://{region}.market-api.kaiko.io/v2/data/liquidation.v1/trades/{exchange}/{instrument_class}/{instrument}
```

{% endcode %}

### Path Parameters

| Parameter          | Required? | Example                                                                                                                            |
| ------------------ | --------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `region`           | Yes       | <p>Choose between: <br><br><code>eu</code> <br><code>us</code></p>                                                                 |
| `exchange`         | Yes       | <p>Exchange <code>code</code>.<br><br>See <a data-mention href="/pages/QiW5iUvcyBF9RISFmZFV">/pages/QiW5iUvcyBF9RISFmZFV</a></p>   |
| `instrument_class` | Yes       | <p>Choose between : <br><br><code>future</code><br><code>perpetual-future</code></p>                                               |
| `instrument`       | Yes       | <p>Instrument <code>code</code>.<br><br>See <a data-mention href="/pages/8ywkQXfxfv1FjtyspEaU">/pages/8ywkQXfxfv1FjtyspEaU</a></p> |

### Query Parameters

<table><thead><tr><th width="163">Parameter</th><th width="98">Required</th><th>Description</th><th>Example</th></tr></thead><tbody><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><td><code>2025-01-23T00:01:00.000Z</code></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><td><code>2025-02-25T23:59:00.000Z</code></td></tr><tr><td><code>sort</code></td><td>No</td><td>Return the data in ascending (<code>asc</code>) or descending (<code>desc</code>) order. <br><br>Default: <code>desc</code></td><td><code>asc</code></td></tr><tr><td><code>page_size</code></td><td>No</td><td><p>See <a data-mention href="/pages/mP3amLsYqKTsrRBoblxX">/pages/mP3amLsYqKTsrRBoblxX</a><br><br>Default: <code>100</code></p><p>Maximum: <code>1000</code></p></td><td><code>500</code></td></tr></tbody></table>

### Fields

<table><thead><tr><th>Field</th><th width="281">Description</th><th>Example</th></tr></thead><tbody><tr><td><code>amount</code></td><td>The quantity, displayed in base currency.</td><td><code>0.113</code></td></tr><tr><td><code>amount_quote</code></td><td>The quantity, displayed in the quote asset.</td><td><code>9362.592400000001</code></td></tr><tr><td><code>amount_usd</code></td><td>The quantity, displayed in USD.</td><td><code>9359.689996356</code></td></tr><tr><td><code>price</code></td><td>The price at which the liquidation was executed, displayed in USD.</td><td><code>82854.8</code></td></tr><tr><td><code>rate</code></td><td>Rate used  to convert quote currency to USD. <br><br>For example:<br><br>1 USDT = 0.997 USD</td><td><code>0.99969</code></td></tr><tr><td><code>position_side</code></td><td>The position liquidated</td><td><code>long</code></td></tr><tr><td><code>timestamp</code></td><td>The timestamp provided by the exchange or the collection timestamp in Unix Timestamp (in milliseconds)</td><td><code>1741785829372000000</code></td></tr><tr><td><code>trade_id</code></td><td>Unique trade ID (unique to the exchange). In case the exchange does not provide an ID, we generate it ourselves.</td><td><code>d472cae0135..dfdh6_g</code></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/liquidation.v1/trades/bbit/perpetual-future/eth-usdt?start_time=2025-04-12T00:00:00Z&end_time=2025-04-12T08:00:00Z&page_size=10'
```

{% endcode %}
{% endtab %}

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

```python
##### 1. Import dependencies #####
import requests
import pandas as pd
from urllib.parse import urlencode

##### 2. Choose the value of the query's parameters #####
# ---- Required parameters ---- #
exchange = "bbit"
instrument_class = "perpetual-future"
instrument = "eth-usdt"

# ---- Optional parameters ---- #
page_size = 10
sort = "desc"
start_time = "2025-04-12T00:00:00Z"
end_time = "2025-04-12T08: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_liquidation_trades(api_key: str, exchange: str, instrument_class: str, instrument: str, 
                                 start_time: str, end_time: str, sort: str, page_size: int):
    headers = {'Accept': 'application/json', 'X-Api-Key': api_key}
    
    base_url = f'https://us.market-api.kaiko.io/v2/data/liquidation.v1/trades/{exchange}/{instrument_class}/{instrument}'
    params = {
        "start_time": start_time,
        "end_time": end_time,
        "sort": sort,
        "page_size": page_size
    }
    
    # Debug: Show the URL being generated
    query_string = urlencode(params)
    full_url = f"{base_url}?{query_string}"
    print(f"DEBUG - Making request to URL: {full_url}")
    print(f"DEBUG - Headers: {headers}")
    
    try:
        res = requests.get(base_url, headers=headers, params=params)
        
        # Debug: Show the actual URL that requests used
        print(f"DEBUG - Actual request URL: {res.url}")
        print(f"DEBUG - Response status code: {res.status_code}")
        
        res.raise_for_status() 
        data = res.json()
        
        if 'data' not in data:
            print("No data returned.")
            return pd.DataFrame() 
            
        df = pd.DataFrame(data['data'])
        print(f"DEBUG - Initial data fetch successful, got {len(df)} records")
        
        # Handle pagination with continuation token
        page_count = 1
        while 'next_url' in data:
            next_url = data['next_url']
            if next_url is None:
                break
                
            print(f"DEBUG - Fetching page {page_count + 1} with URL: {next_url}")
            res = requests.get(next_url, headers=headers)
            res.raise_for_status()
            data = res.json()
            
            if 'data' in data:
                new_records = len(data['data'])
                df = pd.concat([df, pd.DataFrame(data['data'])], ignore_index=True)
                print(f"DEBUG - Fetched additional {new_records} records, total now: {len(df)}")
                page_count += 1
            else:
                print("DEBUG - No more data in pagination response")
                break
        
        return df
    except requests.exceptions.RequestException as e:
        print(f"API request error: {e}")
        print(f"Response status code: {e.response.status_code if hasattr(e, 'response') else 'N/A'}")
        print(f"Response text: {e.response.text if hasattr(e, 'response') else 'N/A'}")
        return pd.DataFrame() 

# ---- Get the data ---- #
print("Starting API request...")
df = get_kaiko_liquidation_trades(
    api_key=api_key, 
    exchange=exchange,
    instrument_class=instrument_class,
    instrument=instrument,
    start_time=start_time, 
    end_time=end_time,
    sort=sort, 
    page_size=page_size
)
```

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

### Response example

````json
```json
{
   "query": {
      "exchange": "bbit",
      "instrument": "eth-usdt",
      "instrument_class": "perpetual-future",
      "commodity": "liquidationEvents",
      "request_time": "2025-04-04T11:58:32.545Z",
      "start_time": "2025-02-12T00:00:01.000Z",
      "start_timestamp": 1739318401000,
      "end_time": "2025-02-24T23:59:37.000Z",
      "end_timestamp": 1740441577000,
      "page_size": 10,
      "sort": "desc",
      "data_version": "v1"
   },
   "answer_time": "2025-04-04T11:58:32.554Z",
   "answer_timestamp": 1743767912554,
   "access": {
      "access_range": {
         "start_timestamp": 1688428800000,
         "end_timestamp": 2177539199000
      },
      "data_range": {
         "start_timestamp": null,
         "end_timestamp": null
      }
   },
   "data": [
      {
         "amount": 0.1,
         "amount_quote": 249.77100000000002,
         "amount_usd": 249.76370743089532,
         "price": 2497.71,
         "rate": 0.9999708029791101,
         "position_side": "long",
         "timestamp": 1740441553739,
         "trade_id": "376def42502a7a307b85d7ffdebec8c8c08990b19f6fb165e0f97c8fd058a1b2"
      },
      {
         "amount": 0.04,
         "amount_quote": 99.7556,
         "amount_usd": 99.75268743366291,
         "price": 2493.89,
         "rate": 0.9999708029791101,
         "position_side": "long",
         "timestamp": 1740441446020,
         "trade_id": "f1062a8c42743ffbddc3d129d65f1ae6848227b871361d6fd66f3bbbbb4b10da"
      },
        /*---*/
    ],
    */....
    
"continuation_token": "3RuQ1KYk3AEZTJXXqsaUMrdUKSYH4CVdGUFQCZC5pts7AYMafCjbnYSuedeLMFu72PsXKepcvdtpvZmNzXmotWV1ARAF8hJxLfaDXn75MmkN3zMq6ma9Ym",
   "next_url": "https://us.market-api.kaiko.io/v2/data/liquidation.v1/trades/bbit/perpetual-future/eth-usdt?continuation_token=3RuQ1KYk3AEZTJXXqsaUMrdUKSYH4CVdGUFQCZC5pts7AYMafCjbnYSuedeLMFu72PsXKepcvdtpvZmNzXmotWV1ARAF8hJxLfaDXn75MmkN3zMq6ma9Ym"
}
````


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.kaiko.com/rest-api/data-feeds/level-1-and-level-2-data/level-1-tick-level/derivative-liquidation-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
