yahoo_finance_client 0.7.0 → 0.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 396333c73bb2a3098fb03607b6c9f4ac31d6ad2fee6abc425ebacae6a3329ec2
4
- data.tar.gz: 852fe8f267af779dd3d4beda42f8bc488b09aca401c98fa784351846dad7cb19
3
+ metadata.gz: 1a66e077f86f9aaaf9fe6017760905c53641a89c58535ee8e0308492f826e74a
4
+ data.tar.gz: 5ccca2925b92065e274b1747014f6b7b79e464f079ffb57b941839739b7f196c
5
5
  SHA512:
6
- metadata.gz: 14e2e611856c718242e81eab276c2a988f5ea98e26ca57b3a951104785b96787e023a38c786b88dd198482a97901220a93e3070c783a1ffc71e1a3bcd82cc8c6
7
- data.tar.gz: cd126e9ac493657f40ecd7429706d40ee954db197be71bdb37f5f93083d766763db7aa2bb24971aa2fcfa352df60a2e13b87421094f9208949bbeb3a36b43f79
6
+ metadata.gz: c979f457c9a49ed6487d2046d0aad76a7d36989dab90899319c297530e9778a8c37a6628ac21f4ef3785d4a08722bff88222873495487327e7f23897376012a7
7
+ data.tar.gz: dd999d278080461b7837a16a93c9344a1c079eebbf6541d78bf2e07cfc950fed9d60505dda9c4ef22a72cb0fdf52f51e241f0dc7662aacb7ea069f3bb774af1d
data/.rubocop.yml CHANGED
@@ -11,7 +11,7 @@ Metrics/AbcSize:
11
11
  Max: 25
12
12
 
13
13
  Metrics/ClassLength:
14
- Max: 310
14
+ Max: 350
15
15
 
16
16
  Metrics/MethodLength:
17
17
  Max: 11
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## [0.8.0] - 2026-05-17
4
+
5
+ - Add `Stock.get_quote_summary(symbol)` returning `{ sector:, industry: }` via Yahoo's `v10/finance/quoteSummary?modules=assetProfile` endpoint. Returns `nil` for funds, ETFs, or any symbol where the asset profile is empty. Same cookie + crumb auth as the existing quote calls.
6
+
3
7
  ## [0.7.0] - 2026-05-16
4
8
 
5
9
  - Add `Stock.get_fx_rate(from, to)` returning the current FX rate between two ISO 4217 currency codes via Yahoo's `<FROM><TO>=X` quote symbol. Returns `1.0` for identity pairs without hitting the API; returns `nil` on error.
data/README.md CHANGED
@@ -84,6 +84,16 @@ YahooFinanceClient::Stock.get_fx_rate("EUR", "USD")
84
84
 
85
85
  Identity pairs short-circuit to `1.0` without hitting the API. Returns `nil` on any upstream error.
86
86
 
87
+ ### Sector / Industry
88
+
89
+ Fetch the sector and industry for a ticker via Yahoo's `quoteSummary` endpoint:
90
+ ```ruby
91
+ YahooFinanceClient::Stock.get_quote_summary("AAPL")
92
+ # => { sector: "Technology", industry: "Consumer Electronics" }
93
+ ```
94
+
95
+ Returns `nil` for funds, ETFs, or any symbol whose `assetProfile` is empty. Sector data changes rarely — cache aggressively on the caller side.
96
+
87
97
  ### Dividend History
88
98
 
89
99
  Fetch historical dividend payments via the chart API:
@@ -10,6 +10,7 @@ module YahooFinanceClient
10
10
  QUOTE_PATH = "/v7/finance/quote"
11
11
  CHART_PATH = "/v8/finance/chart"
12
12
  SEARCH_PATH = "/v1/finance/search"
13
+ QUOTE_SUMMARY_PATH = "/v10/finance/quoteSummary"
13
14
  SEARCH_BASE_URL = "https://query1.finance.yahoo.com"
14
15
  CACHE_TTL = 300
15
16
  MAX_RETRIES = 2
@@ -50,6 +51,17 @@ module YahooFinanceClient
50
51
  fetch_from_cache(cache_key) || fetch_and_cache_fx_rate(cache_key, from, to)
51
52
  end
52
53
 
54
+ # Fetch the sector and industry for a single ticker via Yahoo's
55
+ # quoteSummary endpoint (`assetProfile` module). Returns nil for funds,
56
+ # ETFs, or any symbol where Yahoo doesn't expose an asset profile.
57
+ #
58
+ # @param symbol [String] stock ticker
59
+ # @return [Hash{Symbol => String}, nil] { sector:, industry: } or nil
60
+ def get_quote_summary(symbol)
61
+ cache_key = "quote_summary_#{symbol}"
62
+ fetch_from_cache(cache_key) || fetch_and_cache_quote_summary(cache_key, symbol)
63
+ end
64
+
53
65
  # Search the Yahoo Finance autocomplete index for matching symbols.
54
66
  #
55
67
  # @param query [String] free-text query (ticker or company name)
@@ -235,6 +247,45 @@ module YahooFinanceClient
235
247
  nil
236
248
  end
237
249
 
250
+ def fetch_and_cache_quote_summary(cache_key, symbol)
251
+ profile = fetch_quote_summary_data(symbol)
252
+ store_in_cache(cache_key, profile) if profile
253
+ profile
254
+ end
255
+
256
+ def fetch_quote_summary_data(symbol)
257
+ retries = 0
258
+ begin
259
+ parse_quote_summary_response(make_quote_summary_request(symbol))
260
+ rescue AuthenticationError
261
+ retries += 1
262
+ retry if retries <= MAX_RETRIES
263
+ nil
264
+ end
265
+ end
266
+
267
+ def make_quote_summary_request(symbol)
268
+ session = Session.instance
269
+ session.ensure_authenticated
270
+ url = "#{session.base_url}#{QUOTE_SUMMARY_PATH}/#{symbol}?modules=assetProfile&crumb=#{session.crumb}"
271
+ HTTParty.get(url, headers: { "User-Agent" => Session::USER_AGENT, "Cookie" => session.cookie })
272
+ end
273
+
274
+ def parse_quote_summary_response(response)
275
+ if auth_error?(response)
276
+ Session.instance.invalidate!
277
+ raise AuthenticationError, "Authentication failed"
278
+ end
279
+ return nil unless response.success?
280
+
281
+ profile = JSON.parse(response.body).dig("quoteSummary", "result", 0, "assetProfile")
282
+ return nil if profile.nil? || profile["sector"].to_s.empty?
283
+
284
+ { sector: profile["sector"], industry: profile["industry"] }
285
+ rescue JSON::ParserError
286
+ nil
287
+ end
288
+
238
289
  def fetch_and_cache_dividend_history(cache_key, symbol, range)
239
290
  data = fetch_dividend_history_data(symbol, range)
240
291
  store_in_cache(cache_key, data) unless data.empty?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YahooFinanceClient
4
- VERSION = "0.7.0"
4
+ VERSION = "0.8.0"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yahoo_finance_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesc Leveque
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-05-16 00:00:00.000000000 Z
10
+ date: 2026-05-17 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: csv