# @wayota/redata-api-client

TypeScript client for the REData (Red Eléctrica de España) public API. This package provides convenient methods to fetch Spanish electricity data widgets, supporting category, widget, date range, and geographic filters. The client is based on a custom OpenAPI specification derived from the official Red Eléctrica documentation.

## Features
- Fetch electricity data from REData (Red Eléctrica de España) with a simple TypeScript interface
- Support for categories, widgets, date ranges, and geographic filters
- Typed parameters and responses for safer integration

## Installation

```sh
npm install @wayota/redata-api-client
```

## Getting Started

### Basic Usage

```typescript
import { Client } from '@wayota/redata-api-client';
import { Category } from '@wayota/redata-api-client/enums/Category';
import { Widget } from '@wayota/redata-api-client/enums/Widget';
import { TimeTrunc } from '@wayota/redata-api-client/enums/TimeTrunc';

const client = new Client();

async function main() {
  const response = await client.getByCategoryByWidget({
    category: Category.balance,
    widget: Widget.balanceElectrico,
    query: {
      startDate: '2019-01-01T00:00',
      endDate: '2019-01-31T23:59',
      timeTrunc: TimeTrunc.day,
      // Optional filters:
      // geotrunc: GeoTrunc.electricSystem,
      // geoLimit: GeoLimit.canarias,
      // geoIds: 'your-geo-id',
    },
  });
  console.log(response);
}

main().catch(console.error);
```

### Client Configuration

You can configure the API base URL if needed:

```typescript
const client = new Client({ baseUrl: 'https://apidatos.ree.es' });
```

## API Reference

See the [redata-open-api.yaml](./redata-open-api.yaml) file for the full API specification and supported parameters.

## License

ISC

## Author

Miguel Martín (@miguel-martinr)
