current-price 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3e06a2e3b471120e55d147daa877f6eabd2e0d74
4
+ data.tar.gz: 9b806970e636e20dd282bae968bf17b1c82d0302
5
+ SHA512:
6
+ metadata.gz: 5c58a0e960470b1e5763ae89fa0d921ab8ada3447f455c43fb6d982a9ca7942e9452e2048fd1f2a383bb0c221a8c3d8c3b02603df3ab429005c9ba1dbfc7c8af
7
+ data.tar.gz: 6290e567c0ca5cb53a6cc77f149380d15aa1474a25b8661a547913e4c7ce8ec047e76a03fb3bf6f5bccab0720f65d55ec135c54d1ce7abc83963018863baff47
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,51 @@
1
+ ## CurrentPrice
2
+
3
+ A gem for crawling public endpoints for current stock price & current option chain details.
4
+
5
+ #### Goals
6
+
7
+ * Obtain the 'instantaneous' price of a stock
8
+ * Obtain all available option contracts for a given stock
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'current-price'
15
+
16
+ And then execute:
17
+
18
+ $ bundler
19
+
20
+ Or install it yourself:
21
+
22
+ $ gem install current-price
23
+
24
+ ## Usage
25
+
26
+ #### Google
27
+
28
+ ```ruby
29
+ require 'current-price'
30
+
31
+ client = CurrentPrice::Google.client(:requesting_handle => "my_handle")
32
+
33
+ client.option_chain("CSCO") #=> {:posts=>1149, :followers=>604000, :following=>921, :handle=>"the_skatenerd"}
34
+ ```
35
+
36
+ #### Yahoo
37
+
38
+ ```ruby
39
+ require 'current-price'
40
+
41
+ client = CurrentPrice::Yahoo.client(:requesting_handle => "my_handle")
42
+
43
+ client.quote("CSCO") #=> {:posts=>1149, :followers=>604000, :following=>921, :handle=>"the_skatenerd"}
44
+ ```
45
+
46
+ ## Contributing
47
+
48
+ * Fork the project.
49
+ * Start a feature/bugfix branch.
50
+ * Commit and push until you are happy with your contribution.
51
+ * Submit a pull request
@@ -0,0 +1,9 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ # Default directory to look in is `/specs`
5
+ # Run with `rake spec`
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
+ end
8
+
9
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'current-price'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.add_development_dependency "rake"
8
+ s.add_development_dependency "rspec"
9
+ s.add_development_dependency "rspec-nc"
10
+ s.add_development_dependency "guard"
11
+ s.add_development_dependency "guard-rspec"
12
+ s.add_development_dependency "pry"
13
+ s.add_development_dependency "pry-remote"
14
+ s.add_development_dependency "pry-nav"
15
+ s.add_runtime_dependency('httparty', '~> 0.14.0', '>= 0.14.0')
16
+ s.description = "A ruby stock price & option chain crawler"
17
+ s.date = Time.now.utc.strftime("%Y-%m-%d")
18
+ s.name = 'current-price'
19
+ s.version = CurrentPrice::VERSION
20
+ s.summary = "A ruby stock price & option chain crawler"
21
+ s.authors = ["Ed Richards"]
22
+ s.email = 'er@advect.us'
23
+ s.require_paths = ["lib"]
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.files = `git ls-files`.split("\n")
26
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ s.homepage = 'http://www.github.com/advectus/current-price'
28
+ s.license = 'MIT'
29
+ end
@@ -0,0 +1,10 @@
1
+ require 'current-price/utils'
2
+ require 'current-price/connection'
3
+ require 'current-price/google'
4
+ require 'current-price/google/client'
5
+ require 'current-price/yahoo'
6
+ require 'current-price/yahoo/client'
7
+
8
+ module CurrentPrice
9
+ VERSION = '0.1.0'
10
+ end
@@ -0,0 +1,19 @@
1
+ require 'httparty'
2
+
3
+ module CurrentPrice
4
+ class Connection < Utils
5
+ include HTTParty
6
+
7
+ def initialize(options={})
8
+ @options = options
9
+ end
10
+
11
+ def request(url)
12
+ begin
13
+ self.class.get(url).response.body
14
+ rescue
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ module CurrentPrice
2
+ module Google
3
+ def self.client(options={})
4
+ Google::Client.new(options)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module CurrentPrice
2
+ module Google
3
+ class Client < Connection
4
+ Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
5
+ include Google::Client::Quote
6
+ include Google::Client::OptionChain
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,54 @@
1
+ module CurrentPrice
2
+ module Google
3
+ class Client
4
+ module OptionChain
5
+
6
+ def option_chain(ticker)
7
+ option_chain_serializer(
8
+ ticker,
9
+ request(
10
+ "http://www.google.com/finance/option_chain?q=#{ticker}&output=json"
11
+ )
12
+ )
13
+ end
14
+
15
+ private
16
+
17
+ def option_chain_serializer(ticker, data)
18
+ chunks = eval(data.to_s)
19
+ Hash[chunks[:expirations].map {|expiration_event|
20
+ month, day, year = expiration_event[:m], expiration_event[:d], expiration_event[:y]
21
+ ["#{month}-#{day}-#{year}", option_chain_detail_serializer(
22
+ request(
23
+ "http://www.google.com/finance/option_chain?q=#{ticker}&expd=#{day}&expm=#{month}&expy=#{year}&output=json"
24
+ )
25
+ )]
26
+ }]
27
+ end
28
+
29
+ def option_chain_detail_serializer(data)
30
+ chunks = eval(data.to_s)
31
+ {
32
+ :puts => contracts_serialzer( chunks[:puts] ),
33
+ :calls => contracts_serialzer( chunks[:calls] )
34
+ }
35
+ end
36
+
37
+ def contracts_serialzer(contracts)
38
+ contracts.map{|contract|
39
+ {
40
+ :price => contract[:p],
41
+ :bid => contract[:b],
42
+ :ask => contract[:a],
43
+ :close => contract[:c],
44
+ :oi => contract[:oi],
45
+ :volume => contract[:vol],
46
+ :strike => contract[:strike],
47
+ }
48
+ }
49
+ end
50
+
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,13 @@
1
+ module CurrentPrice
2
+ module Google
3
+ class Client
4
+ module Quote
5
+
6
+ def quote(ticker)
7
+ {}
8
+ end
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module CurrentPrice
2
+ class Utils
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module CurrentPrice
2
+ module Yahoo
3
+ def self.client(options={})
4
+ Yahoo::Client.new(options)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module CurrentPrice
2
+ module Yahoo
3
+ class Client < Connection
4
+ Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
5
+ include Yahoo::Client::Quote
6
+ include Yahoo::Client::OptionChain
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module CurrentPrice
2
+ module Yahoo
3
+ class Client
4
+ module OptionChain
5
+
6
+ def option_chain(ticker)
7
+ {}
8
+ end
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ module CurrentPrice
2
+ module Yahoo
3
+ class Client
4
+ module Quote
5
+
6
+ def quote(ticker)
7
+ quote_serializer(
8
+ request(
9
+ "http://download.finance.yahoo.com/d/quotes.csv?s=#{ticker}&f=json"
10
+ )
11
+ )
12
+ end
13
+
14
+ private
15
+
16
+ def quote_serializer(data)
17
+ chunks = data.split(",")
18
+ {
19
+ :low => chunks[0],
20
+ :ticker => chunks[1].gsub(/"/, ''),
21
+ :price => chunks[2].to_f,
22
+ :name => chunks[3].strip.gsub(/"/, '')
23
+ }
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ describe CurrentPrice::Google::Client::OptionChain do
2
+ describe 'Google.client.option_chain()' do
3
+
4
+ before(:each) do
5
+ @client = CurrentPrice::Google.client({})
6
+ @option_chain = @client.option_chain("CSCO")
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ describe CurrentPrice::Google::Client::Quote do
2
+ describe 'Google.client.quote()' do
3
+
4
+ before(:each) do
5
+ @client = CurrentPrice::Google.client({})
6
+ @quote = @client.quote("CSCO")
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ describe CurrentPrice::Google do
2
+ describe 'Google.client' do
3
+
4
+ before(:each) do
5
+ @client = CurrentPrice::Google.client({})
6
+ end
7
+
8
+ it 'should handle client' do
9
+ expect(@client.class.to_s).to eq "CurrentPrice::Google::Client"
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ describe CurrentPrice::Yahoo::Client::OptionChain do
2
+ describe 'Yahoo.client.option_chain()' do
3
+
4
+ before(:each) do
5
+ @client = CurrentPrice::Yahoo.client({})
6
+ @option_chain = @client.option_chain("CSCO")
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ describe CurrentPrice::Yahoo::Client::Quote do
2
+ describe 'Yahoo.client.quote()' do
3
+
4
+ before(:each) do
5
+ @client = CurrentPrice::Yahoo.client({})
6
+ @quote = @client.quote("CSCO")
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ describe CurrentPrice::Yahoo do
2
+ describe 'Yahoo.client' do
3
+
4
+ before(:each) do
5
+ @client = CurrentPrice::Yahoo.client({})
6
+ end
7
+
8
+ it 'should handle client' do
9
+ expect(@client.class.to_s).to eq "CurrentPrice::Yahoo::Client"
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ describe CurrentPrice do
2
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: current-price
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ed Richards
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-nc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
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: guard-rspec
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
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-remote
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-nav
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: httparty
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.14.0
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 0.14.0
135
+ type: :runtime
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: 0.14.0
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 0.14.0
145
+ description: A ruby stock price & option chain crawler
146
+ email: er@advect.us
147
+ executables: []
148
+ extensions: []
149
+ extra_rdoc_files: []
150
+ files:
151
+ - ".gitignore"
152
+ - Gemfile
153
+ - README.md
154
+ - Rakefile
155
+ - currentprice.gemspec
156
+ - lib/current-price.rb
157
+ - lib/current-price/connection.rb
158
+ - lib/current-price/google.rb
159
+ - lib/current-price/google/client.rb
160
+ - lib/current-price/google/client/option_chain.rb
161
+ - lib/current-price/google/client/quote.rb
162
+ - lib/current-price/utils.rb
163
+ - lib/current-price/yahoo.rb
164
+ - lib/current-price/yahoo/client.rb
165
+ - lib/current-price/yahoo/client/option_chain.rb
166
+ - lib/current-price/yahoo/client/quote.rb
167
+ - spec/current-price/google/client/option_chain_spec.rb
168
+ - spec/current-price/google/client/quote_spec.rb
169
+ - spec/current-price/google_spec.rb
170
+ - spec/current-price/yahoo/client/option_chain_spec.rb
171
+ - spec/current-price/yahoo/client/quote_spec.rb
172
+ - spec/current-price/yahoo_spec.rb
173
+ - spec/current_price_spec.rb
174
+ homepage: http://www.github.com/advectus/current-price
175
+ licenses:
176
+ - MIT
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.5.1
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: A ruby stock price & option chain crawler
198
+ test_files:
199
+ - spec/current-price/google/client/option_chain_spec.rb
200
+ - spec/current-price/google/client/quote_spec.rb
201
+ - spec/current-price/google_spec.rb
202
+ - spec/current-price/yahoo/client/option_chain_spec.rb
203
+ - spec/current-price/yahoo/client/quote_spec.rb
204
+ - spec/current-price/yahoo_spec.rb
205
+ - spec/current_price_spec.rb