basic_yahoo_finance 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +1 -43
- data/lib/basic_yahoo_finance/version.rb +1 -1
- data/lib/basic_yahoo_finance.rb +27 -9
- metadata +4 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95217809498bd8cbfca27e6b16191b2c348efd4248ac1156ce373040c0fa8b2d
|
4
|
+
data.tar.gz: f1fecddfbc95ac38f1904641c7427cc5c308b00d4db82cf878f8a38e6c093c23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 808b8f88f8ba6079a855a54d6a2f7eac8f92d4b4e571e1f8c0c148adab9f156938708715a847c5243689bde28ce75aa77021eef492ce08400db76f462012c149
|
7
|
+
data.tar.gz: 77cad70b5ccd110f6b04824908d1ddbadf80c2b75b97a56ec69ce0cfd257bdbe714e4b162f631448a033208a4812e40aa1ade641cc1ef537358c8162a628a240
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [0.5.2] - 2025-03-29
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
|
12
|
+
- Update gem dependencies and Ruby version
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
|
16
|
+
- Broken API query generating HTTP 404 Not Found error
|
17
|
+
|
18
|
+
### Removed
|
19
|
+
|
20
|
+
- Possibility to use modules in query
|
21
|
+
|
8
22
|
## [0.5.1] - 2023-07-14
|
9
23
|
|
10
24
|
### Changed
|
data/README.md
CHANGED
@@ -31,9 +31,6 @@ Instantiate the `Query` class and use the quotes method on it with either a sing
|
|
31
31
|
# Query a stock, with the price module
|
32
32
|
|
33
33
|
query = BasicYahooFinance::Query.new
|
34
|
-
data = query.quotes('AVEM', 'price')
|
35
|
-
|
36
|
-
# OR the module argument can be left empty as the price module is the default
|
37
34
|
data = query.quotes('AVEM')
|
38
35
|
|
39
36
|
# Query multiple stocks
|
@@ -56,45 +53,6 @@ data["AVEM"]["regularMarketPrice"]["raw"]
|
|
56
53
|
# 52.72
|
57
54
|
```
|
58
55
|
|
59
|
-
## Modules
|
60
|
-
|
61
|
-
While `price` is a common module, its not the only one. A list of known modules include:
|
62
|
-
|
63
|
-
```
|
64
|
-
assetProfile
|
65
|
-
balanceSheetHistory
|
66
|
-
balanceSheetHistoryQuarterly
|
67
|
-
calendarEvents
|
68
|
-
cashflowStatementHistory
|
69
|
-
cashflowStatementHistoryQuarterly
|
70
|
-
defaultKeyStatistics
|
71
|
-
earnings
|
72
|
-
earningsHistory
|
73
|
-
earningsTrend
|
74
|
-
esgScores
|
75
|
-
financialData
|
76
|
-
fundOwnership
|
77
|
-
incomeStatementHistory
|
78
|
-
incomeStatementHistoryQuarterly
|
79
|
-
indexTrend
|
80
|
-
industryTrend
|
81
|
-
insiderHolders
|
82
|
-
insiderTransactions
|
83
|
-
institutionOwnership
|
84
|
-
majorDirectHolders
|
85
|
-
majorHoldersBreakdown
|
86
|
-
netSharePurchaseActivity
|
87
|
-
price
|
88
|
-
recommendationTrend
|
89
|
-
secFilings
|
90
|
-
sectorTrend
|
91
|
-
summaryDetail
|
92
|
-
summaryProfile
|
93
|
-
upgradeDowngradeHistory
|
94
|
-
pageviews
|
95
|
-
quotetype
|
96
|
-
```
|
97
|
-
|
98
56
|
## Development
|
99
57
|
|
100
58
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -107,7 +65,7 @@ As linter RuboCop is used and can be run using:
|
|
107
65
|
|
108
66
|
$ rake rubocop
|
109
67
|
|
110
|
-
This gem is being developed with Ruby 3.
|
68
|
+
This gem is being developed with Ruby 3.3 but should be downward compatible with at least all supported versions of Ruby.
|
111
69
|
|
112
70
|
## Contributing
|
113
71
|
|
data/lib/basic_yahoo_finance.rb
CHANGED
@@ -11,21 +11,28 @@ require_relative "basic_yahoo_finance/version"
|
|
11
11
|
module BasicYahooFinance
|
12
12
|
# Class to send queries to Yahoo Finance API
|
13
13
|
class Query
|
14
|
-
API_URL = "https://
|
14
|
+
API_URL = "https://query1.finance.yahoo.com"
|
15
|
+
COOKIE_URL = "https://fc.yahoo.com"
|
16
|
+
CRUMB_URL = "https://query1.finance.yahoo.com/v1/test/getcrumb"
|
17
|
+
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " \
|
18
|
+
"Chrome/90.0.4421.0 Safari/537.36 Edg/90.0.810.1"
|
15
19
|
|
16
20
|
def initialize(cache_url = nil)
|
17
21
|
@cache_url = cache_url
|
22
|
+
@cookie = fetch_cookie
|
23
|
+
@crumb = fetch_crumb(@cookie)
|
18
24
|
end
|
19
25
|
|
20
|
-
def quotes(symbol
|
26
|
+
def quotes(symbol) # rubocop:disable Metrics/MethodLength
|
21
27
|
hash_result = {}
|
22
28
|
symbols = make_symbols_array(symbol)
|
23
29
|
http = Net::HTTP::Persistent.new
|
24
|
-
http.override_headers["User-Agent"] =
|
30
|
+
http.override_headers["User-Agent"] = USER_AGENT
|
31
|
+
http.override_headers["Cookie"] = @cookie
|
25
32
|
symbols.each do |sym|
|
26
|
-
uri = URI("#{API_URL}/
|
33
|
+
uri = URI("#{API_URL}/v7/finance/quote?symbols=#{sym}&crumb=#{@crumb}")
|
27
34
|
response = http.request(uri)
|
28
|
-
hash_result.store(sym, process_output(JSON.parse(response.body)
|
35
|
+
hash_result.store(sym, process_output(JSON.parse(response.body)))
|
29
36
|
rescue Net::HTTPBadResponse, Net::HTTPNotFound, Net::HTTPError, Net::HTTPServerError, JSON::ParserError
|
30
37
|
hash_result.store(sym, "HTTP Error")
|
31
38
|
end
|
@@ -37,6 +44,17 @@ module BasicYahooFinance
|
|
37
44
|
|
38
45
|
private
|
39
46
|
|
47
|
+
def fetch_cookie
|
48
|
+
http = Net::HTTP.get_response(URI(COOKIE_URL), { "Keep-Session-Cookies" => "true" })
|
49
|
+
cookies = http.get_fields("set-cookie")
|
50
|
+
cookies[0].split(";")[0]
|
51
|
+
end
|
52
|
+
|
53
|
+
def fetch_crumb(cookie)
|
54
|
+
http = Net::HTTP.get_response(URI(CRUMB_URL), { "User-Agent" => USER_AGENT, "Cookie" => cookie })
|
55
|
+
http.read_body
|
56
|
+
end
|
57
|
+
|
40
58
|
def make_symbols_array(symbol)
|
41
59
|
if symbol.instance_of?(Array)
|
42
60
|
symbol
|
@@ -45,14 +63,14 @@ module BasicYahooFinance
|
|
45
63
|
end
|
46
64
|
end
|
47
65
|
|
48
|
-
def process_output(json
|
66
|
+
def process_output(json)
|
49
67
|
# Handle error from the API that the code isn't found
|
50
|
-
return json["
|
68
|
+
return json["error"] unless json["error"].nil?
|
51
69
|
|
52
|
-
result = json["
|
70
|
+
result = json["quoteResponse"]&.dig("result", 0)
|
53
71
|
return nil if result.nil?
|
54
72
|
|
55
|
-
result
|
73
|
+
result
|
56
74
|
end
|
57
75
|
end
|
58
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basic_yahoo_finance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-03-29 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: net-http-persistent
|
@@ -30,20 +29,6 @@ dependencies:
|
|
30
29
|
- - ">="
|
31
30
|
- !ruby/object:Gem::Version
|
32
31
|
version: 4.0.2
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: minitest-emoji
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '2.0'
|
40
|
-
type: :development
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - "~>"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '2.0'
|
47
32
|
description: Very simple Ruby API for Yahoo Finance in order to query the stock market
|
48
33
|
email:
|
49
34
|
- hello@towards.ch
|
@@ -69,7 +54,6 @@ metadata:
|
|
69
54
|
homepage_uri: https://towards.ch
|
70
55
|
rubygems_mfa_required: 'true'
|
71
56
|
source_code_uri: https://github.com/towards/basic_yahoo_finance
|
72
|
-
post_install_message:
|
73
57
|
rdoc_options: []
|
74
58
|
require_paths:
|
75
59
|
- lib
|
@@ -77,15 +61,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
61
|
requirements:
|
78
62
|
- - ">="
|
79
63
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
64
|
+
version: 3.0.0
|
81
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
66
|
requirements:
|
83
67
|
- - ">="
|
84
68
|
- !ruby/object:Gem::Version
|
85
69
|
version: '0'
|
86
70
|
requirements: []
|
87
|
-
rubygems_version: 3.
|
88
|
-
signing_key:
|
71
|
+
rubygems_version: 3.6.2
|
89
72
|
specification_version: 4
|
90
73
|
summary: Basic Yahoo Finance API to query stock prices
|
91
74
|
test_files: []
|