ya_finance 0.0.3 → 0.0.4

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: 8f482ebdafd39e3fe9ac70a158af5abd450b18661e698bbb1f78617f8cfae18e
4
+ data.tar.gz: d1fcc298fff2126fbde03b8c6bc948d638b2347ff940bae5d3e8aaec65de065b
5
5
  SHA512:
6
- metadata.gz: d6ab9b8c5b53a681a6c2efed8bb1073186f12070ba5b46e180dc73c1a35ce7e7e5ad90ae4063e9627af08324173a266c6aae9cc55f8a2a3b1d73d4d4c6f3eab2
7
- data.tar.gz: 8e66f9c6567b61b4057e30363f27651698a411449061e5a0b18444005937ca4679169a759de58d55e6ededdcea8c1845e90c8f5a278a148cb73423640c9d5c64
6
+ metadata.gz: 181cf8a11afb8c4fbd6e7ef932048e0f400458dba45ace5148b81f580f8951e9c17e1968523aaa3ac6f5c815638969109cdaaaac477d3614a9c6a4d8f060e662
7
+ data.tar.gz: 98db47b652881b0d860a61f1d3bfa8e633325aab77b4672c289dc85bc2d7e171500b8603df4fa433efee81d67809ed9c3a90649171e2b77c5da55cca9466fd28
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
@@ -10,20 +10,12 @@ class YaFinance::Http
10
10
 
11
11
 
12
12
  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
13
+ Excon.get(uri.to_s, persistent: true, headers: {"User-Agent" => "YaFin/#{YaFinance::VERSION}"})
20
14
  end
21
15
 
22
16
  module FetchRoot
23
17
  def fetch_root(path)
24
18
  uri = URI("#{ROOT_URL}/#{path}")
25
- puts uri
26
- # @TODO: make a crawler?
27
19
  YaFinance::Http.fetch(uri).body
28
20
  end
29
21
  end
@@ -31,8 +23,6 @@ class YaFinance::Http
31
23
  module FetchHistorical
32
24
  def fetch_historical(path)
33
25
  uri = URI("#{HISTORICAL_URL}/#{path}")
34
- puts uri
35
- # @TODO: make a crawler?
36
26
  YaFinance::Http.fetch(uri).body
37
27
  end
38
28
  end
@@ -40,8 +30,6 @@ class YaFinance::Http
40
30
  module FetchFundamentals
41
31
  def fetch_fundamentals(path)
42
32
  uri = URI("#{FUNDAMENTALS_URL}/#{path}")
43
- puts uri
44
- # @TODO: make a crawler?
45
33
  YaFinance::Http.fetch(uri).body
46
34
  end
47
35
  end
@@ -49,14 +37,12 @@ class YaFinance::Http
49
37
  module FetchV7
50
38
  def fetch_v7(path)
51
39
  uri = URI("#{V7_URL}/#{path}")
52
- puts uri
53
40
  JSON.parse(YaFinance::Http.fetch(uri).body)
54
41
  end
55
42
  end
56
43
  module FetchV8
57
44
  def fetch_v8(path)
58
45
  uri = URI("#{V8_URL}/#{path}")
59
- puts uri
60
46
  JSON.parse(YaFinance::Http.fetch(uri).body)
61
47
  end
62
48
  end
@@ -65,9 +51,7 @@ class YaFinance::Http
65
51
  def fetch_v6(mod)
66
52
  # modules = ['financialData', 'quoteType', 'defaultKeyStatistics', 'assetProfile', 'summaryDetail']
67
53
  uri = URI("#{V6_URL}/#{ERB::Util.url_encode(@ticker)}?modules=#{mod}")
68
- puts "#{uri}"
69
54
  json = JSON.parse(YaFinance::Http.fetch(uri).body)
70
- YaFinance::Http.shutdown
71
55
 
72
56
  if json["quoteSummary"] && json["quoteSummary"]["error"]
73
57
  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.4
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: []