diff --git a/Project.toml b/Project.toml index bbd56d6..d96c7d4 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MarketData" uuid = "945b72a4-3b13-509d-9b46-1525bb5c06de" authors = ["JuliaQuant "] -version = "0.15.0" +version = "0.15.1" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" @@ -17,7 +17,7 @@ CSV = "0.7, 0.8, 0.9, 0.10" HTTP = "0.8, 0.9, 1.0" JSON3 = "1" Reexport = "0.2, 1.0" -TimeSeries = "0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.24" +TimeSeries = "0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.24, 0.25" julia = "1.6" [extras] diff --git a/src/downloads.jl b/src/downloads.jl index f43f765..ce8218f 100644 --- a/src/downloads.jl +++ b/src/downloads.jl @@ -146,7 +146,7 @@ function fred(data::AbstractString="CPIAUCNS") end """ - ons(timeseries::String="L522", dataset::String="MM23")::TimeArray + ons(timeseries::String="L522")::TimeArray The ons() method is a wrapper to download financial and economic time series data from the Office for National Statistics (ONS). @@ -161,9 +161,9 @@ is the Consumer Price Index including housing costs (CPIH) which is the ONS’s # Examples ```julia -UK_RPI = ("CHAW","MM23") -UK_CPI = ("D7BT","MM23") -UK_CPIH = ("L522","MM23") +UK_RPI = ("CHAW") +UK_CPI = ("D7BT") +UK_CPIH = ("L522") ``` # References @@ -175,11 +175,15 @@ https://www.ons.gov.uk/timeseriestool - fred() which accesses the St. Louis Federal Reserve financial and economic data sets. - yahoo() which is a wrapper from downloading financial time series for stocks from Yahoo Finance. """ -function ons(timeseries::AbstractString = "L522", dataset::AbstractString = "MM23") - url = "https://api.ons.gov.uk/dataset/$dataset/timeseries/$timeseries/data" +function ons(timeseries::AbstractString = "L522") + url = "https://api.beta.ons.gov.uk/v1/search?content_type=timeseries&cdids=$timeseries" res = HTTP.get(url) @assert res.status == 200 json = JSON3.read(HTTP.payload(res)) + uri = json["items"][1]["uri"] + res = HTTP.get("https://api.beta.ons.gov.uk/v1/data?uri=$uri") + @assert res.status == 200 + json = JSON3.read(HTTP.payload(res)) ta = nothing if "months" in keys(json) data = json["months"] @@ -203,3 +207,6 @@ function ons(timeseries::AbstractString = "L522", dataset::AbstractString = "MM2 end TimeArray(ta, meta = json["description"]) end + +# For compatibility with earlier versions +ons(timeseries::AbstractString, dataset::AbstractString) = ons(timeseries) \ No newline at end of file