---
updatedAt: 2025-12-05T16:05:41.000Z
agentTools:
  projectIndex: https://developers.modoenergy.com/llms.txt
---

# Using the Index Revenue endpoint to get revenue by market

```python Python
import logging
from datetime import datetime

import requests

logger = logging.getLogger(__name__)


class ModoApiClient:
    def __init__(self, api_token: str) -> None:
        self.api_token = api_token
        self.session = requests.Session()
        self.session.headers.update(
            {
                "X-Token": self.api_token,
                "Accept": "application/json",
            },
        )

    def get(self, url: str, params: dict[str, str] | None = None) -> dict | list[dict]:
        all_results: list[dict] = []
        next_url = url
        try:
            while next_url:
                response = self.session.get(next_url, params=params)

                response.raise_for_status()
                data = response.json()

                if isinstance(data, dict) and "results" in data:
                    results = data["results"]
                    if isinstance(results, dict):
                        results = [results]
                    all_results.extend(results)
                    next_url = data.get("next")
                    params = None
                else:
                    next_url = None
                    all_results = data
        except requests.RequestException as e:
            logger.error(e.response.text)
        finally:
            return all_results


if __name__ == "__main__":
    api_key = "example-api-key"
    client = ModoApiClient(api_key)

    # This will download all the indices you are able to access
    index_url = "https://public-data-api-dev.modoint.com/pub/v1/indices/"
    indices = client.get(url=index_url)

    # Find the specific index you're interested in
    # Tip: the index_id will never change, so once you know it, you can reference it in future API calls
    index_to_find = "ME BESS GB"
    index_id = next((index["id"] for index in indices if index["name"] == index_to_find), None)
    if not index_id:
        raise ValueError(f"Couldn't find index {index_to_find}")

    # Get revenue for this index. Use params to customise the API call
    params = {
        "interval_start": datetime(2025, 1, 1),
        "interval_end": datetime(2025, 1, 2),
        "capacity_normalisation": "mw",
        "time_basis": "year",
        "breakdown": "market",
        # "markets": "bm,wholesale,imbalance",
    }
    index_revenue_url = "https://public-data-api-dev.modoint.com/pub/v1/indices/{id}/revenue/"
    index_revenue = client.get(url=index_revenue_url.format(id=index_id), params=params)
```

```json Response Example
{
  "units": "GBP/MW/year",
  "records": [
    { "market": "bm", "revenue": "-529.505" },
    { "market": "cm", "revenue": "309.160" },
    { "market": "dch", "revenue": "8603.255" },
    { "market": "dcl", "revenue": "10822.384" },
    { "market": "dmh", "revenue": "1836.194" },
    { "market": "dml", "revenue": "563.288" },
    { "market": "drh", "revenue": "688.903" },
    { "market": "drl", "revenue": "2139.179" },
    { "market": "imbalance", "revenue": "9621.953" },
    { "market": "nbr", "revenue": "0.000" },
    { "market": "nqr", "revenue": "1230.702" },
    { "market": "pbr", "revenue": "692.220" },
    { "market": "pqr", "revenue": "3487.110" },
    { "market": "wholesale", "revenue": "-7058.604" }
  ]
}


```

# Define an API client and use it to get the index ID you're looking for

<!-- python@9-59 -->

For a full explanation, see our [Using the Index Revenue endpoint](https://developers.modoenergy.com/recipes/using-the-index-revenue-endpoint) recipe.

# Get index revenue by market

<!-- python@61-71 -->

Use params to customise the API call. 

The key to getting the results broken dow by market is to include the parameter: `breakdown=market`.

# Optionally, filter by market

<!-- python@68 -->

If you're only interested in specific markets you can filter for them. This also works without passing "breakdown=market" if you want the total revenue, but only for a couple of markets.