Giter Club home page Giter Club logo

nordpool-node's Introduction

Nordpool Elspot API npm client

Build Status JavaScript Style Guide

Unofficial Nordpool Elspot API npm client

Restrictions regarding data use

Before you access the Nordpool data using this module, please read and understand the Terms and conditions for use of website There may be clauses prohibiting automatic extraction of data that reduces the performance of the website, limits for republishing information etc.

Features

Usage

import {Prices} from 'nordpool'
const prices = new Prices()
const run = async () => {
  const results = await prices.hourly()
  console.log(results)
}
run()

Methods

  • at: get price at an exact time
  • hourly: get hourly prices
  • daily: get daily prices
  • weekly: get weekly prices
  • monthly: get monthly prices
  • yearly: get yearly prices

Options

Options shall be included as a single object containing the some of the properties listed here

  • area: the energy market area. See nordpool map
    • Accepts: a string or an array of strings. Strings are case sensitive. Currently available areas are Bergen, DK1, DK2, FI, Kr.sand, Molde, OSLO, SE1, SE2, SE3, SE4, SYS, Tr.heim, Tromsø'. (EE, LV, LT, AT, BE, DE-LU, FR and NL are only partially supported - e.g. yearly data is not available.)
    • Optional: if not specified data from all supported areas is returned.
  • currency: choose currency of the returned values. Note that not all areas will return all currencies. EUR seams to work on all areas though.
    • Accepts: a string of either DKK, EUR, NOK or SEK. Strings are case sensitive.
    • Optional: if currency is not specified EUR or wrong EUR is returned.
  • date: must be a date parsable by new Date(x).
    • Accepts: Date object or a string parsable by new Date(x) like a string in ISO 8601 format.
    • Optional: if date is not specified todays date of your local system is used
    • Note: using plain dates (e.g., 2021-09-19) are converted to midnight in your local timezone, which may be on another day than the midnight on default (Norwegian) timezone. If you don't get the results ypu expect, try to specify an exact time and timezone (e.g,2021-09-19T00:00:00+01:00)
  • from: don't return values before/after this time.
    • Accepts: Accepts same formats as date.
    • Optional: falls back to one date based on input from date.
  • to: don't return values/after this time. There are some weird limits to this time span as stated in the known issues. You will be prompted with a warning if you pass the limit.
    • Accepts: Accepts same formats as date.
    • Optional: falls back to the max limits one date based on input from date.

Returned values

The result is returned as a Promise resolving into an array of objects. If requesting hourly with options = { area: 'Oslo', currency: 'NOK', from: '2020-01-01T04:00:00.000Z', to: '2020-01-01T05:00:01.000Z' } the result should be (comments added):

[{
    area: 'Oslo', // Area
    date: '2020-01-01T04:00:00.000Z', // UTC timestamp of price. Eg. price from 04:00 to 05:00 UTC time
    value: 298.57 // Price in selected currency/MWh Eg. NOK/MWh
},
{ area: 'Oslo', date: '2020-01-01T05:00:00.000Z', value: 297.58 }
]

Install

npm install nordpool

Examples

Example 1: Latest hourly prices from all areas

import { nordpool } from 'nordpool'
const prices = new nordpool.Prices()

prices.hourly().then(results => {
  for (const item of results) {
    const row = item.date + ': ' + item.value + ' €/kWh in ' + item.area
    console.log(row)
  }
})

Example 2: Hourly prices in Stockholm

import { Prices } from 'nordpool'
const prices = new Prices()
import dayjs from 'dayjs'
import dayjsPluginUtc from 'dayjs/plugin/utc.js'
import dayjsPluginTimezone from 'dayjs/plugin/timezone.js'
dayjs.extend(dayjsPluginUtc) // Used by timezone
dayjs.extend(dayjsPluginTimezone) // Used to convert from one timezone to another

const formatter = new Intl.NumberFormat('se-SE', {style: 'currency', currency: 'SEK'})
const opts = {
  area: 'SE3', // See http://www.nordpoolspot.com/maps/
  currency: 'SEK' // can also be 'DKK', 'EUR', 'NOK'
}

const run = async () => {
  let results
  try {
    results = await prices.hourly(opts)
  } catch (error) {
    console.error(error)
    return
  }
  for (let i = 0; i < results.length; i++) {
    const date = results[i].date
    const price = results[i].value
    const time = dayjs.tz(date, 'UTC').tz('Europe/Stockholm').format('D.M. H:mm')
    console.log(time + '\t' + formatter.format(price) + '/MWh')
  }
}
run()

Example 3: Consumer prices in Finland (in cent/kWh and local time)

Coverting "business prices" (€/MWh) to "consumer prices" (including VAT)

import { Prices } from 'nordpool'

const prices = new Prices()

const printHourlyConsumerPrices = async () => {
  const results = await prices.hourly({area:'FI'})
  for (const item of results) {
    // item.date is an ISO Date-Time
    // (see https://www.ecma-international.org/ecma-262/11.0/#sec-date-time-string-format)
    // use Date object to format
    const date = new Date(item.date) // automatically in your local timezone
    const hour = date.getHours().toString().padStart(2, '0').concat(':00')

    // item.value is the enrgy price in EUR/MWh
    // convert it to snt/kWh and add Finnish VAT of 24 %
    const price = Math.round(item.value * 1.24 * 100)/1000

    var row = `${hour}\t${price.toFixed(3)} snt/kWh`
    console.log(row)
  }
}
printHourlyConsumerPrices()

Example 4: Weekly prices in Bergen in 2020

Parsing dates with moment and formatting prices with Intl.NumberFormat

import { Prices } from 'nordpool'
import dayjs from 'dayjs'
import dayjsPluginWeekOfYear from 'dayjs/plugin/weekOfYear.js'
dayjs.extend(dayjsPluginWeekOfYear)

const opts = {
  currency: 'NOK',
  area: 'Bergen',
  from: '2019-06-01'
}

const getWeekly = async () => {
  const prices = await new Prices().weekly(opts)
  for (const week of prices.reverse()) {
    const weeklyPriceMessage = 'The MWh price on week ' + 
      dayjs(week.date).week() + '/' + dayjs(week.date).format('YYYY') +
      ' was ' + priceFormat.format(week.value)
    console.log(weeklyPriceMessage)
  }
}
getWeekly()

const priceFormat = new Intl.NumberFormat('no-NO', {
  style: 'currency',
  currency: 'NOK',
  minimumFractionDigits: 2
});

See examples folder for more examples.

Check possible values for area (regions) from nordpoolspot.com

Data availability

Historical data seems to be available for two previous years.

Known issues

  • Versions prior to 2.0 were full of flaws. Don't use them.
  • Version 5.0.0 changes the export! Previous usage was import { nordpool } from 'nordpool' and current is import { Prices } from 'nordpool'.
  • The Nordpool API returns data in Norwegian time zones. The hourly API returns data from midnight to midnight in the Europe/Oslo timezone.
  • Historical data is limited to two calendar years in addition to the current year.
  • The API limits are a bit strange. The maximum number of weeks is 24 and the maximum number of months is 53.

TODO

  • Add support for other API functions (volume, capacity, flow).
  • Make configuration more dynamic so that e.g. the yearly prices would work in all areas.

nordpool-node's People

Contributors

lastrada avatar lekkimworld avatar perstromqvist avatar samuelmr avatar zinen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nordpool-node's Issues

Invalid params

Hi. Any idea why I'm keep getting this error?

{ status: '-2001', message: 'INVALID PARAMS' }

I've got it before, but just once. Now it's every time I try.

jensjakob/charge-cheap#17

Problem receiving prices for next full night

Hi.

I have problems with hourly prices while using "from" and "to". I would like to receive prices for next night, both before and after midnight. It's ok to do two requests if needed, but I can't understand how the "from" and "to" works for hourly prices.

I thought if I wasn't using any of the "from" or "to" option, the latest prices would been received. But today (before midnight) I was still just receiving the same days prices. Using "from" or "to" field also sometimes just give me one price, not hourly prices, even if using the hourly function. It also seems to be some problem using both "from" and "to" having a "to large range"...

I will try to have a look at the problem, but maybe someone has notice this problem before and have a simple suggestion or solution.

moment.js development is stale

As stated in the project status of moment.js documentation further development are stopped and the teams itself says:

we would like to discourage Moment from being used in new projects going forward

The moment.js links to dayjs as the smallest alternative to be a applicable successor.

@samuelmr would you consider a pull request with moment replaced by dayjs?

URL invalid

Nordpool has changed URL from nordpoolspot to nordpoolgroup tus generating a error in Homebridge.

[25/04/2023, 06:09:00] FetchError: request to http://www.nordpoolspot.com/api/marketdata/page/10?currency=,SEK,SEK,SEK&endDate=25-04-2023 failed, reason: getaddrinfo ENOTFOUND www.nordpoolspot.com
at ClientRequest. (file:///var/lib/homebridge/node_modules/homebridge-nordpool/node_modules/node-fetch/src/index.js:108:11)
at ClientRequest.emit (node:events:513:28)
at Socket.socketErrorListener (node:_http_client:502:9)
at Socket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21)

Visiting the URL redirects to https://www.nordpoolgroup.com/api/marketdata/page/10?currency=,SEK,SEK,SEK&endDate=25-04-2023

Code in npm module is not the same as when you clone the repo

I was experiencing an issue parsing the float value that sometimes contained a space. I fixed the issue and wanted to create a PR so I clone the repo and started writing a test for the issue only to figure out the issue was fixed in my fork (removing spaces from the value in prices.js at line 114). Could you republish the module to npm to ensure the npm module contains the fix?

Thx

Update test dependencies

The output of npm outdated:

Package  Current  Wanted  Latest  Location
mocha      3.5.3   3.5.3   8.2.1  nordpool
nock       9.6.1   9.6.1  13.0.5  nordpool

not working

when i try to run the code it just says: import
{nordpool} from 'nordpool'
^
SyntaxError: invalid syntax

date stamp given under "Area" for FI?

Thank you for this node!

I just realized something a bit strange, the date for me in the object is under Area, like this;

payload: array[48]
[0 … 9]
0: object
Area: "10-03-2023"
Timestamp: "2023-03-10 00:00"
StartTime: "2023-03-10 00:00"
EndTime: "2023-03-10 01:00"
Price: 94.68
Valuta: "EUR/MWh"

My Area is set to FI in the node setting. It looks like this might be a bug for the FI area?

It's nice to have the date, so I can easily calculate things only for today's date, but it looks a bit strange like that.

I checked and changed the area to SE1 and I get SE1 reported correctly as Area, and I lose the datestamp:

payload: array[48]
[0 … 9]
0: object
Area: "SE1"
Timestamp: "2023-03-10 00:00"
StartTime: "2023-03-10 00:00"
EndTime: "2023-03-10 01:00"
Price: 50.89
Valuta: "EUR/MWh"

request is deprecated

request and therefor also request-promise is deprecated.

A tiny sized replacement could be node-fetch as request author link to here.

@samuelmr would you consider a pull request with request replaced by node-fetch?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.