EnergieID / entsoe-py

Python client for the ENTSO-E API (european network of transmission system operators for electricity)
MIT License
406 stars 181 forks source link

Bad request for query_imbalace_prices #19

Closed pkassing closed 5 years ago

pkassing commented 5 years ago

dear all, first of all, thank's very much for developing this package, it saved me a lot of time learning to work with the original API. For the most part it works fine for me and I can easily query load- and generation data on different countries. However I'm having troubles with the "query_imbalance_prices" function. My code looks like this:

from entsoe import EntsoePandasClient
import pandas as pd
from datetime import date

s_token = 'my_token'

year = 2015
start_month = 1 
end_month = 1
end_day = 31
country = 'DE'
client = EntsoePandasClient(api_key= s_token)
 tz ='Europe/Berlin'
start = pd.Timestamp(year = year, month = start_month, day = 1, hour = 0 , minute = 0, tz = tz )
    end = pd.Timestamp(year = year, month = end_month , day = end_day  , hour = 23, minute = 45, tz = tz )
load_df = client.query_imbalance_prices(country_code = country, start = start, end = end, psr_type = 'A95')
HTTPError: 400 Client Error: Bad Request for url: https://transparency.entsoe.eu/api?documentType=A85&controlArea_Domain=10Y1001A1001A83F&psrType=A96

I tried a lot of different types for the psr_type and also included some "DocumentTypes", such as 'A81' - 'A86' and 'BSN-types' ('A95'-'98'), all resulting in the same error. On the API documentation I found that you should also include the bidding zone, which the query function seems not to do.

Am I missing something or should the "query imbalance_prices" function take BSN-types or DocumentTypes instead of psr_types?

thanks very much for your help !

best Philipp

atantet commented 5 years ago

Hi Philipp, If I'm not wrong, psr_type should correspond to a key in entsoe.mappings.PSRTYPE_MAPPINGS See https://github.com/EnergieID/entsoe-py#psr-type Best, Alexis

JrtPec commented 5 years ago

The query_imbalance_prices does its lookup of the country code in DOMAIN_MAPPINGS. Germany is a weird case, because it has country code 'DE' ('10Y1001A1001A83F'), and bidding zones 'DE-AT-LU' ('10Y1001A1001A63L') up until October '18 and bidding zone 'DE-LU' ('10Y1001A1001A82H') starting October '18.

Please try your request with country_code='DE-AT-LU', I think that should work.

This issue is also discussed in part in #9, but I think the whole country/domain/bidding zone thing could be implemented better, I just don't have an elegant idea in mind right now.

jpaduart commented 5 years ago

FYI: Austria was separated last October from the formerly common DE/AT/LU bidding zone so this makes sense. https://www.eex.com/en/about/newsroom/news-detail/preparation-for-the-split-of-the-power-market-bidding-zone-between-germany-and-austria/85380

Op ma 29 apr. 2019 om 18:15 schreef Jan Pecinovsky <notifications@github.com

:

The query_imbalance_prices does its lookup of the country code in DOMAIN_MAPPINGS. Germany is a weird case, because it has country code 'DE' ('10Y1001A1001A83F'), and bidding zones 'DE-AT-LU' ('10Y1001A1001A63L') up until October '18 and bidding zone 'DE-LU' ('10Y1001A1001A82H') starting October '18.

Please try your request with country_code='DE-AT-LU', I think that should work.

This issue is also discussed in part in #9 https://github.com/EnergieID/entsoe-py/issues/9, but I think the whole country/domain/bidding zone thing could be implemented better, I just don't have an elegant idea in mind right now.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/EnergieID/entsoe-py/issues/19#issuecomment-487644333, or mute the thread https://github.com/notifications/unsubscribe-auth/AIO2LUI4OHQT5QYIUIH2BMTPS4NLRANCNFSM4HJEGHFA .

pkassing commented 5 years ago

I tried it with country_code = 'DE-AT-LU' but it still doesn't work. Also, I tried out several psr_types, document types and BSN types:

psr_types = {'B01': 'Biomass','B02': 'Fossil Brown coal/Lignite','B03': 'Fossil Coal-derived gas','B04': 'Fossil Gas',
    'B05': 'Fossil Hard coal','B06': 'Fossil Oil', 'B07': 'Fossil Oil shale', 'B08': 'Fossil Peat', 'B09': 'Geothermal',
    'B10': 'Hydro Pumped Storage', 'B11': 'Hydro Run-of-river and poundage', 'B12': 'Hydro Water Reservoir',
    'B13': 'Marine', 'B14': 'Nuclear', 'B15': 'Other renewable', 'B16': 'Solar','B17': 'Waste',
    'B18': 'Wind Offshore', 'B19': 'Wind Onshore',}

balance_params = {'A81': 'Contracted reserves',
                'A82': 'Accepted offers',
                'A83': 'Activated balancing quantities',
                'A84': 'Activated balancing prices',
                'A85': 'Imbalance prices',
                'A86': 'Imbalance volume',
                 'A88': 'Cross border balancing',
                'A89': 'Contracted reserve prices',
                'A95': 'Frequency containment reserve',
           'A96': 'Automatic frequency restoration reserve',
           'A97': 'Manual frequency restoration reserve',
           'A98': 'Replacement reserve'}

I always get a HTTP 400 Error response.

Are you guys getting information on Frequency Reserve Prices, quantities and volumes ? The information that I am looking for should look like this: Screenshot (31)

Maybe the query_imbalance_prices function is not the correct one to use ?

JrtPec commented 5 years ago

I tried this call

client = EntsoePandasClient(api_key=settings.api_key)

start = pd.Timestamp('20190101', tz='Europe/Berlin')
end = pd.Timestamp('20190102', tz='Europe/Berlin')

client.query_imbalance_prices(country_code='DE-LU', start=start, end=end)

and it works fine for me:

Screenshot 2019-04-30 at 12 11 28

I tried it with some PSR Types though, and couldn't get it to work. Although the API-docs say that PSR type is an optional parameter for imbalance prices.

That being said: What you show in your screenshot are not the Imbalance Prices! It is the Price of Reserved Balancing Reserve. I didn't immediately find it in the API docs, but the API does have "Prices of Procured Balancing Reserves", and "Prices of Activated Balancing Energy".

These methods have not been implemented in the Python Client yet.

I tried Prices of Procured Balancing Reserves as a raw request:

params = {
    'documentType': 'A89',
    'controlArea_Domain': '10YCZ-CEPS-----N',
    'type_MarketAgreement.Type': 'A01',
    'businessType': 'A96'
}
response = client.base_request(params=params, start=start, end=end)
response.raise_for_status()
print(response.text)

That worked fine!

Feel free to implement additional requests from the API and create a pull request if you'd like.

pkassing commented 5 years ago

I think I will try to work with the raw requests :) If I'm free I can try to implement it in the entso-e client.

Thank you for your help!