Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MarketData"
uuid = "945b72a4-3b13-509d-9b46-1525bb5c06de"
authors = ["JuliaQuant <https://github.com/JuliaQuant>"]
version = "0.15.0"
version = "0.15.1"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand All @@ -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]
Expand Down
19 changes: 13 additions & 6 deletions src/downloads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -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
Expand All @@ -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"]
Expand All @@ -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)