# Analytics

## Get aggregate TCA statistics

<mark style="color:blue;">`GET`</mark> `/api/tca_stats/`

Retrieves aggregate statistics for a set of orders, as filtered by query parameters below. Note that the output is a subset of the data shown on TaaS's [Analytics](/other-features/transaction-cost-analysis.md) page.&#x20;

#### Query Parameters

| Name               | Type          | Description                                                                                                                                              |
| ------------------ | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| accounts\_\_name   | string        | Account to include in aggregation                                                                                                                        |
| pair               | string        | Example: `BTC-USDT`                                                                                                                                      |
| side               | string        | `buy` or `sell`                                                                                                                                          |
| strategy           | string        | [Trajectory](/interacting-with-the-api/api-reference/type-reference.md#strategy-enum) to include (`VWAP`, `TWAP`, `IS`)                                  |
| super\_strategy    | string        | Strategy to include (`Impact Minimization`, `Aggressive Maker`, etc.) Note that only one of (`strategy`, `super_strategy`) should be specified in a call |
| created\_at\_\_gte | ISO 8601 date | Include only orders created on or after this date, e.g., `2024-09-13`                                                                                    |
| created\_at\_\_lte | ISO 8601 date | Include only orders created on or before this date, e.g., `2024-09-14`                                                                                   |

{% tabs %}
{% tab title="200: OK" %}

```javascript
{'summary': {'num_orders': 1000,
  'num_pairs': 8,
  'avg_duration': 175.74219266221795,
  'sum_notional': 12436204.142881382,
  'orders_value': '$12.44M',
  'sum_fee': 4741.834601611435,
  'exch_fee': '$4.74K',
  'fee_cost': 3.8129276000392065,
  'pov': 0.0,
  'departure_cost': 0.7686062896022027,
  'arrival_cost': 0.6356043187543811,
  'vwap_cost': 0.6395291279757329,
  'interval_returns': -0.13300197084782164},
 'breakdowns': {'fill_role': {'cutbys': ['role'],
   'labels': ['TAKE', 'MAKE', 'OTC'],
   'data': {'TAKE': [58.74792384940719],
    'MAKE': [40.844465220094875],
    'OTC': [0.4076109304979441]}},
  'fill_exchange': {'cutbys': ['exchange'],
   'labels': ['OKX', 'OKXOTC', 'Bybit'],
   'data': {'OKX': [99.51157408033795],
    'OKXOTC': [0.4076109304979441],
    'Bybit': [0.08081498916409907]}}}}
```

{% endtab %}

{% tab title="403: Forbidden" %}

```javascript
{'detail': 'Invalid token.'}
```

{% endtab %}

{% tab title="500: Internal Server Error" %}

```javascript
{'error': 'Account name not found' | 'Invalid side' | 'Invalid date format' | 'Invalid super strategy' | 'Invalid strategy' }
```

{% endtab %}
{% endtabs %}

## Get orders with detailed stats (TCA data)

<mark style="color:blue;">`GET`</mark> `/api/orders_with_stats/`

Similar to data from GET /orders endpoint, but includes more detailed execution info: list of fills and relevant transaction cost analysis data such as arrival and departure price.

#### Query Parameters

| Name       | Type   | Description                                                  |
| ---------- | ------ | ------------------------------------------------------------ |
| page\_size | number | <p>size of paginated orders, max 1000</p><p>default: 500</p> |
| page       | number | <p>1-indexed page number</p><p>default: 1</p>                |

{% tabs %}
{% tab title="200: OK paginated orders with stats" %}

```json
{
    "orders": [
        {
            "id": "8cb8b3f6-d0ed-4dcc-97cb-d46baab928c9",
            "custom_order_id": "",
            "notes": "",
            "pair": "1INCH:PERP-USDT",
            "side": "buy",
            "buy_token": "1INCH:PERP",
            "sell_token": "USDT",
            "sell_token_amount": 376.4,
            "executed_qty": 376.5159,
            "average_executed_price": 0.37651596708133706,
            "executed_notional": 376.5159,
            "total_fee": 0.17899986,
            "strategy": "TWAP",
            "super_strategy": "Impact Minimization",
            "duration": 120,
            "accounts": [
                "8640fa74-c66f-44a9-8686-c71bf0491ec4"
            ],
            "account_names": [
                "okxtest"
            ],
            "engine_passiveness": 0.02,
            "schedule_discretion": 0.08,
            "strategy_params": {
                "reduce_only": true,
                "passive_only": false
            },
            "user": "2",
            "status": "COMPLETE",
            "is_simple": false,
            "failure_reason": "",
            "limit_price": -1.0,
            "time_start": "2024-01-25T23:25:54.712402Z",
            "time_end": "2024-01-25T23:27:54.712402Z",
            "created_at": "2024-01-25T23:25:54.762625Z",
            "updated_at": "2024-01-25T23:30:49.646518Z",
            "fills": [
                {
                    "placement_id": "a5b2018a-173e-4972-b1c9-c4bbca81e7b6",
                    "role": "TAKE",
                    "executed_price": 0.3765,
                    "executed_qty": 17.6955,
                    "executed_notional": 17.6955,
                    "fee": 0.00884775,
                    "fill_time": "2024-01-25T23:26:13.346000Z"
                },
                //...
            ],
            "stats": {
                      "order_id": "8cb8b3f6-d0ed-4dcc-97cb-d46baab928c9",
                      "stat_id": 233531,
                      "interval_volume": 544.5882,
                      "vwap": 3214.6546467955054,
                      "arrival_price": 3214.81,
                      "departure_price": 3215.08
                      }
        },
        //...
    ],
    "page_number": 1,
    "page_size": 500,
    "num_pages": 1,
    "order_count": 73
}
```

{% endtab %}
{% endtabs %}

## Get multi order TCA

<mark style="color:blue;">`GET`</mark> `/api/multi_order_tca`

Similar to data from GET /orders endpoint, but includes more detailed execution info: list of fills and relevant transaction cost analysis data such as arrival and departure price. Refer to [Transaction Cost Analysis](/other-features/transaction-cost-analysis.md#benchmark-costs) for detailed explanations on some of the metrics.

#### Query Parameters

Need either multi\_order\_id or custom\_order\_id

| Name              | Type   | Description           |
| ----------------- | ------ | --------------------- |
| multi\_order\_id  | string | UUID of multi order   |
| custom\_order\_id | string | specified multi order |

{% tabs %}
{% tab title="200: OK paginated orders with stats" %}

```json
{
  "notional_exposure": 57.451, // in USD
  "fee_notional": 9.94468e-7, // in USD
  "fee_cost": 0.00004, // in bps
  "vwap_cost": 39.23477228401562, // in bps
  "arrival_cost": 40.250532544640556, // in bps
  "pov": 0.19167316910751267 // participation rate in percent i.e. this is 0.19%
}
```

{% endtab %}

{% tab title="422: Unprocessable Entity" %}

```json
{
  "message": "MultiOrder not found for identifier abcddd"
}
```

{% 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.tread.fi/interacting-with-the-api/api-reference/analytics.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.
