# Borrows, repayments, liquidations, and withdrawals

## What is this endpoint for?

This endpoint returns transactions (borrows, repayments, withdrawals, deposits and liquidations) registered on-chain, for the main L\&B protocols.

Learn about our methodologies for [DEX data](https://25446524.fs1.hubspotusercontent-eu1.net/hubfs/25446524/Case%20Studies%20%2B%20Data%20Gudies/DEX%20Methodology.pdf) and [Uniswap V3](https://25446524.fs1.hubspotusercontent-eu1.net/hubfs/25446524/Factsheets%20and%20Methodologies/Uniswap_V3_snapshot_Dec22.pdf).

### Endpoint

{% code overflow="wrap" %}

```http
https://eu.market-api.kaiko.io/v2/data/lending.v1/events
```

{% endcode %}

### Parameters

<table><thead><tr><th>Parameter</th><th width="95">Required</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td><code>blockchain</code></td><td>No</td><td>Should be one or several of the currently supported blockchains. <br><br>See <a data-mention href="/pages/a2ImeIv5a9wmXExkWX8W">/pages/a2ImeIv5a9wmXExkWX8W</a></td><td><code>ethereum</code></td></tr><tr><td><code>protocol</code></td><td>No</td><td>Should be one or several of the currently supported L&#x26;B protocols.</td><td><code>aav1,aav2</code></td></tr><tr><td><code>user_address</code></td><td>No</td><td>Filter on a specific wallet addresses (comma separated).</td><td><code>0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045</code></td></tr><tr><td><code>live</code></td><td>No</td><td>Shows the data as soon as the block is validated. <br><br>(Default: <code>false</code>, in case of block reorganization).</td><td><code>true</code></td></tr><tr><td><code>tx_hash</code></td><td>No</td><td>Filter on a specific transaction hash.</td><td><code>0xe68b84740**</code></td></tr><tr><td><code>asset</code></td><td>No</td><td>L&#x26;B events including the requested token. Default: all available tokens.</td><td><code>weth or weth,usdt,usdc</code></td></tr><tr><td><code>type</code></td><td>No</td><td>Event type: borrow, deposit, withdraw, repayment or liquidation.</td><td><code>borrow,withdraw</code></td></tr><tr><td><code>block_number</code></td><td>No</td><td>Block height.</td><td><code>10795593</code></td></tr><tr><td><code>start_block</code></td><td>No</td><td>Starting block height (inclusive).</td><td><code>129870</code></td></tr><tr><td><code>end_block</code></td><td>No</td><td>Ending block height (inclusive).</td><td><code>130000</code></td></tr><tr><td><code>start_time</code></td><td>No</td><td>Starting time in ISO 8601 (inclusive).</td><td><code>2022-04-01T00:00:00.000Z</code></td></tr><tr><td><code>end_time</code></td><td>No</td><td>Ending time in ISO 8601 (inclusive).</td><td><code>2022-05-01T00:00:00.000Z</code></td></tr><tr><td><code>sort</code></td><td>No</td><td>Returns the data in ascending or descending order.<br><br>Default: <code>desc</code>.</td><td><code>ascending</code></td></tr><tr><td><code>page_size</code></td><td>No</td><td>Number of snapshots to return data for. (default: 100, min: 1, max: 1000). <br><br>See <a data-mention href="/pages/mP3amLsYqKTsrRBoblxX">/pages/mP3amLsYqKTsrRBoblxX</a></td><td><code>1000</code></td></tr></tbody></table>

### Fields

| Field              | Description                                                      | Example                                      |
| ------------------ | ---------------------------------------------------------------- | -------------------------------------------- |
| `blockchain`       | The blockchain on which the transaction happened.                | `ethereum`                                   |
| `block_number`     | The height of the block in which the transaction happened.       | `16025918`                                   |
| `datetime`         | The timestamp of the block in which the transaction happened.    | `1669124591`                                 |
| `transaction_hash` | Transaction hash                                                 | ---                                          |
| `log_index`        | Log index of the transaction                                     | `152`                                        |
| `protocol`         | Code of the L\&B protocol.                                       | `aave/v2`                                    |
| `type`             | Event type: Borrow, deposit, withdraw, repayment or liquidation. | `borrow`, `deposit`, etc                     |
| `user_address`     | Address of the user.                                             | `0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045` |
| `asset_symbol`     | Symbol of the underlying asset.                                  | `crv`                                        |
| `asset_address`    | Address of the underlying asset.                                 | `0xd533a949740bb3306d119cc777fa900ba034cd52` |
| `asset_decimals`   | Decimals of the underlying asset.                                | `18`                                         |
| `receipt_symbol`   | Symbol of the receipt asset.                                     | `acrv`                                       |
| `receipt_address`  | Address of the receipt asset.                                    | `0x8dae6cb04688c62d939ed9b68d32bc62e49970b1` |
| `receipt_decimals` | Decimals of the receipt asset.                                   | `18`                                         |
| `amount`           | Amounts of the borrowed token.                                   | `299894.78`                                  |
| `metadata`         | Metadata linked to the event type and protocol.                  | More information below.                      |

### Metadata information

**Borrow event:**

| Field            | Description                                                                          | Example                                      |
| ---------------- | ------------------------------------------------------------------------------------ | -------------------------------------------- |
| `amount_receipt` | Amounts of the receipt token.                                                        | `299899`                                     |
| `rate`           | Borrow rate (at the event level or at the contract level depending on the protocol). | `0.02820253961814756`                        |
| `rate_type`      | Stable (1) or Variable (2)                                                           | `1` or `2`                                   |
| `on_behalf_of`   | The address of user who will incur the debt.                                         | `0xeffc18fc3b7eb8e676dac549e0c693ad50d1ce31` |

**Deposit event:**

| Field            | Description                                       | Example                                      |
| ---------------- | ------------------------------------------------- | -------------------------------------------- |
| `amount_receipt` | Amounts of the receipt token.                     | `299899`                                     |
| `rate`           | Supply rate of the overall lending pool.          | `0.000203088325657998768898798`              |
| `on_behalf_of`   | The address that will receive the receipt tokens. | `0xeffc18fc3b7eb8e676dac549e0c693ad50d1ce31` |

**Withdraw event:**&#x20;

| Field            | Description                                         | Example                                      |
| ---------------- | --------------------------------------------------- | -------------------------------------------- |
| `amount_receipt` | Amounts of the receipt token.                       | `299899`                                     |
| `on_behalf_of`   | The address that will receive the underlying token. | `0xeffc18fc3b7eb8e676dac549e0c693ad50d1ce31` |

**Repayment event**

| Field              | Description                                  | Example                                      |
| ------------------ | -------------------------------------------- | -------------------------------------------- |
| `amount_receipt`   | Amounts of the receipt token.                | `299899`                                     |
| `on_behalf_of`     | The address of user who will incur the debt. | `0xeffc18fc3b7eb8e676dac549e0c693ad50d1ce31` |
| `borrow_rate_mode` | Stable (1) or Variable (2)                   | `1` or `2`                                   |

**Liquidation event**

<table><thead><tr><th width="263">Field</th><th width="247">Description</th><th>Example</th></tr></thead><tbody><tr><td><code>liquidation_debt_asset_symbol</code></td><td>Symbol of the debt asset.</td><td><code>renfil</code></td></tr><tr><td><code>liquidation_debt_asset_address</code></td><td>Address of the debt asset.</td><td><code>0xd5147bc8e386d91cc5dbe72099dac6c9b99276f5</code></td></tr><tr><td><code>liquidation_debt_asset_decimals</code></td><td>Decimals of the debt asset.</td><td><code>18</code></td></tr><tr><td><code>liquidation_debt_amount_in_asset</code></td><td>Amount of the debt asset.</td><td><code>1899</code></td></tr><tr><td><code>liquidation_caller_address</code></td><td>The address that triggered the liquidation transaction.</td><td><code>0xdfd3bd446f1b7fd96dc995126ee845af0b1254cd</code></td></tr><tr><td><code>receive_receipt_token</code></td><td>The liquidator chooses to receive the collateral's asset (False) or recept token (True).</td><td><code>True</code> or <code>False</code></td></tr><tr><td><code>liquidation_type</code></td><td>Debt (1) or Collateral (2)</td><td><code>1</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: KAIKO_API_KEY' \
  'https://us.market-api.kaiko.io/v2/data/lending.v1/events?blockchain=ethereum&start_time=2024-09-27T13:13:53.441Z&end_time=2024-09-29T13:13:53.441Z'
```

{% 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 ---- #
blockchain = "ethereum" 
protocol = "aav2"

# ---- Optional parameters ---- #
user_address = None
live = "false"
tx_hash = None
asset = "weth"
type = "borrow"
block_number = None
start_block = None
end_block = None
start_time = "2025-03-01T13:00:00Z"
end_time = None
sort = "desc"
page_size = 1000

# ---- 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, blockchain: str, protocol: str, user_address: str, live: str, tx_hash: str, asset: str, type: str, block_number: int, start_block: int, end_block: int, start_time: str, end_time: str, sort: str, page_size: int):
    headers = {'Accept': 'application/json', 'X-Api-Key': api_key}
    
    url = f'https://eu.market-api.kaiko.io/v2/data/lending.v1/events'
    params = {
        "blockchain": blockchain,
        "protocol": protocol,
        "user_address": user_address,
        "live": live,
        "tx_hash": tx_hash,
        "asset": asset,
        "type": type,
        "block_number": block_number,
        "start_block": start_block,
        "end_block": end_block,
        "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, blockchain=blockchain, protocol=protocol, user_address=user_address, live=live, tx_hash=tx_hash, asset=asset, type=type, block_number=block_number, start_block=start_block, end_block=end_block, start_time=start_time, end_time=end_time, sort=sort, page_size=page_size)
print (df)
```

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

### Response example

```json
{
  "query": {
        "blockchain": "*",
        "block_number": "*",
        "asset": "*",
        "user_address": "*",
        "tx_hash": "*",
        "type": "*",
        "start_time": "*",
        "end_time": "*",
        "protocol": "*",
        "sort": "descending",
        "page_size": "1000",
        "start_block": "*",
        "end_block": "*"
    },
    "time": "2022-05-17T14:26:27.274Z",
    "timestamp": 1652797587,
    "data":
    [
        {
            "blockchain": "ethereum",
            "block_number": 16025918,
            "datetime": 1669124591,
            "transaction_hash":"0xa49cfa9c026e728614ca0bdf7272eaaad5b3dd8881fd263ea19ef7d648d9c941",
            "exchange_code": "aave/v2",
            "type": "repayment",
            "user_address": "0x4f381fb46dfde2bc9dcae2d881705749b1ed6e1a",
            "asset_symbol": "crv",
            "asset_address": "0xd533a949740bb3306d119cc777fa900ba034cd52",
            "asset_decimals": 18,
            "receipt_symbol": "acrv",
            "receipt_address": "0x8dae6cb04688c62d939ed9b68d32bc62e49970b1",
            "receipt_decimals": 18,
            "amount": 299894.78,
            "metadata": {
                "borrowRateMode": 2,
                "amountInReceiptAsset": "299894.77",
                "onBehalfOf": "0x4f381fb46dfde2bc9dcae2d881705749b1ed6e1a"
            }
        }
        /* ... */
    ],
    "continuation_token": "xxx",
    "next_url": "https://eu.market-api.kaiko.io/v2/data/lending.v1/events?continuation_token=xxx"
}
```


---

# 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/borrows-repayments-liquidations-and-withdrawals.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.
