yahoo_finanza 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9602809c4c47dc466f221a68ee3fd5dc49da982b
4
+ data.tar.gz: 5b916f15428285a6eb8588b512d4b950495e7e7f
5
+ SHA512:
6
+ metadata.gz: 96501e3e71893c13a75f38393b01abfbccc17228a20fc7e9a4658781d8fcb274da0915712f5d51b2ecc0fd965cc6cb72e1be3e48c5782f07c2bf553b1212692f
7
+ data.tar.gz: f682d7425a8942dc76b7bd644a11e96846163c7bfdc2ef4c03a1f431818ae0099445eaf6f0260ee5205a140b00937111c92601a0baf1bca1cfb820c6a7789d45
@@ -0,0 +1,61 @@
1
+ require 'ostruct'
2
+ require 'csv'
3
+ require 'open-uri'
4
+
5
+ module YahooFinanza
6
+ # Finance Utils For Yahoo Finanza
7
+ module FinanceUtils
8
+ def self.included(base)
9
+ base.extend(self)
10
+ end
11
+
12
+ def method_missing(method_sym, *args, &block)
13
+ if !!(method_sym =~ /'_url'/)
14
+ "http://www.nasdaq.com/screening/companies-by-name.aspx?letter=0&exchange=#{method_sym}&render=download"
15
+ end
16
+ end
17
+
18
+ %w(nasdaq nyse amex).each do |market_symbol|
19
+ define_method "#{market_symbol}_url".to_sym do
20
+ "http://www.nasdaq.com/screening/companies-by-name.aspx?letter=0&exchange=#{market_symbol}&render=download"
21
+ end
22
+ end
23
+
24
+ def symbols_by_market(market)
25
+ symbols = []
26
+ return symbols if market.nil?
27
+ if respond_to?("#{market}_url".to_sym)
28
+ url = send("#{market}_url".to_sym)
29
+ market_file = open(url)
30
+
31
+ CSV.foreach(market_file) do |row|
32
+ next if row.first == 'Symbol'
33
+ symbols.push(row.first.gsub(' ', ''))
34
+ end
35
+ end
36
+ symbols
37
+ end
38
+ end
39
+ end
40
+
41
+ # Old Code
42
+ # MARKETS = OpenStruct.new(
43
+ # us: OpenStruct.new(
44
+ # nasdaq: OpenStruct.new(
45
+ # url: 'http://www.nasdaq.com/screening/companies-by-name.aspx?letter=0&exchange=nasdaq&render=download'),
46
+ # nyse: OpenStruct.new(
47
+ # url: 'http://www.nasdaq.com/screening/companies-by-name.aspx?letter=0&exchange=nyse&render=download'),
48
+ # amex: OpenStruct.new(
49
+ # url: 'http://www.nasdaq.com/screening/companies-by-name.aspx?letter=0&exchange=amex&render=download')))
50
+
51
+ # def symbols_by_market_old(country, market)
52
+ # symbols = []
53
+ # return symbols unless MARKETS[country][market]
54
+ # market_file = open(MARKETS[country][market].url)
55
+
56
+ # CSV.foreach(market_file) do |row|
57
+ # next if row.first == 'Symbol'
58
+ # symbols.push(row.first.gsub(' ', ''))
59
+ # end
60
+ # symbols
61
+ # end
@@ -0,0 +1,4 @@
1
+ # Yahoo Finanza Version
2
+ module YahooFinanza
3
+ VERSION = '0.0.1'
4
+ end
@@ -0,0 +1,45 @@
1
+ require 'json'
2
+ require 'ostruct'
3
+
4
+ module YahooFinanza
5
+ # Yahoo Helpers for Yahoo Finanza
6
+ module YahooHelpers
7
+ def yahoofy(payload)
8
+ yahoofied = OpenStruct.new
9
+ jsons = JSON.parse(payload)['query']['results']['quote']
10
+ if jsons.class == Hash
11
+ tmpsym = OpenStruct.new(symbol)
12
+ if tmpsym.Name
13
+ yahoofied[tmpsym.symbol] = tmpsym
14
+ end
15
+ else
16
+ jsons.each do |symbol|
17
+ tmpsym = OpenStruct.new(symbol)
18
+ if tmpsym.Name
19
+ yahoofied[tmpsym.symbol] = tmpsym
20
+ end
21
+ end
22
+ end
23
+ return nil if yahoofied.to_h.keys.empty?
24
+ yahoofied
25
+ end
26
+
27
+ def single_yahoofy(payload)
28
+ jsons = JSON.parse(payload)['query']['results']['quote']
29
+ result = OpenStruct.new(jsons)
30
+ return nil unless result.Name
31
+ result
32
+ end
33
+
34
+ def historical_yahoofy(payload)
35
+ yahoofied = []
36
+ jsons = JSON.parse(payload)['query']['results']
37
+ return [] unless jsons
38
+ jsons['quote'].each do |symbol|
39
+ tmpsym = OpenStruct.new(symbol)
40
+ yahoofied << tmpsym
41
+ end
42
+ yahoofied
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,50 @@
1
+ require 'yahoo_finanza/version'
2
+ require 'yahoo_finanza/finance_utils'
3
+ require 'yahoo_finanza/yahoo_helpers'
4
+ require 'yql'
5
+ require 'json'
6
+ require 'ostruct'
7
+
8
+ module YahooFinanza
9
+ # Yahoo Finanza Client
10
+ class Client
11
+ include YahooFinanza::FinanceUtils
12
+ include YahooFinanza::YahooHelpers
13
+
14
+ attr_reader :yql
15
+
16
+ def initialize
17
+ @yql = Yql::Client.new
18
+ @yql.format = 'json'
19
+ end
20
+
21
+ def quotes(symbols)
22
+ return nil if symbols.empty?
23
+ query = Yql::QueryBuilder.new 'yahoo.finance.quotes'
24
+ query.conditions = "symbol in (\"#{symbols.join('\", \"')}\")"
25
+ @yql.query = query
26
+ response = @yql.get
27
+ yahoofy(response.show)
28
+ end
29
+
30
+ def quote(symbol)
31
+ return nil if symbol == ''
32
+ query = Yql::QueryBuilder.new 'yahoo.finance.quotes'
33
+ query.conditions = "symbol in (\"#{symbol}\")"
34
+ @yql.query = query
35
+ response = @yql.get
36
+ single_yahoofy(response.show)
37
+ end
38
+
39
+ def historical_quotes(symbol, options = {})
40
+ return [] if symbol == ''
41
+ query = Yql::QueryBuilder.new 'yahoo.finance.historicaldata'
42
+ query.conditions = {
43
+ symbol: symbol, startDate: options[:start_date],
44
+ endDate: options[:end_date] }
45
+ @yql.query = query
46
+ response = @yql.get
47
+ historical_yahoofy(response.show)
48
+ end
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yahoo_finanza
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eric D. Santos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yql
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: |-
84
+ An easy to use and updated yahoo finance gem with
85
+ finance utils and a Yahoo Finance Client.
86
+ email:
87
+ - eric.santos@cometa.works
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - lib/yahoo_finanza.rb
93
+ - lib/yahoo_finanza/finance_utils.rb
94
+ - lib/yahoo_finanza/version.rb
95
+ - lib/yahoo_finanza/yahoo_helpers.rb
96
+ homepage: ''
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.0.14
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: An easy to use and updated yahoo finance gem with finance utils and a Yahoo
120
+ Finance Client.
121
+ test_files: []