This file provides guidance to Claude Code (claude.ai/code) for maintaining and extending the OMIEData Go library.
This is a Go library that provides access to OMIE (Iberian Electricity Market Operator) data. The library implements parsers and downloaders for various market data types including marginal prices and energy by technology.
omiedata/
├── types/ # Data structures and enums
├── parsers/ # File parsing logic
├── downloaders/ # HTTP download functionality
├── importers/ # High-level API combining parsers and downloaders
├── examples/ # Example applications
└── testdata/ # Sample files for testing
enums.go: System types (Spain=1, Portugal=2, Iberian=9) and technology typesdata.go: Data structures for parsed results (MarginalPriceData, TechnologyEnergy, etc.)errors.go: Custom error types with error codes
Each parser implements the Parser interface:
MarginalPriceParser: Parses daily market price filesEnergyByTechnologyParser: Parses energy generation by technology
Each downloader implements the Downloader interface:
- Constructs OMIE URLs based on date patterns
- Handles HTTP requests with retries
- Returns responses or saves to disk
High-level API that combines downloaders and parsers:
Import(): Fetches data for a date rangeImportSingleDate(): Fetches data for a single date- Handles concurrent downloads with configurable limits
OMIE files use ISO-8859-1 (Latin-1) encoding:
import "golang.org/x/text/encoding/charmap"
decoder := charmap.ISO8859_1.NewDecoder()European decimal format (comma as decimal separator):
// Convert "123,45" to 123.45
value := strings.Replace(field, ",", ".", -1)- Files use DD/MM/YYYY format
- Hours are 1-24 (not 0-23)
- Handle DST changes (some days have 23 or 25 hours)
Base URL: https://www.omie.es/sites/default/files/dados/
File patterns:
- Marginal Price:
AGNO_YYYY/MES_MM/TXT/INT_PBC_EV_H_1_DD_MM_YYYY_DD_MM_YYYY.TXT - Energy by Tech:
AGNO_YYYY/MES_MM/TXT/INT_PBC_TECNOLOGIAS_H_SYS_DD_MM_YYYY_DD_MM_YYYY.TXT
- Define data structures in
types/data.go - Create parser in
parsers/implementing theParserinterface - Create downloader in
downloaders/implementing theDownloaderinterface - Create importer in
importers/combining parser and downloader - Add tests using sample files in
testdata/ - Add example in
examples/
The testdata/ directory contains sample files from different time periods:
PMD_20060101.txt- Old format (Cent/kWh)PMD_20090601.txt- Transition formatPMD_20221030.txt- Current format (EUR/MWh)EnergyByTechnology_9_20201113.TXT- Technology breakdown
Run tests:
go test ./...
go test -v ./parsers -run TestMarginalPriceParser- Pre-2009: Prices in Cent/kWh (parser converts to EUR/MWh)
- 2009-2019: Various format transitions
- 2019+: Current EUR/MWh format
Some days have 23 or 25 hours due to daylight saving time changes. Parsers must handle variable hour counts.
Empty fields in OMIE files indicate missing data. Parsers should handle gracefully.
Use typed errors from types/errors.go:
ErrCodeNotFound: Data not available for dateErrCodeNetwork: Network/download issuesErrCodeParse: File parsing errors
# Run all tests
go test ./...
# Run with coverage
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
# 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
# Build examples (optional)
go build ./examples/marginal-price
go build ./examples/energy-by-technology
go build ./examples/average-price
# Format code
go fmt ./...
# Lint (requires golangci-lint)
golangci-lint run- Follow standard Go conventions
- Use meaningful variable names
- Add comments for exported functions
- Handle errors explicitly
- Use context for cancellation support
- Log errors but don't panic in library code
- Additional data types as needed
- Performance optimizations if required
- Use gocyclo (go tool gocyclo -over=15 .) to find and fix code with high complexity