Thanks to visit codestin.com
Credit goes to pkg.go.dev

omiedata

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2025 License: MIT Imports: 2 Imported by: 0

README

OMIEData

A Go library for accessing electricity market data from OMIE (Iberian Peninsula's Electricity Market Operator). This library provides data access for daily market prices and energy by technology for Spain and Portugal.

This is a Go port of the OMIEData Python library.

Table of Contents

Features

  • Marginal Prices: Hourly electricity prices for Spain and Portugal
  • Energy by Technology: Generation breakdown by source (wind, solar, nuclear, etc.)
  • Concurrent Downloads: Parallel data fetching
  • Multiple Formats: Support for historical format changes
  • Type Safety: Full Go type safety with proper error handling

Installation

go get github.com/devuo/omiedata

Quick Start

Marginal Prices
package main

import (
    "context"
    "fmt"
    "log"
    "time"

    "github.com/devuo/omiedata"
)

func main() {
    // Create importer
    importer := omiedata.NewMarginalPriceImporter()

    // Get data for yesterday
    ctx := context.Background()
    yesterday := time.Now().AddDate(0, 0, -1)

    data, err := importer.ImportSingleDate(ctx, yesterday)
    if err != nil {
        log.Fatal(err)
    }

    priceData := data.(*omiedata.MarginalPriceData)

    fmt.Printf("Date: %s\n", priceData.Date.Format("2006-01-02"))

    // Print hourly prices
    for hour := 1; hour <= 24; hour++ {
        if price, exists := priceData.SpainPrices[hour]; exists {
            fmt.Printf("Hour %2d: %.2f EUR/MWh\n", hour, price)
        }
    }
}
Energy by Technology
package main

import (
    "context"
    "fmt"
    "log"
    "time"

    "github.com/devuo/omiedata"
)

func main() {
    // Create importer for Iberian system
    importer := omiedata.NewEnergyByTechnologyImporter(omiedata.Iberian)

    ctx := context.Background()
    date := time.Date(2024, 1, 15, 0, 0, 0, 0, time.UTC)

    result, err := importer.ImportSingleDate(ctx, date)
    if err != nil {
        log.Fatal(err)
    }

    dayData := result.(*omiedata.TechnologyEnergyDay)

    fmt.Printf("Energy data for %s:\n", dayData.Date.Format("2006-01-02"))

    // Show renewable energy for each hour
    for _, record := range dayData.Records {
        renewable := record.Wind + record.SolarPV + record.SolarThermal + record.Hydro
        fmt.Printf("Hour %2d: %.1f MWh renewable\n", record.Hour, renewable)
    }
}
Date Range Import
// Import data for a week
start := time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)
end := start.AddDate(0, 0, 6)

results, err := importer.Import(ctx, start, end)
if err != nil {
    log.Fatal(err)
}

dataList := results.([]*omiedata.MarginalPriceData)
fmt.Printf("Imported %d days of data\n", len(dataList))

Configuration

You can customize the import behavior with options:

options := omiedata.ImportOptions{
    Verbose:       true,           // Enable verbose logging
    MaxRetries:    5,              // Number of download retries
    RetryDelay:    2 * time.Second, // Delay between retries
    MaxConcurrent: 3,              // Maximum concurrent downloads
}

importer := omiedata.NewMarginalPriceImporterWithOptions(options)

Data Types

MarginalPriceData

Contains hourly electricity prices and energy volumes:

type MarginalPriceData struct {
    Date            time.Time
    SpainPrices     map[int]float64 // hour (1-24) -> EUR/MWh
    PortugalPrices  map[int]float64 // hour (1-24) -> EUR/MWh
    SpainBuyEnergy  map[int]float64 // hour (1-24) -> MWh
    SpainSellEnergy map[int]float64 // hour (1-24) -> MWh
    IberianEnergy   map[int]float64 // hour (1-24) -> MWh
    BilateralEnergy map[int]float64 // hour (1-24) -> MWh
}
TechnologyEnergy

Contains energy generation by technology for a specific hour:

type TechnologyEnergy struct {
    Date              time.Time
    Hour              int
    System            SystemType
    Coal              float64 // MWh
    Nuclear           float64 // MWh
    Wind              float64 // MWh
    SolarPV           float64 // MWh
    // ... other technologies
}

System Types

  • omiedata.Spain (1) - Spanish market
  • omiedata.Portugal (2) - Portuguese market
  • omiedata.Iberian (9) - Combined Iberian market

Error Handling

The library uses structured error types:

data, err := importer.ImportSingleDate(ctx, date)
if err != nil {
    if omieErr, ok := err.(*types.OMIEError); ok {
        switch omieErr.Code {
        case types.ErrCodeNotFound:
            fmt.Println("Data not available for this date")
        case types.ErrCodeNetwork:
            fmt.Println("Network error occurred")
        case types.ErrCodeParse:
            fmt.Println("Failed to parse data")
        }
    }
    return err
}

Historical Data Format Changes

The library automatically handles OMIE's format changes over time:

  • Pre-2009: Prices in Cent/kWh (automatically converted to EUR/MWh)
  • 2009-2019: Transition period with format variations
  • 2019+: Current EUR/MWh format

Examples

See the examples directory for complete working examples:

Run examples:

go run ./examples/marginal-price
go run ./examples/energy-by-technology
go run ./examples/average-price -start 01-01-2024 -end 03-01-2024

Testing

Run tests with sample data:

go test ./...

The test suite includes sample files from different time periods to ensure compatibility with format changes.

Acknowledgments

Documentation

Overview

Package omiedata provides access to OMIE (Iberian Electricity Market Operator) data.

This library allows you to download and parse electricity market data from the OMIE website, including marginal prices and energy by technology for Spain and Portugal.

Basic usage example:

importer := omiedata.NewMarginalPriceImporter()
data, err := importer.ImportSingleDate(ctx, time.Now().AddDate(0, 0, -1))
if err != nil {
	log.Fatal(err)
}
// Use data...

Index

Constants

View Source
const (
	Spain    = types.Spain
	Portugal = types.Portugal
	Iberian  = types.Iberian
)

System type constants

View Source
const (
	Coal               = types.Coal
	FuelGas            = types.FuelGas
	SelfProducer       = types.SelfProducer
	Nuclear            = types.Nuclear
	Hydro              = types.Hydro
	CombinedCycle      = types.CombinedCycle
	Wind               = types.Wind
	ThermalSolar       = types.ThermalSolar
	PhotovoltaicSolar  = types.PhotovoltaicSolar
	Residuals          = types.Residuals
	Import             = types.Import
	ImportWithoutMIBEL = types.ImportWithoutMIBEL
)

Technology type constants

Variables

This section is empty.

Functions

This section is empty.

Types

type EnergyByTechnologyImporter

type EnergyByTechnologyImporter = importers.EnergyByTechnologyImporter

Re-export key types for easier access

func NewEnergyByTechnologyImporter

func NewEnergyByTechnologyImporter(systemType SystemType) *EnergyByTechnologyImporter

NewEnergyByTechnologyImporter creates a new energy by technology importer with default settings

func NewEnergyByTechnologyImporterWithOptions

func NewEnergyByTechnologyImporterWithOptions(systemType SystemType, options ImportOptions) *EnergyByTechnologyImporter

NewEnergyByTechnologyImporterWithOptions creates a new energy by technology importer with custom options

type ImportOptions

type ImportOptions = importers.ImportOptions

Import options

type MarginalPriceData

type MarginalPriceData = types.MarginalPriceData

Data types

type MarginalPriceImporter

type MarginalPriceImporter = importers.MarginalPriceImporter

Importers

func NewMarginalPriceImporter

func NewMarginalPriceImporter() *MarginalPriceImporter

NewMarginalPriceImporter creates a new marginal price importer with default settings

func NewMarginalPriceImporterWithOptions

func NewMarginalPriceImporterWithOptions(options ImportOptions) *MarginalPriceImporter

NewMarginalPriceImporterWithOptions creates a new marginal price importer with custom options

type SystemType

type SystemType = types.SystemType

System types

type TechnologyEnergy

type TechnologyEnergy = types.TechnologyEnergy

Re-export key types for easier access

type TechnologyEnergyDay

type TechnologyEnergyDay = types.TechnologyEnergyDay

Re-export key types for easier access

type TechnologyType

type TechnologyType = types.TechnologyType

Technology types

Directories

Path Synopsis
examples
average-price command
marginal-price command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL