# Exchanges

## What is this endpoint for?

This endpoint helps inform exchange analysis with data such as total volume in USD, trades, the number of listed assets, and volume proportions by asset.\
\
The data aggregates all instruments available on the requested exchange. Only base assets are taken into consideration.&#x20;

### Endpoint

{% code overflow="wrap" %}

```http
https://us.market-api.kaiko.io/v2/data/analytics.v2/exchange_metrics
```

{% endcode %}

### Parameters

<table><thead><tr><th width="150">Parameter</th><th width="96">Required</th><th width="306">Description</th><th>Example</th></tr></thead><tbody><tr><td><code>exchange</code></td><td>Yes</td><td>The desired exchange <code>code</code>.<br><br>See <a data-mention href="/pages/QiW5iUvcyBF9RISFmZFV">/pages/QiW5iUvcyBF9RISFmZFV</a></td><td><code>cbse</code></td></tr><tr><td><code>start_time</code></td><td>Yes</td><td>Starting time in ISO 8601 (inclusive). First time at which we want to have  metrics.</td><td><code>2023-11-29T14:00:00.0000000Z</code></td></tr><tr><td><code>end_time</code></td><td>Yes</td><td>Ending time in ISO 8601 (exclusive). Last time at which we want to have exchange metrics.</td><td><code>2023-11-29T15:00:00.0000000Z</code></td></tr><tr><td><code>interval</code></td><td>Yes</td><td>The interval parameter is suffixed with <code>h</code> or <code>d</code> to specify hours or days, respectively.<br><br>Any arbitrary value between one second and one day can be used, as long as it sums up to a maximum of 1 day. The suffixes are <code>h</code> (hour) and <code>d</code> (day).<br><br> Default: <code>1h</code>.</td><td><code>1h</code></td></tr><tr><td><code>sources</code></td><td>No</td><td>If <code>true</code>, returns trading information detailed by pair. <br><br>Default: <code>false</code></td><td></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>Minimum: <code>1</code><br>Maximum: <code>100</code></p><p>Default: <code>10</code></p></td><td><code>100</code></td></tr><tr><td><code>sort</code></td><td>No</td><td>If <code>asc</code>, sort time-series in ascending. If desc, sort time-series in descending.<br><br>Default: <code>desc</code></td><td><code>asc</code></td></tr></tbody></table>

### Fields

| Field                    | Category         | Description                                                                   | Example                                                                                                                                                                                                                                                                                                                     |
| ------------------------ | ---------------- | ----------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `timestamp`              | Trading activity | Timestamp at which the interval begins.                                       | `2023-11-29T14:00:00.000Z`                                                                                                                                                                                                                                                                                                  |
| `total_volume_usd`       | Trading activity | Total volume in USD traded in the interval. 0 when no trades are reported.    | `139803179.89191553`                                                                                                                                                                                                                                                                                                        |
| `total_trade_count`      | Trading activity | Total trade count in the interval. 0 when no trades are reported.             | `121748`                                                                                                                                                                                                                                                                                                                    |
| `nb_listed_assets`       | Trading activity | Number of listed assets in the interval. 0 when no trades are reported.       | `235`                                                                                                                                                                                                                                                                                                                       |
| `nb_listed_pairs`        | Trading activity | Number of listed pairs in the interval. 0 when no trades are reported.        | `379`                                                                                                                                                                                                                                                                                                                       |
| `asset_volumes`          | Trading activity | Trading information details by asset.                                         | <p><code>\[{"asset\_code": "btc",</code><br><code>"asset\_trade\_count": 22772,</code><br><code>"asset\_total\_volume\_usd": 61612344.01769975,</code><br><code>"asset\_price\_usd": 37994.62623807689,</code><br><code>"asset\_contribution": 0.4407077440250888,</code><br><code>"pairs\_volumes": \[]]}, ...]</code></p> |
| `asset_code`             | Trading activity | Asset code.                                                                   | `btc`                                                                                                                                                                                                                                                                                                                       |
| `asset_trade_count`      | Trading activity | Trade count in the interval by asset. 0 when no trades are reported.          | `159115`                                                                                                                                                                                                                                                                                                                    |
| `asset_total_volume_usd` | Trading activity | Volume in USD traded in the interval by asset. 0 when no trades are reported. | `61612344.01769975`                                                                                                                                                                                                                                                                                                         |
| `asset_price_usd`        | Trading activity | Asset cross-price in USD used to compute volume in USD.                       | `37994.62623807689`                                                                                                                                                                                                                                                                                                         |
| `asset_contribution`     | Trading activity | Asset volume percentage over total volume.                                    | `0.4407077440250888`                                                                                                                                                                                                                                                                                                        |
| `pairs_volumes`          | Trading activity | Trading information details by pair.                                          | <p><code>\[{"pair\_code": "btc-usd",</code><br><code>"pair\_trade\_count": 19193,</code><br><code>"pair\_volume\_usd": 57484171.99063697,</code><br><code>"pair\_contribution": 0.9329976469345679}, ...]</code></p>                                                                                                        |
| `pair_code`              | Trading activity | Pair code.                                                                    | `btc-usd`                                                                                                                                                                                                                                                                                                                   |
| `pair_trade_count`       | Trading activity | Trade count in the interval by pair. 0 when no trades are reported.           | `1686`                                                                                                                                                                                                                                                                                                                      |
| `pair_volume_usd`        | Trading activity | Volume in USD traded in the interval by pair. 0 when no trades are reported.  | `57484171.99063697`                                                                                                                                                                                                                                                                                                         |
| `pair_contribution`      | Trading activity | Pair volume percentage over asset volume.                                     | `0.9329976469345679`                                                                                                                                                                                                                                                                                                        |

### 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/analytics.v2/exchange_metrics?exchange=cbse&sort=desc&sources=true&start_time=2023-11-29T14:00:00.0000000Z&end_time=2023-11-29T15:00:00.0000000Z&interval=1h&page_size=100'
```

{% endcode %}
{% endtab %}

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

```python
import http.client
import json

# Enter your Kaiko API Key
api_key = "KAIKO_API_KEY"
api_host = "us.market-api.kaiko.io"
api_base_endpoint = "/v2/data/analytics.v2/exchange_metrics"
# Start of mandatory parameter configuration
mandatory_params = {
    "exchange": "cbse",
    "start_time": "2024-08-27T13:13:53.441Z",
    "end_time" : "2024-08-27T18:27:53.441Z",
    "interval" : "1h",
}
# End of mandatory parameter configuration
# Start of optional parameter configuration
optional_params = {
    "sources": "false",
}
# End of optional parameter configuration
conn = http.client.HTTPSConnection(api_host)
headers = {
    "X-Api-Key": api_key,
    "Accept": "application/json"
}

all_params = {**mandatory_params, **optional_params}

url_params = []
for param, value in all_params.items():
    url_params.append(f"{param}={value}")
url_params = '&'.join(url_params)

endpoint_with_params = f"{api_base_endpoint}?{url_params}"

# Pagination for next pages
all_data = []
next_url = endpoint_with_params
while next_url:
    conn.request("GET", next_url, headers=headers)
    response = conn.getresponse()
    data = json.loads(response.read().decode("utf-8"))
    all_data.extend(data.get("data", []))
    print(f"Fetched {len(data.get('data', []))} datapoints. Total: {len(all_data)}")
    next_url = data.get("next_url", "").replace("https://us.market-api.kaiko.io", "")
    if not next_url:
        break
conn.close()
print(f" datapoints fetched: {(all_data)}")
```

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

### Response example

{% tabs %}
{% tab title="JSON" %}

```json
{
    "data": [
        {
            "timestamp": "2023-11-29T14:00:00.000Z",
            "total_volume_usd": 139803179.89191553,
            "total_trade_count": 121748,
            "nb_listed_assets": 235,
            "nb_listed_pairs": 379,
            "assets_volumes": [
                {
                  "asset_code": "btc",
                  "asset_trade_count": 22772,
                  "asset_total_volume_usd": 61612344.01769975,
                  "asset_price_usd": 37994.62623807689,
                  "asset_contribution": 0.4407077440250888,
                  "pairs_volumes": [
                        {
                          "pair_code": "btc-usd",
                          "pair_trade_count": 19193,
                          "pair_volume_usd": 57484171.99063697,
                          "pair_contribution": 0.9329976469345679
                        },
                        {
                          "pair_code": "btc-eur",
                          "pair_trade_count": 1686,
                          "pair_volume_usd": 1722929.4947314486,
                          "pair_contribution": 0.027964030945430225
                        },
                        {
                          "pair_code": "btc-usdt",
                          "pair_trade_count": 807,
                          "pair_volume_usd": 1590807.5262940996,
                          "pair_contribution": 0.02581962351305931
                        },
                        {
                          "pair_code": "btc-gbp",
                          "pair_trade_count": 1086,
                          "pair_volume_usd": 814435.0060372388,
                          "pair_contribution": 0.013218698606942646
                        }
                    ]
                },
              /* ... */
            ]
        },
        /* ... */
    ]  
}
```

{% endtab %}
{% endtabs %}


---

# 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/monitoring-solutions/kaiko-market-explorer/exchanges.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.
