Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: yahoo finance (#98) #99

Merged
merged 1 commit into from
Sep 9, 2024
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
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
Loading