> For the complete documentation index, see [llms.txt](https://docs.kaiko.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kaiko.com/rest-api/monitoring-solutions/kaiko-blockchain-monitoring/bitcoin-wallets/balances.md).

# Balances

## What is this endpoint for?

This endpoint offers in-depth insights into Bitcoin wallets including transfers and wallet balances over time.

### Endpoint

{% code overflow="wrap" %}

```http
https://us.market-api.kaiko.io/v2/data/wallet.v1/audit
```

{% endcode %}

### Parameters

<table><thead><tr><th>Parameter</th><th data-type="checkbox">Required</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td><code>blockchain</code></td><td>true</td><td>Always <code>bitcoin</code>.</td><td><code>bitcoin</code></td></tr><tr><td><code>sort</code></td><td>false</td><td>The sorting order for the results.</td><td><code>asc</code> or <code>desc</code></td></tr><tr><td><code>page_size</code></td><td>false</td><td><p>Number of results to return data for. (max: 5000).</p><p>See <a href="https://docs.kaiko.com/kaiko-rest-api/general/getting-started/pagination">Pagination</a></p></td><td><code>100</code></td></tr><tr><td><code>start_time</code></td><td>false</td><td>Starting time in ISO 8601 (inclusive).</td><td><code>2022-05-01T00:00:00.000Z</code></td></tr><tr><td><code>end_time</code></td><td>false</td><td>Ending time in ISO 8601 (inclusive).</td><td><code>2022-05-01T00:00:00.000Z</code></td></tr><tr><td><code>transaction_hash</code></td><td>false</td><td>The transaction hash to filter on.</td><td><code>5ae688ab08139338e3024e150339ffa94c9d2ba23f38d0838025a41dc2fac3e6</code></td></tr><tr><td><code>user_address</code></td><td>false</td><td>The address to filter on.</td><td><code>bc1qm8ktha9m745u2gh54kprk72eu9t6n5xa2adckn</code></td></tr></tbody></table>

### Fields

| Field                        | Description                                                                                                                                                             | Example                                                            |
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| `blockchain`                 | Blockchain name.                                                                                                                                                        | `bitcoin`                                                          |
| `block_number`               | The height of the block.                                                                                                                                                | `871899`                                                           |
| `timestamp`                  | The timestamp of the block.                                                                                                                                             | `1732536300000000000`                                              |
| `address`                    | The address on which the row is focused.                                                                                                                                | `bc1qhyar38j6catjs8y30naptzrs8jhgudhzcv8s98`                       |
| `transaction_hash`           | Transaction hash.                                                                                                                                                       | `e84b146c3f26545b525772a38425513f36a1738bfbb49a474aefe14a8c6d7903` |
| `transaction_id`             | Transaction ID.                                                                                                                                                         | `334480d40ca84435bf440da99e9454cca25d06163996cd9a6ba4b517b9da1608` |
| `transaction_type`           | <p>Transaction type.<br><br><strong>See information</strong> <a href="#possible-values-for-the-field-transaction_type"><strong>below</strong></a><strong>.</strong></p> | `witness_v0_keyhash`                                               |
| `transaction_index`          | The index of the transaction.                                                                                                                                           | `4695`                                                             |
| `internal_transaction_index` |                                                                                                                                                                         | `1`                                                                |
| `token_symbol`               | Symbol of the token or coin transfered                                                                                                                                  | `BTC`                                                              |
| `direction`                  | Inflow or outflow from the user\_address.                                                                                                                               | `out`                                                              |
| `amount`                     | Amount of asset transfered.                                                                                                                                             | `0.0022931`                                                        |
| `amount_usd`                 | Amount of asset transferred in usd.                                                                                                                                     | `225.6601111753002`                                                |
| `balance_after`              | Wallet balance for the user\_address for this asset.                                                                                                                    | `0`                                                                |
| `balance_after_usd`          | Wallet balance for the user\_address for this asset in usd.                                                                                                             | `0`                                                                |

### Request example

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

```url
curl --compressed -H "Accept: application/json" -H "X-Api-Key: <client-api-key>" \
  "https://eu.market-api.kaiko.io/v2/data/wallet.v1/audit?blockchain=bitcoin"
```

{% 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 = "bitcoin" 

# ---- Optional parameters ---- #
start_time = "2022-05-01T00:00:00.000Z"
end_time = "2022-30-01T00:00:00.000Z"
page_size = 100
sort = "desc"
transaction_hash = None
user_address = "1FfmbHfnpaZjKFvyi1okTjJJusN455paPH"

# ---- 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, start_time: str, end_time: str, page_size: int, sort: str, transaction_hash: str, user_address: str):
    headers = {'Accept': 'application/json', 'X-Api-Key': api_key}
    
    url = f'https://us.market-api.kaiko.io/v2/data/wallet.v1/audit'
    params = {
        "blockchain": blockchain,
        "start_time": start_time,
        "end_time": end_time,
        "page_size": page_size,
        "sort": sort,
        "transaction_hash": transaction_hash,
        "user_address": user_address
    }

    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, start_time=start_time, end_time=end_time, page_size=page_size, sort=sort, transaction_hash=transaction_hash, user_address=user_address)
print (df)
```

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

### Response example

```json
{
    "query":
    {
        "live": "False",
        "start_time": "2024-01-01T00:00:00.000Z",
        "end_time": "2024-01-02T00:00:00.000Z",
        "start_block": 0,
        "end_block": 0,
        "page_size": 100,
        "sort": "0",
        "data_version": "v1",
        "commodity": "wallet_data",
        "request_time": "2024-01-01T00:00:00.000Z"
    },
    "time": "2024-01-01T00:00:00.000Z",
    "timestamp": 1732536300000,
    "access":
    {
        "access_range":
        {
            "start_timestamp": 1073001600000,
            "end_timestamp": "None"
        },
        "data_range":
        {
            "start_timestamp": "None",
            "end_timestamp": "None"
        }
    },
    "data":
    [
        {
            "blockchain": "bitcoin",
            "block_number": 871899,
            "timestamp": 1732536300000000000,
            "address": "bc1qt42fgv262u3d2qvpmwecpxdwfmxpjug6mxn532",
            "transaction_hash": "e84b146c3f26545b525772a38425513f36a1738bfbb49a474aefe14a8c6d7903",
            "transaction_id": "334480d40ca84435bf440da99e9454cca25d06163996cd9a6ba4b517b9da1608",
            "transaction_type": "witness_v0_keyhash",
            "transaction_index": 4695,
            "internal_transaction_index": 0,
            "token_symbol": "BTC",
            "direction": "in",
            "amount": 0.00228863,
            "amount_usd": 225.22022599935772,
            "balance_after": 1.06076911,
            "balance_after_usd": 104388.50259209116
        },
        /* ... */
    ],
    "continuation_token": "xxx",
    "next_url": "https://us.market-api.kaiko.io/v2/data/wallet.v1/audit?continuation_token=xxx"
    }
}
```

### **Possible values for the field `transaction_type`:**

| Value                   |
| ----------------------- |
| `minerReward`           |
| `multisig`              |
| `pubkey`                |
| `pubkeyhash`            |
| `scripthash`            |
| `witness_unknown`       |
| `witness_v0_keyhash`    |
| `witness_v0_scripthash` |
| `witness_v1_taproot`    |
| `nulldata`              |
| `nonstandard`           |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.kaiko.com/rest-api/monitoring-solutions/kaiko-blockchain-monitoring/bitcoin-wallets/balances.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
