#elspot #nordpool #day-ahead #trade-power #power-market

eb_nordpool

从 Nordpool 提取 elspot 价格

3 个版本

新版本 0.1.2 2024 年 8 月 18 日
0.1.1 2024 年 8 月 15 日
0.1.0 2024 年 8 月 5 日
Download history 105/week @ 2024-08-04 110/week @ 2024-08-11

每月 215 次下载

MIT/Apache

58KB
471 行代码(不含注释)

eb_nordpool

Rust 库,用于从 Nordpool 提取 elspot 价格。

此软件包仍处于早期开发阶段,未来将提供文档。

运行测试。

./run.sh

lib.rs:

eb_nordpool 提供了一种轻松提取 Nordpool elspot 价格的方法。

入门

从 nordpoolgroup.com 或从文件获取价格。

use eb_nordpool::{elspot, region_time, units};

// Set the currency "DKK, EUR, NOK or SEK", when downloading prices from nordpool.
let currency = elspot::Currencies::NOK;

// Download todays or tomorrows prices (we can not control this..)
// If time is before 13:00 in Norway, you get prices for today; else you get for tomorrow.
let data = elspot::hourly::from_nordpool(currency).unwrap();
// ..this http request is currently blocking, but this might change in the future.

// Gives you the actual date for the prices in YYYY-MM-DD format (chrono's NaiveDate type).
data.date()

// Save data to file.
data.to_file("path/to/data.json");

// When or if you have data stored locally, you can simply load it from a file.
let data = elspot::hourly::from_file("path/to/data.json").unwrap();

// Serialize data to json string, nice if you want to load it somewhere else.
let s = data.to_string();

// Print out all available regions. This is convenient for finding a specific region.
data.print_regions();

// Get all regions in a Vec<&str>, nice if you want to do something with all regions.
let regions = data.regions();

// Check if a region exists in dataset.
if data.has_region("Oslo") {
    // ..do something
}

// Get all prices for a specific region (always in ascending order starting at time 00:00).
let prices = data.all_prices_for_region("Oslo");

// Print all price data.
for p in prices.iter() {
    println!("{}", p);
}

// Print one price.
let p = &prices[8];
let (region, from, to, value, unit) = (&p.region, &p.from, &p.to, &p.value, &p.unit);
println!("Price for {region} between {from} and {to} is {value} {unit}");

// Price now for specific region.
if let Ok(p) = hourly.price_now_for_region("Oslo") {
    println!("Price for Oslo now:  {} {}", p.value, p.unit);
}

// Get price for specific timestamp (must be in Utc)
let utc_dt = region_time::utc_with_ymd_and_hms(2024, 6, 20, 11, 0, 0);
let p = hourly.price_for_region_at_utc_dt("Oslo", &utc_dt);
// NOTE: this gives you the price for 13:00 local time, Oslo is 2 hours ahead during CEST..
match p {
    Ok(p) => println!("{}", p),
    Err(e) => println!("{}", e),
}

// Convert currency and power units (remember to declare as mutable..).
let mut p = prices[3].clone();
units::to_currency_sub_unit(&mut p); // Converts "160,00" to "16000" e.g. to cents.
units::to_currency_full_unit(&mut p); // Same as above, but the other way around.
units::to_power_kwh_unit(&mut p); // Converts from MWh to kWh (also adjusts the price value).
units::to_power_mwh_unit(&mut p); // Same as above, but the other way around.

依赖项

~5–17MB
~234K SLoC