Skip to content

Repository files navigation

OMIEData

Go ReferenceGo Report Card

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"
)
funcmain() {
// Create importerimporter:=omiedata.NewMarginalPriceImporter()
// Get data for yesterdayctx:=context.Background()
yesterday:=time.Now().AddDate(0, 0, -1)
data, err:=importer.ImportSingleDate(ctx, yesterday)
iferr!=nil {
log.Fatal(err)
}
priceData:=data.(*omiedata.MarginalPriceData)
fmt.Printf("Date: %s\n", priceData.Date.Format("2006-01-02"))
// Print hourly pricesforhour:=1; hour<=24; hour++ {
ifprice, 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"
)
funcmain() {
// Create importer for Iberian systemimporter:=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)
iferr!=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 hourfor_, record:=rangedayData.Records {
renewable:=record.Wind+record.SolarPV+record.SolarThermal+record.Hydrofmt.Printf("Hour %2d: %.1f MWh renewable\n", record.Hour, renewable)
}
}

Date Range Import

// Import data for a weekstart:=time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)
end:=start.AddDate(0, 0, 6)
results, err:=importer.Import(ctx, start, end)
iferr!=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 loggingMaxRetries: 5, // Number of download retriesRetryDelay: 2*time.Second, // Delay between retriesMaxConcurrent: 3, // Maximum concurrent downloads
}
importer:=omiedata.NewMarginalPriceImporterWithOptions(options)

Data Types

MarginalPriceData

Contains hourly electricity prices and energy volumes:

typeMarginalPriceDatastruct {
Date time.TimeSpainPricesmap[int]float64// hour (1-24) -> EUR/MWhPortugalPricesmap[int]float64// hour (1-24) -> EUR/MWhSpainBuyEnergymap[int]float64// hour (1-24) -> MWhSpainSellEnergymap[int]float64// hour (1-24) -> MWhIberianEnergymap[int]float64// hour (1-24) -> MWhBilateralEnergymap[int]float64// hour (1-24) -> MWh
}

TechnologyEnergy

Contains energy generation by technology for a specific hour:

typeTechnologyEnergystruct {
Date time.TimeHourintSystemSystemTypeCoalfloat64// MWhNuclearfloat64// MWhWindfloat64// MWhSolarPVfloat64// 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)
iferr!=nil {
ifomieErr, ok:=err.(*types.OMIEError); ok {
switchomieErr.Code {
casetypes.ErrCodeNotFound:
fmt.Println("Data not available for this date")
casetypes.ErrCodeNetwork:
fmt.Println("Network error occurred")
casetypes.ErrCodeParse:
fmt.Println("Failed to parse data")
}
}
returnerr
}

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

About

A Go library for accessing electricity market data from OMIE (Iberian Peninsula's Electricity Market Operator).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages