ya_finance 0.0.3 → 0.0.5

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: b05bad6d63cce37688dad5df50aa50d958905beec2cc5776fdba3a5c69759678
4
- data.tar.gz: 842da8f452080372fda65ff08ae6a462209ea73364244ef489aa671da60226c5
3
+ metadata.gz: d3b1ab8f58be71d6362b157a5265cfda7f9c34c12a432a57409a86b07248ebcd
4
+ data.tar.gz: 572e07d9c6d388faad402ff06de29e9526a0e27874b5760dc6096afd22580834
5
5
  SHA512:
6
- metadata.gz: d6ab9b8c5b53a681a6c2efed8bb1073186f12070ba5b46e180dc73c1a35ce7e7e5ad90ae4063e9627af08324173a266c6aae9cc55f8a2a3b1d73d4d4c6f3eab2
7
- data.tar.gz: 8e66f9c6567b61b4057e30363f27651698a411449061e5a0b18444005937ca4679169a759de58d55e6ededdcea8c1845e90c8f5a278a148cb73423640c9d5c64
6
+ metadata.gz: 2cd6e4c8c761f8795c63af3d76305df06480fc78fbca8929873a1a7adc0d5c1978f2b6f9260873b4822f31b2bcac9fdbbca44f108d6894b4ff77b28d651f22ae
7
+ data.tar.gz: aeceee608eac2fb0ced6432f00b8a9a7ba539f828a23926ccf1dd73b7953e5a7905aeb48da7c71e458d9a8f53bb9ab098e474ac4c82cab2af967400539f098eb
data/Gemfile CHANGED
@@ -1,7 +1,9 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
+ gem 'excon'
3
4
  group :test do
4
- gem 'mocha'
5
+ gem 'webmock'
6
+ gem 'vcr'
5
7
  end
6
8
 
7
9
  gem "oga", "~> 3.4"
@@ -24,10 +24,20 @@ class YaFinance
24
24
  YaFinance::Scrapper::Holders.process(response)
25
25
  end
26
26
  def options
27
- fetch_v7("options/#{@ticker}")['optionChain']['result'][0]['options']
27
+ response = fetch_v7("options/#{@ticker}")['optionChain']['result'][0]['options'][0]
28
+ {
29
+ puts: remap_options(response['puts']),
30
+ calls: remap_options(response['calls']),
31
+ }
28
32
  end
29
33
 
30
34
  private
31
-
35
+ def remap_options(opts)
36
+ opts.map{|opt|
37
+ opt['expirationParsed'] = Time.at(opt['expiration']) unless opt['expiration'].nil?
38
+ opt['lastTradeDateParsed'] = Time.at(opt['lastTradeDate']) unless opt['lastTradeDate'].nil?
39
+ opt
40
+ }
41
+ end
32
42
  end
33
43
  end
@@ -1,3 +1,4 @@
1
+ require 'excon'
1
2
  class YaFinance::Http
2
3
  ROOT_URL = 'https://finance.yahoo.com/'
3
4
  QUERY_URL = "https://query2.finance.yahoo.com"
@@ -10,20 +11,12 @@ class YaFinance::Http
10
11
 
11
12
 
12
13
  def self.fetch(uri)
13
- @@http ||= Net::HTTP::Persistent.new
14
- @@http.override_headers["User-Agent"] = "YaFin/#{YaFinance::VERSION}"
15
- @@http.request(uri)
16
- end
17
- def self.shutdown
18
- @@http.shutdown
19
- @@http = nil
14
+ Excon.get(uri.to_s, persistent: true, headers: {"User-Agent" => "YaFin/#{YaFinance::VERSION}"})
20
15
  end
21
16
 
22
17
  module FetchRoot
23
18
  def fetch_root(path)
24
19
  uri = URI("#{ROOT_URL}/#{path}")
25
- puts uri
26
- # @TODO: make a crawler?
27
20
  YaFinance::Http.fetch(uri).body
28
21
  end
29
22
  end
@@ -31,8 +24,6 @@ class YaFinance::Http
31
24
  module FetchHistorical
32
25
  def fetch_historical(path)
33
26
  uri = URI("#{HISTORICAL_URL}/#{path}")
34
- puts uri
35
- # @TODO: make a crawler?
36
27
  YaFinance::Http.fetch(uri).body
37
28
  end
38
29
  end
@@ -40,8 +31,6 @@ class YaFinance::Http
40
31
  module FetchFundamentals
41
32
  def fetch_fundamentals(path)
42
33
  uri = URI("#{FUNDAMENTALS_URL}/#{path}")
43
- puts uri
44
- # @TODO: make a crawler?
45
34
  YaFinance::Http.fetch(uri).body
46
35
  end
47
36
  end
@@ -49,14 +38,12 @@ class YaFinance::Http
49
38
  module FetchV7
50
39
  def fetch_v7(path)
51
40
  uri = URI("#{V7_URL}/#{path}")
52
- puts uri
53
41
  JSON.parse(YaFinance::Http.fetch(uri).body)
54
42
  end
55
43
  end
56
44
  module FetchV8
57
45
  def fetch_v8(path)
58
46
  uri = URI("#{V8_URL}/#{path}")
59
- puts uri
60
47
  JSON.parse(YaFinance::Http.fetch(uri).body)
61
48
  end
62
49
  end
@@ -65,9 +52,7 @@ class YaFinance::Http
65
52
  def fetch_v6(mod)
66
53
  # modules = ['financialData', 'quoteType', 'defaultKeyStatistics', 'assetProfile', 'summaryDetail']
67
54
  uri = URI("#{V6_URL}/#{ERB::Util.url_encode(@ticker)}?modules=#{mod}")
68
- puts "#{uri}"
69
55
  json = JSON.parse(YaFinance::Http.fetch(uri).body)
70
- YaFinance::Http.shutdown
71
56
 
72
57
  if json["quoteSummary"] && json["quoteSummary"]["error"]
73
58
  return json["quoteSummary"]["error"]
@@ -32,9 +32,7 @@ class YaFinance::Past
32
32
  end
33
33
 
34
34
  def capital_gains
35
- require 'byebug'
36
35
  evs = fetch_v8("chart/#{@ticker}?events=capitalGains#{OPTIONS}")['chart']['result'][0]['events']
37
- debugger
38
36
  end
39
37
 
40
38
  def actions
@@ -5,11 +5,13 @@ class YaFinance
5
5
  class Holders
6
6
  def self.process(html)
7
7
  doc = Oga.parse_xml(html)
8
- #TODO: organize result tables
9
- holders = doc.css('[data-test] td').map{|e| e.text }
10
- institutional = doc.css('.BdT td').map{|e| e.text } # 0
11
- funds = doc.css('.BdT td').map{|e| e.text } # 1
12
- {holders: holders, institutional: institutional, funds: funds}
8
+ table = doc.css('[data-test] td').map{|e| e.text }
9
+ {
10
+ insiders_percent: table[0].to_f,
11
+ intitutions_percent: table[2].to_f,
12
+ institutions_float: table[4].to_f,
13
+ institutions_amount: table[6].to_i
14
+ }
13
15
  end
14
16
  end
15
17
  end
data/lib/ya_finance.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "net/http/persistent" # @TODO: how to remove?
4
3
  require "net/http"
5
4
  require "open-uri"
6
5
  require "ostruct"
@@ -27,4 +26,3 @@ end
27
26
 
28
27
  Dir[File.join(__dir__, 'ya_finance', '*.rb')].each { |file| require file }
29
28
  Dir[File.join(__dir__, 'ya_finance/scrapper', '*.rb')].each { |file| require file }
30
- Dir[File.join(__dir__, 'ya_finance/insider_trading', '*.rb')].each { |file| require file }
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ya_finance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Fonseca Engel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-10 00:00:00.000000000 Z
11
+ date: 2023-08-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Financial Information consumer with CLI working in 2023
13
+ description: Financial Information consumer with CLI working in 2023 - reads from
14
+ Yahoo Finances
14
15
  email: gabrielfengel@gmail.com
15
16
  executables:
16
17
  - yafin
@@ -51,5 +52,5 @@ requirements: []
51
52
  rubygems_version: 3.3.7
52
53
  signing_key:
53
54
  specification_version: 4
54
- summary: Financial Information 2023 - Yahoo Finances
55
+ summary: Financial Information 2023 - reads from Yahoo Finances
55
56
  test_files: []