basic_yahoo_finance 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -2
- data/lib/basic_yahoo_finance/cache.rb +9 -0
- data/lib/basic_yahoo_finance/util.rb +37 -0
- data/lib/basic_yahoo_finance/version.rb +1 -1
- data/lib/basic_yahoo_finance.rb +8 -2
- metadata +23 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc49f81262f0b33b698c042829def51cfc98c1bf75e29fce773cc01ab0c5ab54
|
4
|
+
data.tar.gz: 93070ae61360d85c31e1506fbed33d35c6e47ab9d5d98fa67ab6bb4dc56d25f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f38f40a8f6e272cad2bfcd0f6eeea27bcda86bfdd0ac0e0cde3f1d972ef33aea156cd65e47b876718b1bcb268c8bf1f28e65b6c8f8f2053a33673fa274799a33
|
7
|
+
data.tar.gz: a0e36b64d40a44e4c2b569202422ebf7cd8b56f72e6e01af2cd869eddcb757c1c05caa3658ea618efbbe0a6e8a94970479fd72ca2aa6031d2e57563f9917565a
|
data/CHANGELOG.md
CHANGED
@@ -5,14 +5,29 @@ 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.
|
8
|
+
## [0.3.0] - 2022-05-06
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Initial setup for redis caching
|
13
|
+
- Utility class with symbols generator used in currency queries
|
14
|
+
- Foreign exchange symbol generator and finder
|
15
|
+
- Rubygems MFA requirement
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
|
19
|
+
- Fix format of returned symbol for FX symbol finder
|
20
|
+
- Update gems
|
21
|
+
- Parse URI before opening request to API
|
22
|
+
|
23
|
+
## [0.2.0] - 2021-02-05
|
9
24
|
|
10
25
|
### Changed
|
11
26
|
|
12
27
|
- User-Agent header in API requests to announce as "BYF" instead of default "Ruby"
|
13
28
|
- Invalid ticker test to new behaviour of the API when the ticker does not exist
|
14
29
|
|
15
|
-
## 0.1.0 - 2021-01-29
|
30
|
+
## [0.1.0] - 2021-01-29
|
16
31
|
|
17
32
|
### Added
|
18
33
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BasicYahooFinance
|
4
|
+
# Small useful utility methods
|
5
|
+
class Util
|
6
|
+
# Find correct FX symbol in quotes as the symbol format can vary
|
7
|
+
def self.find_fx_symbol(quotes, currency1, currency2)
|
8
|
+
# Exception for USDCHF=X symbol as it is sometimes returned as CHF=X
|
9
|
+
if currency1 == "USD" && currency2 == "CHF"
|
10
|
+
quotes["USDCHF=X"].nil? ? "CHF=X" : "#{currency1}CHF=X"
|
11
|
+
else
|
12
|
+
"#{currency1}#{currency2}=X"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Generate currency symbols based on array of currencies and base currency
|
17
|
+
def self.generate_currency_symbols(currencies, base_currency)
|
18
|
+
currency_symbols = []
|
19
|
+
currencies.each do |currency|
|
20
|
+
next if currency == base_currency
|
21
|
+
|
22
|
+
currency_symbols.push("#{currency}#{base_currency}=X")
|
23
|
+
end
|
24
|
+
currency_symbols.join(",")
|
25
|
+
end
|
26
|
+
|
27
|
+
# Generate symobol for foreign exchange rate lookup
|
28
|
+
def self.generate_fx_symbol(currency1, currency2)
|
29
|
+
# Exception for USD against CHF which is formatted as 'CHF=X'
|
30
|
+
if currency1 == "USD" && currency2 == "CHF"
|
31
|
+
"#{currency2}=X"
|
32
|
+
else
|
33
|
+
"#{currency1}/#{currency2}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/basic_yahoo_finance.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require "json"
|
4
4
|
require "open-uri"
|
5
|
+
require_relative "basic_yahoo_finance/cache"
|
6
|
+
require_relative "basic_yahoo_finance/util"
|
5
7
|
require_relative "basic_yahoo_finance/version"
|
6
8
|
|
7
9
|
module BasicYahooFinance
|
@@ -9,11 +11,15 @@ module BasicYahooFinance
|
|
9
11
|
class Query
|
10
12
|
API_URL = "https://query1.finance.yahoo.com"
|
11
13
|
|
14
|
+
def initialize(cache_url = nil)
|
15
|
+
@cache_url = cache_url
|
16
|
+
end
|
17
|
+
|
12
18
|
def quotes(symbols)
|
13
19
|
symbols_value = generate_symbols_value(symbols)
|
14
20
|
begin
|
15
|
-
|
16
|
-
|
21
|
+
url = URI.parse("#{API_URL}/v7/finance/quote?symbols=#{symbols_value}")
|
22
|
+
uri = URI.open(url, "User-Agent" => "BYF/#{BasicYahooFinance::VERSION}")
|
17
23
|
process_output(JSON.parse(uri.read))
|
18
24
|
rescue OpenURI::HTTPError
|
19
25
|
empty_symbols_hash(symbols)
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basic_yahoo_finance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: minitest-emoji
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -35,6 +49,8 @@ files:
|
|
35
49
|
- LICENSE
|
36
50
|
- README.md
|
37
51
|
- lib/basic_yahoo_finance.rb
|
52
|
+
- lib/basic_yahoo_finance/cache.rb
|
53
|
+
- lib/basic_yahoo_finance/util.rb
|
38
54
|
- lib/basic_yahoo_finance/version.rb
|
39
55
|
homepage: https://towards.ch
|
40
56
|
licenses:
|
@@ -45,8 +61,9 @@ metadata:
|
|
45
61
|
changelog_uri: https://github.com/towards/basic_yahoo_finance/blob/master/CHANGELOG.md
|
46
62
|
documentation_uri: https://www.rubydoc.info/gems/basic_yahoo_finance
|
47
63
|
homepage_uri: https://towards.ch
|
64
|
+
rubygems_mfa_required: 'true'
|
48
65
|
source_code_uri: https://github.com/towards/basic_yahoo_finance
|
49
|
-
post_install_message:
|
66
|
+
post_install_message:
|
50
67
|
rdoc_options: []
|
51
68
|
require_paths:
|
52
69
|
- lib
|
@@ -61,8 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
78
|
- !ruby/object:Gem::Version
|
62
79
|
version: '0'
|
63
80
|
requirements: []
|
64
|
-
rubygems_version: 3.
|
65
|
-
signing_key:
|
81
|
+
rubygems_version: 3.3.7
|
82
|
+
signing_key:
|
66
83
|
specification_version: 4
|
67
84
|
summary: Basic Yahoo Finance API to query stock prices
|
68
85
|
test_files: []
|