current-price 0.1.0 → 0.2.0

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: 3e06a2e3b471120e55d147daa877f6eabd2e0d74
4
- data.tar.gz: 9b806970e636e20dd282bae968bf17b1c82d0302
3
+ metadata.gz: 481330298fe2b03685afe03519eb2892105a92fb
4
+ data.tar.gz: 3966f4d44548e984dd3e12b6ca6fa5434fe67ea5
5
5
  SHA512:
6
- metadata.gz: 5c58a0e960470b1e5763ae89fa0d921ab8ada3447f455c43fb6d982a9ca7942e9452e2048fd1f2a383bb0c221a8c3d8c3b02603df3ab429005c9ba1dbfc7c8af
7
- data.tar.gz: 6290e567c0ca5cb53a6cc77f149380d15aa1474a25b8661a547913e4c7ce8ec047e76a03fb3bf6f5bccab0720f65d55ec135c54d1ce7abc83963018863baff47
6
+ metadata.gz: aabc419a8aa91a43e71494c0060df3d6a8e0dc03568a6ff9b0fe229c59bea4e7a8716663110ef404da26180a58ab99514bb24eda419dfc98c80a9cfba4dfd605
7
+ data.tar.gz: d6af8730dd67fc659fea92f08391b73a47d880479a54c94ed297f7e6262445b949e8e01761d7e776200dc3e66fc31b0ea5465f21babac5ea9b0a7fefd8d38c98
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## CurrentPrice
2
2
 
3
- A gem for crawling public endpoints for current stock price & current option chain details.
3
+ A gem for crawling public endpoints for current stock price & current option chain details
4
4
 
5
5
  #### Goals
6
6
 
@@ -30,7 +30,7 @@ require 'current-price'
30
30
 
31
31
  client = CurrentPrice::Google.client(:requesting_handle => "my_handle")
32
32
 
33
- client.option_chain("CSCO") #=> {:posts=>1149, :followers=>604000, :following=>921, :handle=>"the_skatenerd"}
33
+ client.option_chain("CSCO") #=> {"9-16-2016"=>{:puts=>[{:price=>"0.03", :bid=>"-", :ask=>"0.02", :close=>"0.00", :oi=>"290", :volume=>"-", :strike=>"19.00"}, ..
34
34
  ```
35
35
 
36
36
  #### Yahoo
@@ -40,7 +40,7 @@ require 'current-price'
40
40
 
41
41
  client = CurrentPrice::Yahoo.client(:requesting_handle => "my_handle")
42
42
 
43
- client.quote("CSCO") #=> {:posts=>1149, :followers=>604000, :following=>921, :handle=>"the_skatenerd"}
43
+ client.quote("CSCO") #=> {:low=>"22.46", :ticker=>"CSCO", :price=>31.14, :name=>"Cisco Systems"}
44
44
  ```
45
45
 
46
46
  ## Contributing
data/lib/current-price.rb CHANGED
@@ -6,5 +6,5 @@ require 'current-price/yahoo'
6
6
  require 'current-price/yahoo/client'
7
7
 
8
8
  module CurrentPrice
9
- VERSION = '0.1.0'
9
+ VERSION = '0.2.0'
10
10
  end
@@ -12,6 +12,7 @@ module CurrentPrice
12
12
  begin
13
13
  self.class.get(url).response.body
14
14
  rescue
15
+
15
16
  end
16
17
  end
17
18
 
@@ -15,22 +15,23 @@ module CurrentPrice
15
15
  private
16
16
 
17
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
- }]
18
+ Hash[
19
+ eval(data.to_s).fetch(:expirations).map{ |expiry|
20
+ month, day, year = expiry[:m], expiry[:d], expiry[: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
+ ]
27
28
  end
28
29
 
29
30
  def option_chain_detail_serializer(data)
30
- chunks = eval(data.to_s)
31
+ data_hash = eval(data.to_s)
31
32
  {
32
- :puts => contracts_serialzer( chunks[:puts] ),
33
- :calls => contracts_serialzer( chunks[:calls] )
33
+ :puts => contracts_serialzer( data_hash.fetch(:puts) ),
34
+ :calls => contracts_serialzer( data_hash.fetch(:calls) )
34
35
  }
35
36
  end
36
37
 
@@ -1,4 +1,11 @@
1
1
  module CurrentPrice
2
2
  class Utils
3
+ def underscore(str)
4
+ str.gsub(/::/, '/').
5
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
6
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
7
+ tr("-", "_").
8
+ downcase
9
+ end
3
10
  end
4
11
  end
@@ -4,9 +4,23 @@ module CurrentPrice
4
4
  module OptionChain
5
5
 
6
6
  def option_chain(ticker)
7
- {}
7
+ url = 'https://query.yahooapis.com/v1/public/yql?q='
8
+ #url += URI.encode("SELECT * FROM yahoo.finance.option_contracts WHERE symbol IN ('#{ticker}') AND expiration='2016-09-16' AND type='C'")
9
+ url += URI.encode("SELECT contract FROM yahoo.finance.option_contract WHERE symbol='#{ticker}'")
10
+ url += '&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback='
11
+ option_chain_serializer(
12
+ request(
13
+ url
14
+ )
15
+ )
8
16
  end
9
-
17
+
18
+ private
19
+
20
+ def option_chain_serializer(data)
21
+ JSON.parse(data)
22
+ end
23
+
10
24
  end
11
25
  end
12
26
  end
@@ -2,11 +2,14 @@ module CurrentPrice
2
2
  module Yahoo
3
3
  class Client
4
4
  module Quote
5
-
5
+
6
6
  def quote(ticker)
7
+ url = 'https://query.yahooapis.com/v1/public/yql?q='
8
+ url += URI.encode("SELECT * FROM yahoo.finance.quotes WHERE symbol IN ('#{ticker}')")
9
+ url += '&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback='
7
10
  quote_serializer(
8
11
  request(
9
- "http://download.finance.yahoo.com/d/quotes.csv?s=#{ticker}&f=json"
12
+ url
10
13
  )
11
14
  )
12
15
  end
@@ -14,13 +17,11 @@ module CurrentPrice
14
17
  private
15
18
 
16
19
  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
- }
20
+ Hash[
21
+ JSON.parse(data).fetch('query')['results']['quote'].map{ |key, val|
22
+ [underscore(key), val]
23
+ }
24
+ ]
24
25
  end
25
26
 
26
27
  end
@@ -6,5 +6,8 @@ describe CurrentPrice::Google::Client::OptionChain do
6
6
  @option_chain = @client.option_chain("CSCO")
7
7
  end
8
8
 
9
+ it 'should retrieve cisco option chain' do
10
+ end
11
+
9
12
  end
10
13
  end
@@ -6,5 +6,8 @@ describe CurrentPrice::Google::Client::Quote do
6
6
  @quote = @client.quote("CSCO")
7
7
  end
8
8
 
9
+ it 'should retrieve cisco quote' do
10
+ end
11
+
9
12
  end
10
13
  end
@@ -6,5 +6,8 @@ describe CurrentPrice::Yahoo::Client::OptionChain do
6
6
  @option_chain = @client.option_chain("CSCO")
7
7
  end
8
8
 
9
+ it 'should retrieve cisco option chain' do
10
+ end
11
+
9
12
  end
10
13
  end
@@ -6,5 +6,8 @@ describe CurrentPrice::Yahoo::Client::Quote do
6
6
  @quote = @client.quote("CSCO")
7
7
  end
8
8
 
9
+ it 'should retrieve cisco quote' do
10
+ end
11
+
9
12
  end
10
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: current-price
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Richards
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-10 00:00:00.000000000 Z
11
+ date: 2016-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake