yquotes 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b08f86c5ff3fee6eee461f42329c84d35493c66
4
- data.tar.gz: a7e15f17170b6fe991613dd67c31f659d3e4be9e
3
+ metadata.gz: 6dc42bf53b65ad0b48a9aed0a175f7a00974966b
4
+ data.tar.gz: cc7708a6045547f49bc8c15824c8775f35772bd9
5
5
  SHA512:
6
- metadata.gz: fe8b9bd2d89823dc2a88f122f478e799e82510b752bc745a54fc2fcb95943eb1ffea4219c9ea737eb56c85ce70796cb379ffd391976f1b1feea4d415a3322632
7
- data.tar.gz: 2697dcda93eb2c7f43798c72865b794239a3b8db3480541692d29d38a4cd1ead669b9864317e4891aacb4e006597ff6ed9d76085dac53e3bebba2ac5b8d09c39
6
+ metadata.gz: 50360ff44e037372ea7d01599ecd8f80453c63b24cdba315bd30b3c72f55728cc52e8006dbb7a44c79a6a8afe3c29a78fc48c9597ad0bb2fb86a85ecfa55253d
7
+ data.tar.gz: 6b09b51b70069edc23c1b81514b0a0a4290eabdb8579410a4a8e9cbcf0f3b9e0a9722ea42f94279e055e7537a5ed38e370ad3ae501999a60f0f45b550dae62f5
@@ -1,3 +1,3 @@
1
1
  module YQuotes
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
data/lib/yquotes/yahoo.rb CHANGED
@@ -14,7 +14,36 @@ module YQuotes
14
14
 
15
15
  # Get cookie and crumb
16
16
  def initialize
17
+ fetch_credentials
18
+ end
19
+
20
+ # fetch_csv: fetch historical quotes in csv format
21
+ def fetch_csv(ticker, start_date=nil, end_date=nil, period='d')
22
+ connection = nil
23
+
24
+ # retry 3-times in case it sends unauthorized
25
+ 3.times do |i|
26
+ begin
27
+ url = build_url(ticker, start_date, end_date, period)
28
+ connection = open(url, 'Cookie' => @cookie)
29
+ break
30
+ rescue OpenURI::HTTPError => e
31
+ fetch_credentials
32
+ end
33
+ end
34
+
35
+ data = CSV.parse(connection.read, :converters => :numeric)
36
+
37
+ raise "Yahoo.fetch_csv unable to fetch data" unless data.is_a? Array
38
+ return data
39
+ end
17
40
 
41
+ alias_method :get_csv, :fetch_csv
42
+ alias_method :get_data, :fetch_csv
43
+
44
+ private
45
+
46
+ def fetch_credentials
18
47
  # get cookie
19
48
  page = open(COOKIE_URL)
20
49
  @cookie = page.meta['set-cookie'].split('; ', 2).first
@@ -30,20 +59,6 @@ module YQuotes
30
59
  end
31
60
  end
32
61
 
33
- # fetch_csv: fetch historical quotes in csv format
34
- def fetch_csv(ticker, start_date=nil, end_date=nil, period='d')
35
- url = build_url(ticker, start_date, end_date, period)
36
- connection = open(url, 'Cookie' => @cookie)
37
- data = CSV.parse(connection.read, :converters => :numeric)
38
- raise "Yahoo.fetch_csv unable to fetch data" unless data.is_a? Array
39
- return data
40
- end
41
-
42
- alias_method :get_csv, :fetch_csv
43
- alias_method :get_data, :fetch_csv
44
-
45
- private
46
-
47
62
  # build_params: build parameters for get query
48
63
  def build_url(ticker, start_date=nil, end_date=nil, period='d')
49
64
 
data/lib/yquotes.rb CHANGED
@@ -55,8 +55,7 @@ module YQuotes
55
55
 
56
56
  # strip columns and create index
57
57
  df.index = Daru::Index.new(df['Date'].to_a)
58
- df = df['Volume', 'Adj Close']
59
- df.rename_vectors 'Volume' => :volume, 'Adj Close' => :close
58
+ df.rename_vectors 'Volume' => :volume, 'Adj Close' => :adj_close, 'Open' => :open, 'Close' => :close, 'High' => :high, 'Low' => :low
60
59
 
61
60
  d = df.filter(:row) { |row| row[:volume] > 0}
62
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yquotes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - P Choudhary
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-21 00:00:00.000000000 Z
11
+ date: 2017-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler