yahoo_finance_client 0.6.0 → 0.7.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 +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/README.md +10 -0
- data/lib/yahoo_finance_client/stock.rb +43 -0
- data/lib/yahoo_finance_client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 396333c73bb2a3098fb03607b6c9f4ac31d6ad2fee6abc425ebacae6a3329ec2
|
|
4
|
+
data.tar.gz: 852fe8f267af779dd3d4beda42f8bc488b09aca401c98fa784351846dad7cb19
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 14e2e611856c718242e81eab276c2a988f5ea98e26ca57b3a951104785b96787e023a38c786b88dd198482a97901220a93e3070c783a1ffc71e1a3bcd82cc8c6
|
|
7
|
+
data.tar.gz: cd126e9ac493657f40ecd7429706d40ee954db197be71bdb37f5f93083d766763db7aa2bb24971aa2fcfa352df60a2e13b87421094f9208949bbeb3a36b43f79
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## [0.7.0] - 2026-05-16
|
|
4
|
+
|
|
5
|
+
- 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.
|
|
6
|
+
|
|
3
7
|
## [0.6.0] - 2026-05-16
|
|
4
8
|
|
|
5
9
|
- Expose Yahoo's `currency` field in `get_quote` / `get_quotes` results so callers can support multi-currency portfolios
|
data/README.md
CHANGED
|
@@ -74,6 +74,16 @@ YahooFinanceClient::Stock.search("apple", count: 5)
|
|
|
74
74
|
|
|
75
75
|
Search returns `[]` if the query is empty or the upstream request fails.
|
|
76
76
|
|
|
77
|
+
### FX Rates
|
|
78
|
+
|
|
79
|
+
Fetch a current FX rate between two ISO 4217 currency codes via Yahoo's `<FROM><TO>=X` quote symbol:
|
|
80
|
+
```ruby
|
|
81
|
+
YahooFinanceClient::Stock.get_fx_rate("EUR", "USD")
|
|
82
|
+
# => 1.0823
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Identity pairs short-circuit to `1.0` without hitting the API. Returns `nil` on any upstream error.
|
|
86
|
+
|
|
77
87
|
### Dividend History
|
|
78
88
|
|
|
79
89
|
Fetch historical dividend payments via the chart API:
|
|
@@ -37,6 +37,19 @@ module YahooFinanceClient
|
|
|
37
37
|
fetch_from_cache(cache_key) || fetch_and_cache_dividend_history(cache_key, symbol, range)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
+
# Fetch the current FX rate between two ISO 4217 currency codes via Yahoo's
|
|
41
|
+
# `<FROM><TO>=X` quote symbol. Returns 1.0 for identity pairs without hitting the API.
|
|
42
|
+
#
|
|
43
|
+
# @param from [String] source currency code (e.g. "EUR")
|
|
44
|
+
# @param to [String] target currency code (e.g. "USD")
|
|
45
|
+
# @return [Float, nil] one unit of `from` expressed in `to`, or nil on error
|
|
46
|
+
def get_fx_rate(from, to)
|
|
47
|
+
return 1.0 if from == to
|
|
48
|
+
|
|
49
|
+
cache_key = "fx_#{from}_#{to}"
|
|
50
|
+
fetch_from_cache(cache_key) || fetch_and_cache_fx_rate(cache_key, from, to)
|
|
51
|
+
end
|
|
52
|
+
|
|
40
53
|
# Search the Yahoo Finance autocomplete index for matching symbols.
|
|
41
54
|
#
|
|
42
55
|
# @param query [String] free-text query (ticker or company name)
|
|
@@ -192,6 +205,36 @@ module YahooFinanceClient
|
|
|
192
205
|
Time.at(value).utc.to_date
|
|
193
206
|
end
|
|
194
207
|
|
|
208
|
+
def fetch_and_cache_fx_rate(cache_key, from, to)
|
|
209
|
+
rate = fetch_fx_rate_data("#{from}#{to}=X")
|
|
210
|
+
store_in_cache(cache_key, rate) if rate
|
|
211
|
+
rate
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def fetch_fx_rate_data(symbol)
|
|
215
|
+
retries = 0
|
|
216
|
+
begin
|
|
217
|
+
parse_fx_response(make_authenticated_request(symbol))
|
|
218
|
+
rescue AuthenticationError
|
|
219
|
+
retries += 1
|
|
220
|
+
retry if retries <= MAX_RETRIES
|
|
221
|
+
nil
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def parse_fx_response(response)
|
|
226
|
+
if auth_error?(response)
|
|
227
|
+
Session.instance.invalidate!
|
|
228
|
+
raise AuthenticationError, "Authentication failed"
|
|
229
|
+
end
|
|
230
|
+
return nil unless response.success?
|
|
231
|
+
|
|
232
|
+
rate = JSON.parse(response.body).dig("quoteResponse", "result", 0, "regularMarketPrice")
|
|
233
|
+
rate&.to_f
|
|
234
|
+
rescue JSON::ParserError
|
|
235
|
+
nil
|
|
236
|
+
end
|
|
237
|
+
|
|
195
238
|
def fetch_and_cache_dividend_history(cache_key, symbol, range)
|
|
196
239
|
data = fetch_dividend_history_data(symbol, range)
|
|
197
240
|
store_in_cache(cache_key, data) unless data.empty?
|