Crate strompris

Crate strompris 

Source
Expand description

This crate offers a wrapper of the Strømpris API offered by HvaKosterStrømmen.

The crate is designed to be as simple as the API itself, so only one method is exposed: A method for getting the prices for a given region on a given day.

This crate offers both async and blocking ways of fetching prices. See the blocking module for more information on the blocking API.

See www.hvakosterstrommen.no for more info about the API.

Example using tokio:

use strompris::{Strompris, PriceRegion, Date, Error};

#[tokio::main]
async fn main() -> Result<(), Error> {
    let date = Date::from_ymd_opt(2024, 1, 31).unwrap();
    let client = Strompris::default();
    let prices = client.get_prices(date, PriceRegion::NO1).await?;
    for price in prices.iter() {
        println!("Price: {:.2}", price.nok_per_kwh);
        println!("From: {}", price.time_start.time());
        println!("To: {}", price.time_end.time());
    }
    Ok(())
}

Re-exports§

pub use error::Error;

Modules§

blocking
For use outside an async runtime.
error
The module containing errors for this crate

Structs§

Date
A wrapper for chrono::NaiveDate.
HourlyPrice
Wraps the resulting JSON-object, exposing each attribute.
Strompris
The client for communicating with the Strømpris API hosted on www.hvakosterstrommen.no.

Enums§

PriceRegion
Because the different regions of Norway has different access to power, Norway is divided into 5 price regions. Each of these regions has its own hourly price.