Skip to content

Commit

Permalink
Add commodities (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
roryl23 authored Oct 6, 2024
1 parent 538accd commit f7fa379
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "AlphaVantage"
uuid = "6348297c-a006-11e8-3a05-9bbf8830fd7b"
license = "MIT"
authors = ["Ellis Valentiner <ellisvalentiner@gmail.com>", "Dean Markwick <dean.markwick@talk21.com>"]
version = "0.4.1"
version = "0.5.0"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ If you encounter a clear bug, please file a minimal reproducible example on GitH
## Features

* Intraday prices for stocks, currencies and cryptocurrencies.
* Daily, weekly and monthly prices for stocks, currencies and cryptocurrencies.
* Daily, weekly and monthly prices for stocks, currencies, cryptocurrencies, and commodities.
* Technical indicators for stock prices.
* Crypto currency health index from Flipside Crypto.
* Fundamental data for stocks.
Expand Down
4 changes: 4 additions & 0 deletions src/AlphaVantage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ include("sector_performance.jl")
include("fundamental_values.jl")
include("fundamentals.jl")
include("economic_indicators.jl")
include("commodities.jl")

# avclient
export key, AlphaVantageClient, AlphaVantageResponse
Expand Down Expand Up @@ -69,4 +70,7 @@ export
federal_fund_rate,
cpi

# commodities
# `WTI` etc are exported in macro

end # module
21 changes: 21 additions & 0 deletions src/commodities.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
for func in (:wti, :brent, :natural_gas, :copper, :aluminum, :wheat, :corn, :cotton, :coffee, :all_commodities)
x = "$(func)"
fname = Symbol(x)
@eval begin
function ($fname)(interval::Union{String, Nothing}=nothing, client = GLOBAL[], datatype::Union{String, Nothing}=nothing, parser = "default")
@argcheck in(interval, ["daily", "weekly", "monthly", nothing])
@argcheck in(datatype, ["json", "csv", nothing])
params = Dict(
"function"=>uppercase($x),
"interval"=>isnothing(interval) ? "monthly" : interval,
"datatype"=>isnothing(datatype) ? "csv" : datatype,
"apikey"=>key(client)
)
uri = _build_uri(client.scheme, client.host, "query", params)
data = retry(_get_request, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000))(uri)
p = _parser(parser, datatype)
return p(data)
end
export $fname
end
end

0 comments on commit f7fa379

Please sign in to comment.