yfinrb 0.1.0 → 0.2.15

Sign up to get free protection for your applications and to get access to all the features.
data/lib/yfinrb/utils.rb CHANGED
@@ -1,34 +1,6 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # yfinance - market data downloader
4
- # https://github.com/ranaroussi/yfinance
5
- #
6
- # Copyright 2017-2019 Ran Aroussi
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
- #
20
-
21
- #!/usr/bin/env ruby
22
- # frozen_string_literal: true
23
-
24
- require 'date'
25
- require 'logger'
26
- require 'net/http'
27
- require 'json'
28
- require 'time'
29
- require 'uri'
30
-
31
- class Yfin
1
+ require 'polars-df'
2
+
3
+ class Yfinrb
32
4
  class Utils
33
5
  BASE_URL = 'https://query1.finance.yahoo.com'
34
6
 
@@ -290,13 +262,36 @@ class Yfin
290
262
  case interval
291
263
  when '1mo'
292
264
  1.month
265
+ when '2mo'
266
+ 2.months
293
267
  when '3mo'
294
268
  3.months
269
+ when '6mo'
270
+ 6.months
271
+ when '9mo'
272
+ 9.months
273
+ when '12mo'
274
+ 1.year
295
275
  when '1y'
296
276
  1.year
277
+ when '2y'
278
+ 2.year
279
+ when '3y'
280
+ 3.year
281
+ when '4y'
282
+ 4.year
283
+ when '5y'
284
+ 5.year
297
285
  when '1wk'
298
286
  1.week
287
+ when '2wk'
288
+ 2.week
289
+ when '3wk'
290
+ 3.week
291
+ when '4wk'
292
+ 4.week
299
293
  else
294
+ Rails.logger.warn { "#{__FILE__}:#{__LINE__} #{interval} not a recognized interval" }
300
295
  interval
301
296
  end
302
297
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- module Yfinrb
4
- VERSION = "0.1.0"
1
+ class Yfinrb
2
+ VERSION = "0.2.15"
5
3
  end
@@ -3,8 +3,10 @@
3
3
  require 'thread'
4
4
  require 'date'
5
5
  require 'nokogiri'
6
+ require 'zache'
7
+ require 'httparty'
6
8
 
7
- class Yfin
9
+ class Yfinrb
8
10
  module YfConnection
9
11
  extend ActiveSupport::Concern
10
12
  # extend HTTParty
@@ -23,7 +25,7 @@ class Yfin
23
25
  def yfconn_initialize
24
26
  # Rails.logger.info { "#{__FILE__}:#{__LINE__} here"}
25
27
  begin
26
- @@zache = Zache.new
28
+ @@zache = ::Zache.new
27
29
  @@session_is_caching = true
28
30
  rescue NoMethodError
29
31
  # Not caching
@@ -33,7 +35,7 @@ class Yfin
33
35
  @@crumb = nil
34
36
  @@cookie = nil
35
37
  @@cookie_strategy = 'basic'
36
- @@cookie_lock = Mutex.new()
38
+ @@cookie_lock = ::Mutex.new()
37
39
  end
38
40
 
39
41
 
@@ -54,9 +56,9 @@ class Yfin
54
56
  }
55
57
 
56
58
  proxy = _get_proxy
57
- HTTParty.http_proxy(addr = proxy.split(':').first, port = proxy.split(':').second.split('/').first) unless proxy.nil?
59
+ ::HTTParty.http_proxy(addr = proxy.split(':').first, port = proxy.split(':').second.split('/').first) unless proxy.nil?
58
60
 
59
- cookie_hash = HTTParty::CookieHash.new
61
+ cookie_hash = ::HTTParty::CookieHash.new
60
62
  cookie_hash.add_cookies(@@cookie)
61
63
  options = { headers: headers.dup.merge(@@user_agent_headers).merge({ 'cookie' => cookie_hash.to_cookie_string, 'crumb' => crumb })} #, debug_output: STDOUT }
62
64
 
@@ -64,7 +66,9 @@ class Yfin
64
66
  joiner = ('?'.in?(request_args[:url]) ? '&' : '?')
65
67
  u += (joiner + CGI.unescape(request_args[:params].to_query)) unless request_args[:params].empty?
66
68
 
67
- response = HTTParty.get(u, options)
69
+ # Rails.logger.info { "#{__FILE__}:#{__LINE__} u=#{u}, options = #{options.inspect}" }
70
+ response = ::HTTParty.get(u, options)
71
+ # Rails.logger.info { "#{__FILE__}:#{__LINE__} response=#{response.inspect}" }
68
72
 
69
73
  return response
70
74
  end
@@ -169,13 +173,13 @@ class Yfin
169
173
  return @@crumb unless @@crumb.nil?
170
174
  return nil if (cookie = _get_cookie_basic()).nil?
171
175
 
172
- cookie_hash = HTTParty::CookieHash.new
176
+ cookie_hash = ::HTTParty::CookieHash.new
173
177
  cookie_hash.add_cookies(cookie)
174
178
  options = {headers: @@user_agent_headers.dup.merge(
175
179
  { 'cookie' => cookie_hash.to_cookie_string }
176
180
  )} #, debug_output: STDOUT }
177
181
 
178
- crumb_response = HTTParty.get('https://query1.finance.yahoo.com/v1/test/getcrumb', options)
182
+ crumb_response = ::HTTParty.get('https://query1.finance.yahoo.com/v1/test/getcrumb', options)
179
183
  @@crumb = crumb_response.parsed_response
180
184
 
181
185
  return (@@crumb.nil? || '<html>'.in?(@@crumb)) ? nil : @@crumb
@@ -195,17 +199,17 @@ class Yfin
195
199
  get_args[:expire_after] = @expire_after if @session_is_caching
196
200
  response = @session.get(**get_args)
197
201
 
198
- soup = Nokogiri::HTML(response.content, 'html.parser')
202
+ soup = ::Nokogiri::HTML(response.content, 'html.parser')
199
203
  csrfTokenInput = soup.find('input', attrs: {'name': 'csrfToken'})
200
204
 
201
205
  # puts 'Failed to find "csrfToken" in response'
202
206
  return false if csrfTokenInput.nil?
203
207
 
204
208
  csrfToken = csrfTokenInput['value']
205
- puts "csrfToken = #{csrfToken}"
209
+ # puts "csrfToken = #{csrfToken}"
206
210
  sessionIdInput = soup.find('input', attrs: {'name': 'sessionId'})
207
211
  sessionId = sessionIdInput['value']
208
- puts "sessionId='#{sessionId}"
212
+ # puts "sessionId='#{sessionId}"
209
213
 
210
214
  originalDoneUrl = 'https://finance.yahoo.com/'
211
215
  namespace = 'yahoo'
@@ -1,5 +1,4 @@
1
- class Yfin
2
-
1
+ class Yfinrb
3
2
  class YfinanceException < StandardError
4
3
  attr_reader :msg
5
4
  end
data/lib/yfinrb.rb CHANGED
@@ -1,17 +1,23 @@
1
+ class Yfinrb
2
+ end
3
+
1
4
  # frozen_string_literal: true
2
5
 
3
- require_relative 'yfin/version'
4
- require_relative 'yfin/yfinance_exception'
5
- require_relative 'yfin/ticker'
6
- require_relative 'yfin/price_history'
7
- require_relative 'yfin/quote'
8
- require_relative 'yfin/analysis'
9
- require_relative 'yfin/fundamentals'
10
- require_relative 'yfin/financials'
11
- require_relative 'yfin/holders'
6
+ require_relative 'yfinrb/version'
7
+ require_relative 'yfinrb/utils'
8
+ require_relative 'yfinrb/yfinance_exception'
9
+ require_relative 'yfinrb/yf_connection'
10
+ require_relative 'yfinrb/price_technical'
11
+ require_relative 'yfinrb/price_history'
12
+ require_relative 'yfinrb/quote'
13
+ require_relative 'yfinrb/analysis'
14
+ require_relative 'yfinrb/fundamentals'
15
+ require_relative 'yfinrb/financials'
16
+ require_relative 'yfinrb/holders'
17
+ require_relative 'yfinrb/ticker'
12
18
  require_relative "yfinrb/version"
13
19
 
14
- module Yfinrb
15
- class Error < StandardError; end
16
- # Your code goes here...
20
+ class Yfinrb
21
+
22
+ extend Yfinrb::PriceTechnical
17
23
  end
data/yfinrb-0.2.13.gem ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yfinrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bill McKinnon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-05 00:00:00.000000000 Z
11
+ date: 2024-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzinfo-data
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: tulirb
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Download market data from Yahoo! Finance's API
70
84
  email:
71
85
  - bill@bmck.org
@@ -80,6 +94,7 @@ files:
80
94
  - LICENSE.txt
81
95
  - README.md
82
96
  - Rakefile
97
+ - chart.png
83
98
  - lib/yfinrb.rb
84
99
  - lib/yfinrb/analysis.rb
85
100
  - lib/yfinrb/financials.rb
@@ -87,6 +102,7 @@ files:
87
102
  - lib/yfinrb/holders.rb
88
103
  - lib/yfinrb/multi.rb
89
104
  - lib/yfinrb/price_history.rb
105
+ - lib/yfinrb/price_technical.rb
90
106
  - lib/yfinrb/quote.rb
91
107
  - lib/yfinrb/ticker.rb
92
108
  - lib/yfinrb/tickers.rb
@@ -95,6 +111,7 @@ files:
95
111
  - lib/yfinrb/yf_connection.rb
96
112
  - lib/yfinrb/yfinance_exception.rb
97
113
  - sig/yfinrb.rbs
114
+ - yfinrb-0.2.13.gem
98
115
  homepage: https://www.github.com/bmck/yfinrb
99
116
  licenses:
100
117
  - MIT
@@ -117,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
134
  - !ruby/object:Gem::Version
118
135
  version: '0'
119
136
  requirements: []
120
- rubygems_version: 3.1.6
137
+ rubygems_version: 3.2.33
121
138
  signing_key:
122
139
  specification_version: 4
123
140
  summary: A shameless port of python's yfinance module to ruby