PBYF 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/pbyf.rb +38 -0
  2. metadata +45 -0
data/lib/pbyf.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'rest-client'
2
+ require 'csv'
3
+ #Pause Break Yahoo Finance gem
4
+ class PBYF
5
+ #these are the base urls for querying various parts of yahoo finance
6
+ @@quote_url = 'http://download.finance.yahoo.com/d/quotes.csv?s='
7
+ @@historical_quote_url = 'http://ichart.yahoo.com/table.csv?s='
8
+
9
+ # this gets an array of arrays for the csv file
10
+ # arr_of_arrays = CSV.parse(RestClient.get 'http://download.finance.yahoo.com/d/quotes.csv?s=%40%5EDJI,GOOG&f=nsl1op')
11
+
12
+ #this will divide them into rows
13
+ # CSV.parse(RestClient.get 'http://download.finance.yahoo.com/d/quotes.csv?s=%40%5EDJI,GOOG&f=nsl1op') do |row|
14
+ # row
15
+ # end
16
+
17
+ #str_of_stocks should be formatted according to yahoo finance api docs
18
+ def self.get_quote str_of_stocks, str_of_options
19
+ query_url = @@quote_url + str_of_stocks + '&f=' + str_of_options
20
+ arr_of_arrays = CSV.parse(RestClient.get query_url)
21
+ end
22
+
23
+ # one cannot get multiple stocks for historical quotes, you must get them separately
24
+ # for now dates will be assumed to be the format Month-Day-Year, i.e. 3-19-1988
25
+ def self.get_hist_quote str_of_stock, from_date, to_date, interval = 'd'
26
+ from = from_date.split('-')
27
+ to = to_date.split('-')
28
+ from_to_params = "&a=#{from[0].to_i-1}" + "&b=#{from[1]}" + "&c=#{from[2]}" + "&d=#{to[0].to_i-1}" + "&e=#{to[1]}" + "&f=#{to[2]}"
29
+ query_url = @@historical_quote_url + str_of_stock + from_to_params + "&g=#{interval}"
30
+ puts query_url
31
+ arr_of_arrays = CSV.parse(RestClient.get query_url)
32
+ end
33
+
34
+ end
35
+
36
+ #testing
37
+ #PBYF.get_quote('%40%5EDJI,GOOG', 'nsl1op')
38
+ #PBYF.get_hist_quote( 'GOOG', '3-19-2012', '4-19-2012', 'd' )
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: PBYF
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Wickman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-14 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: For use with Yahoo Finance
15
+ email: wickman.matthew@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/pbyf.rb
21
+ homepage: http://pause-break.net
22
+ licenses: []
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 1.8.24
42
+ signing_key:
43
+ specification_version: 3
44
+ summary: Still a work in progress
45
+ test_files: []