Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Awattar: fetch more than 24h price data #16338

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion tariff/awattar.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ func (t *Awattar) run(done chan error) {
for ; true; <-tick.C {
var res awattar.Prices

// Awattar publishes prices for next day around 13:00 CET/CEST, so up to 35h of price data are available
// To be on the safe side request a window of -2h and +48h, the API doesn't mind requesting more than available
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we round to hours and do we really need two hours back instead of start of current hour?

Copy link
Contributor Author

@andi0b andi0b Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need 2 hours, but it could mitigate potential edge cases, like some potential errors in the awattar api regarding daylight savings time. Requesting one entry less doesn't seem worth investigating potential edge cases.

Start time in the Awattar api is exclusive, requesting start=12:15 for example returns 13:00-14:00 as the first entry in the response.

Rounding would be possible, but I don't see the benefit, except of adding complexity.

The PR is open for your changes.

start := time.Now().Add(-2 * time.Hour).UnixMilli()
end := time.Now().Add(48 * time.Hour).UnixMilli()
uri := fmt.Sprintf("%s?start=%d&end=%d", t.uri, start, end)

if err := backoff.Retry(func() error {
return backoffPermanentError(client.GetJSON(t.uri, &res))
return backoffPermanentError(client.GetJSON(uri, &res))
}, bo()); err != nil {
once.Do(func() { done <- err })

Expand Down