Skip to content

Commit

Permalink
Merge pull request #99 from Arkoniak/98-fix-yahoo-finance-api
Browse files Browse the repository at this point in the history
fix: yahoo finance (#98)
  • Loading branch information
Arkoniak authored Sep 9, 2024
2 parents fe531f5 + 8864a7b commit b5efb44
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion 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.14.1"
version = "0.15.0"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
18 changes: 14 additions & 4 deletions src/downloads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,22 @@ julia> yahoo(:AAPL, YahooOpt(period1 = start))
"""
function yahoo(sym::AbstractString = "^GSPC", opt::YahooOpt = YahooOpt())
host = rand(["query1", "query2"])
url = "https://$host.finance.yahoo.com/v7/finance/download/$sym"
url = "https://$host.finance.yahoo.com/v8/finance/chart/$sym"
res = HTTP.get(url, query = opt)
@assert res.status == 200
csv = CSV.File(res.body, missingstring = "null")
sch = TimeSeries.Tables.schema(csv)
TimeArray(csv, timestamp = first(sch.names)) |> cleanup_colname!

json_arr = JSON3.read(res.body)
quotes = json_arr.chart.result[1].indicators.quote[1]
input_table = (; timestamp = Dates.Date.(Dates.unix2datetime.(json_arr.chart.result[1].timestamp)),
Open = Vector(quotes.open),
High = Vector(quotes.high),
Low = Vector(quotes.low),
Close = Vector(quotes.close),
AdjClose = Vector(json_arr.chart.result[1].indicators.adjclose[1].adjclose),
Volume = Vector(quotes.volume)
)

TimeArray(input_table, timestamp = :timestamp)
end

yahoo(s::Symbol, opt::YahooOpt = YahooOpt()) = yahoo(string(s), opt)
Expand Down
14 changes: 7 additions & 7 deletions test/downloads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ using MarketData
using Test

@testset "remote" begin
@testset "FRED" begin
ta = fred()
@test ta |> timestamp |> length > 100
ta = fred("DGS10")
@test ta |> timestamp |> length > 100
@test !(ta isa TimeArray{T} where T<:AbstractString)
end
# @testset "FRED" begin
# ta = fred()
# @test ta |> timestamp |> length > 100
# ta = fred("DGS10")
# @test ta |> timestamp |> length > 100
# @test !(ta isa TimeArray{T} where T<:AbstractString)
# end

@testset "Yahoo" begin
t = Dates.now() - Year(2)
Expand Down

2 comments on commit b5efb44

@Arkoniak
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/114815

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.15.0 -m "<description of version>" b5efb44c852e6a672ff2a48e39fba762283f81a9
git push origin v0.15.0

Please sign in to comment.