UK Gas Market Information

Timothy Wong

2019-05-14

The National Grid publishes live market information through Market Information Provision Initiative (MIPI) API. It hosts a large volume of data (over 13,500 data items)1 and is used extensively on a daily basis.

Calling the API

The function dataItemExplorer calls the MIPI API and returns data from the Data Item Explorer. The first argument dataitems is a character vector of data items where multiple values are accepted. It must match with the data items provided on the Data Item Explorer. This function also requires fromdate and todate which specify the date range to return data from. The return type is a data.frame object.

response <- dataItemExplorer(dataitems = c("Storage Injection, Actual",
                                           "Storage Withdrawal, Actual"),
                             fromdate = "2017-01-01",
                             todate = "2017-12-31")
head(response, 10)
ApplicableAt ApplicableFor Value GeneratedTimeStamp QualityIndicator Substituted CreatedDate PublicationObjectName
2017-02-10 15:00:00 2017-01-01 654339382 2017-02-10 15:01:38 2017-02-10 15:01:38 Storage Injection, Actual
2017-02-10 15:00:00 2017-01-02 191923757 2017-02-10 15:01:38 2017-02-10 15:01:39 Storage Injection, Actual
2017-02-10 15:00:00 2017-01-03 65808124 2017-02-10 15:01:38 2017-02-10 15:01:38 Storage Injection, Actual
2017-02-10 15:00:00 2017-01-04 2743671 2017-02-10 15:01:38 2017-02-10 15:01:39 Storage Injection, Actual
2017-02-10 15:00:00 2017-01-05 72190668 2017-02-10 15:01:38 2017-02-10 15:01:40 Storage Injection, Actual
2017-02-10 15:00:00 2017-01-06 2582168 2017-02-10 15:01:38 2017-02-10 15:01:46 Storage Injection, Actual
2017-02-10 15:00:00 2017-01-07 202786018 2017-02-10 15:01:38 2017-02-10 15:01:40 Storage Injection, Actual
2017-02-10 15:00:00 2017-01-08 354960293 2017-02-10 15:01:38 2017-02-10 15:01:45 Storage Injection, Actual
2017-02-10 15:00:00 2017-01-09 247556567 2017-02-10 15:01:38 2017-02-10 15:01:39 Storage Injection, Actual
2017-02-10 15:00:00 2017-01-10 121739669 2017-02-10 15:01:38 2017-02-10 15:01:45 Storage Injection, Actual

Using batch mode

The National Grid API has certain limit of the size of the query. As a result, we need to implement batch mode if the query it too large. The batchsize argument can be configured to limit the size of each API call. It will loop through all dates iteratively and return all results.

response <- dataItemExplorer(dataitems = c("Storage Injection, Actual",
                                           "Storage Withdrawal, Actual"),
                             fromdate = "2017-01-01",
                             todate = "2017-12-31",
                             batchsize = 20)

Visualising the API response

Since the return type is a data.frame object, users can use standard plotting packages such as ggplot2 to visualise the response.

library(ggplot2)
#> Registered S3 methods overwritten by 'ggplot2':
#>   method         from 
#>   [.quosures     rlang
#>   c.quosures     rlang
#>   print.quosures rlang
qplot(x = ApplicableFor,
      y = Value,
      data = response,
      colour = PublicationObjectName,
      geom = "line") + 
  theme(legend.position = "bottom")


  1. According to the National Grid