current-price 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/current-price.rb +1 -1
- data/lib/current-price/connection.rb +1 -0
- data/lib/current-price/google/client/option_chain.rb +13 -12
- data/lib/current-price/utils.rb +7 -0
- data/lib/current-price/yahoo/client/option_chain.rb +16 -2
- data/lib/current-price/yahoo/client/quote.rb +10 -9
- data/spec/current-price/google/client/option_chain_spec.rb +3 -0
- data/spec/current-price/google/client/quote_spec.rb +3 -0
- data/spec/current-price/yahoo/client/option_chain_spec.rb +3 -0
- data/spec/current-price/yahoo/client/quote_spec.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 481330298fe2b03685afe03519eb2892105a92fb
|
4
|
+
data.tar.gz: 3966f4d44548e984dd3e12b6ca6fa5434fe67ea5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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")
|
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")
|
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
@@ -15,22 +15,23 @@ module CurrentPrice
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def option_chain_serializer(ticker, data)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
31
|
+
data_hash = eval(data.to_s)
|
31
32
|
{
|
32
|
-
:puts => contracts_serialzer(
|
33
|
-
:calls => contracts_serialzer(
|
33
|
+
:puts => contracts_serialzer( data_hash.fetch(:puts) ),
|
34
|
+
:calls => contracts_serialzer( data_hash.fetch(:calls) )
|
34
35
|
}
|
35
36
|
end
|
36
37
|
|
data/lib/current-price/utils.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2016-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|