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.
- Features
- Installation
- Quick Start
- Configuration
- Data Types
- System Types
- Error Handling
- Historical Data Format Changes
- Examples
- Testing
- Acknowledgments
- 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
go get github.com/devuo/omiedatapackage 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)
}
}
}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)
}
}// 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))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)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
}Contains energy generation by technology for a specific hour:
typeTechnologyEnergystruct {
Date time.TimeHourintSystemSystemTypeCoalfloat64// MWhNuclearfloat64// MWhWindfloat64// MWhSolarPVfloat64// MWh// ... other technologies
}omiedata.Spain(1) - Spanish marketomiedata.Portugal(2) - Portuguese marketomiedata.Iberian(9) - Combined Iberian market
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
}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
See the examples directory for complete working examples:
marginal-price/- Basic price data importenergy-by-technology/- Technology breakdown analysisaverage-price/- Calculate average PT price for a date range
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-2024Run tests with sample data:
go test ./...The test suite includes sample files from different time periods to ensure compatibility with format changes.
- Based on the original OMIEData Python library
- OMIE (Operador del Mercado Ibérico de Energía) for providing the data