# Tokens in a liquidity pool (Uniswap v3)

## What is this endpoint for?

The Uniswap V3 Liquidity Estimator offers insight into the token reserves on Uniswap V3.&#x20;

{% hint style="info" %}
This data shows the liquidity across all the price levels for a specific pair of tokens on Uniswap V3. Each price level has a range, which is shown as `lower_tick` (the lowest price of the level) and `upper_tick` (the highest price of the level). The data shows you the amount of tokens and liquidity available at each price level. \
\
We display all price-levels up to 10% either side of the current block price. The data is provided in a block-by-block granularity.\
\
Access the methodology [here](https://www.kaiko.com/reports/the-dex-data-handbook?p=2920\&preview=true\&preview_id=2920\&classic=true).
{% endhint %}

### Endpoint

{% code overflow="wrap" %}

```http
https://eu.market-api.kaiko.io/v2/data/liquidity.v1/snapshots/usp3
```

{% endcode %}

### Parameters

<table><thead><tr><th>Parameter</th><th width="103">Required</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td><code>pool_address</code></td><td>Yes</td><td>Pool address.</td><td><code>0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640</code></td></tr><tr><td><code>blockchain</code></td><td>No</td><td>Should be one of the currently supported blockchains.<br><br><a data-mention href="/pages/a2ImeIv5a9wmXExkWX8W">/pages/a2ImeIv5a9wmXExkWX8W</a></td><td><code>ethereum</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>start_block</code></td><td>No</td><td>Starting block height (inclusive).</td><td><code>19645000</code></td></tr><tr><td><code>end_block</code></td><td>No</td><td>Ending block height (inclusive).</td><td><code>19645010</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>price_range</code></td><td>No</td><td>The interval of price around the current price, in % (min: 0, default: 0.1, max: 0.2).</td><td><code>0.05</code></td></tr><tr><td><code>page_size</code></td><td>No</td><td>Number of snapshots to return data for. (default: 10, min: 1, max: 10). <br><br>See <a data-mention href="/pages/mP3amLsYqKTsrRBoblxX">/pages/mP3amLsYqKTsrRBoblxX</a></td><td><code>10</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.                                                      | `16028979`                                   |
| `pool_name`     | Name of the pool as it is written on the blockchain.                          | `USDC-WETH-0.001`                            |
| `pool_address`  | Address of the contract of the pool.                                          | `0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640` |
| `current_tick`  | The current tick at this block.                                               | `-58580`                                     |
| `current_price` | The current price at this block, normalized using the pool’s tokens decimals. | `0.0028577887443084`                         |
| `datetime`      | The timestamp of the block. In seconds.                                       | `1669161611`                                 |
| `snapshots`     | The snapshot of the liquidity at each tick of the pool.                       | See table below.                             |

**Field snapshots**

<table><thead><tr><th>Field snapshot</th><th width="278">Description</th><th>Example</th></tr></thead><tbody><tr><td><code>amount0</code></td><td>The amount of token0 in the specified tick range, normalized using the token0 decimals.</td><td><code>0</code></td></tr><tr><td><code>amount1</code></td><td>The amount of token1 in the specified tick range, normalized using the token1 decimals.</td><td><code>26.4381078606</code></td></tr><tr><td><code>amount</code></td><td>The amount of liquidity in the specified tick range.</td><td><code>1.7305248294559624e+23</code></td></tr><tr><td><code>lower_tick</code></td><td>The lower tick of the range.</td><td><code>-59580</code></td></tr><tr><td><code>upper_tick</code></td><td>The upper tick of the range.</td><td><code>-59520</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/liquidity.v1/snapshots/usp3?pool_address=0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640'
```

{% 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 ---- #
pool_address = "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640"

# ---- Optional parameters ---- #
blockchain = "ethereum"
live = "false"
start_block = None
end_block = None
start_time = "2022-04-01T00:00:00.000Z"
end_time = "2022-04-01T00:02:00.000Z"
sort = "desc"
price_range = None
page_size = 100

# ---- 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, pool_address: str, blockchain: str, live: str, 
                  start_block: str, end_block: str, start_time: str, 
                  end_time: str, sort: str, price_range: str, page_size: int):
    headers = {'Accept': 'application/json', 'X-Api-Key': api_key}
    
    url = f'https://eu.market-api.kaiko.io/v2/data/liquidity.v1/snapshots/usp3'
    params = {
        "pool_address": pool_address,
        "blockchain": blockchain,
        "live": live,
        "start_block": start_block,
        "end_block": end_block,
        "start_time": start_time,
        "end_time": end_time,
        "sort": sort,
        "price_range": price_range,
        "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:
            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:
        return pd.DataFrame() 

# ---- Get the data ---- #
df = get_kaiko_data(api_key=api_key, pool_address=pool_address, blockchain=blockchain, 
                   live=live, start_block=start_block, end_block=end_block, 
                   start_time=start_time, end_time=end_time, sort=sort, 
                   price_range=price_range, page_size=int(page_size))
```

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

### Response example&#x20;

```json
{
    "query": {
        "blockchain": "ethereum",
        "protocol": "usp3",
        "pool_address": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
        "start_block": "*",
        "end_block": "*",
        "start_time": "*",
        "end_time": "*",
        "sort": "descending",
        "page_size": "10",
        "live": "false",
        "price_range": "0.1"
    },
    "time": "2024-09-27T14:03:53.973Z",
    "timestamp": 1727445833,
    "data": [
        {
            "block_number": "20842364",
            "pool_name": "liquidity_pool",
            "pool_address": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
            "current_tick": "197507",
            "current_price": 0.00037773843033961135,
            "datetime": 1727444963,
            "blockchain": "ethereum",
            "exchange": "usp3",
            "snapshots": [
                {
                    "amount0": 0,
                    "amount1": 21.540770877363897,
                    "amount": 2335301572930716700,
                    "lower_tick": 196460,
                    "upper_tick": 196470
                },
                {
                    "amount0": 0,
                    "amount1": 21.58927177741234,
                    "amount": 2339389776616961000,
                    "lower_tick": 196470,
                    "upper_tick": 196480
                },
                ...
            ]
        },
        ...
     ],
    "continuation_token": "xxx",
    "next_url": "https://us.market-api.kaiko.io/v2/data/liquidity.v1/snapshots/usp3?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-2-aggregations/tokens-in-a-liquidity-pool/tokens-in-a-liquidity-pool-uniswap-v3.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.
