iex-ruby-client 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/.rubocop_todo.yml +14 -6
- data/CHANGELOG.md +6 -0
- data/README.md +20 -3
- data/lib/iex-ruby-client.rb +2 -2
- data/lib/iex/api.rb +20 -0
- data/lib/iex/api/company.rb +17 -0
- data/lib/iex/api/quote.rb +1 -10
- data/lib/iex/resources.rb +3 -0
- data/lib/iex/resources/company.rb +21 -0
- data/lib/iex/resources/quote.rb +57 -0
- data/lib/iex/{resource.rb → resources/resource.rb} +0 -0
- data/lib/iex/version.rb +1 -1
- data/spec/fixtures/iex/company/invalid.yml +61 -0
- data/spec/fixtures/iex/company/msft.yml +68 -0
- data/spec/fixtures/iex/{invalid.yml → quote/invalid.yml} +0 -0
- data/spec/fixtures/iex/{msft.yml → quote/msft.yml} +0 -0
- data/spec/iex/resources/company_spec.rb +28 -0
- data/spec/iex/{quote_spec.rb → resources/quote_spec.rb} +11 -5
- metadata +20 -11
- data/lib/iex/quote.rb +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46bb34f95ce06a28bda7ef497524779e523005d8
|
4
|
+
data.tar.gz: d6d45b4e0f9053a97275a76183c6da980c397119
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07c3d56637a21ef86dbd196e319f8ffd38ebf890ba8c9eefda6ef21e57a4f1b1fd10a3e10f1620899ee7e08fc6bd895fa828fdf0d98754e0dcbdd7f311979a7c
|
7
|
+
data.tar.gz: 0b6be443863b617f4af1a21021ed36ceaf2670bba91cd240a5ca4b003925d6fc385a8cdee2d0f582905dbd40ad4aabdcbd90ee40dd3c5a40d44ca0d516ba3049
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2018-03-
|
3
|
+
# on 2018-03-26 16:58:34 -0400 using RuboCop version 0.51.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -9,13 +9,13 @@
|
|
9
9
|
# Offense count: 1
|
10
10
|
# Configuration parameters: CountComments, ExcludedMethods.
|
11
11
|
Metrics/BlockLength:
|
12
|
-
Max:
|
12
|
+
Max: 33
|
13
13
|
|
14
|
-
# Offense count:
|
14
|
+
# Offense count: 32
|
15
15
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
16
16
|
# URISchemes: http, https
|
17
17
|
Metrics/LineLength:
|
18
|
-
Max:
|
18
|
+
Max: 221
|
19
19
|
|
20
20
|
# Offense count: 1
|
21
21
|
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
@@ -24,11 +24,19 @@ Naming/FileName:
|
|
24
24
|
Exclude:
|
25
25
|
- 'lib/iex-ruby-client.rb'
|
26
26
|
|
27
|
-
# Offense count:
|
27
|
+
# Offense count: 1
|
28
|
+
Style/AsciiComments:
|
29
|
+
Exclude:
|
30
|
+
- 'lib/iex/resources/quote.rb'
|
31
|
+
|
32
|
+
# Offense count: 6
|
28
33
|
Style/Documentation:
|
29
34
|
Exclude:
|
30
35
|
- 'spec/**/*'
|
31
36
|
- 'test/**/*'
|
37
|
+
- 'lib/iex/api.rb'
|
38
|
+
- 'lib/iex/api/company.rb'
|
32
39
|
- 'lib/iex/api/quote.rb'
|
33
40
|
- 'lib/iex/errors/symbol_not_found_error.rb'
|
34
|
-
- 'lib/iex/
|
41
|
+
- 'lib/iex/resources/company.rb'
|
42
|
+
- 'lib/iex/resources/quote.rb'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
### 0.2.0 (2018/03/26)
|
2
|
+
|
3
|
+
* Moved `IEX::Quote` into `IEX::Resources::Quote` - [@dblock](https://github.com/dblock).
|
4
|
+
* Added `IEX::Resources::Company#get` returning company information - [@dblock](https://github.com/dblock).
|
5
|
+
* Added `IEX::Resources::Quote#latest_update_t` and `IEX::Resources::Quote#iex_last_updated_t` in `Time` format - [@dblock](https://github.com/dblock).
|
6
|
+
|
1
7
|
### 0.1.0 (2018/03/23)
|
2
8
|
|
3
9
|
* Initial public release - [@dblock](https://github.com/dblock).
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ Run `bundle install`.
|
|
23
23
|
Fetches a single stock quote.
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
quote = IEX::Quote.get('MSFT')
|
26
|
+
quote = IEX::Resources::Quote.get('MSFT')
|
27
27
|
|
28
28
|
quote.latest_price # 90.165
|
29
29
|
quote.change # 0.375
|
@@ -31,7 +31,24 @@ quote.change_percent # 0.00418
|
|
31
31
|
quote.change_percent_s # '+0.42%'
|
32
32
|
```
|
33
33
|
|
34
|
-
See [#quote](https://iextrading.com/developer/docs/#quote) for detailed documentation or [quote.rb](lib/iex/quote.rb) for returned fields.
|
34
|
+
See [#quote](https://iextrading.com/developer/docs/#quote) for detailed documentation or [quote.rb](lib/iex/resources/quote.rb) for returned fields.
|
35
|
+
|
36
|
+
### Get Company Information
|
37
|
+
|
38
|
+
Fetches company information for a symbol.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
company = IEX::Resources::Company.get('MSFT')
|
42
|
+
|
43
|
+
company.ceo # 'Satya Nadella'
|
44
|
+
company.company_name # 'Microsoft Corporation'
|
45
|
+
```
|
46
|
+
|
47
|
+
See [#company](https://iextrading.com/developer/docs/#company) for detailed documentation or [company.rb](lib/iex/resources/company.rb) for returned fields.
|
48
|
+
|
49
|
+
## Errors
|
50
|
+
|
51
|
+
### SymbolNotFound
|
35
52
|
|
36
53
|
If a symbol cannot be found an [IEX::Errors::SymbolNotFound](lib/iex/errors/symbol_not_found_error.rb) exception is raised.
|
37
54
|
|
@@ -45,4 +62,4 @@ Copyright (c) 2018, [Daniel Doubrovkine](https://twitter.com/dblockdotorg) and [
|
|
45
62
|
|
46
63
|
This project is licensed under the [MIT License](LICENSE.md).
|
47
64
|
|
48
|
-
Data provided for free by [IEX](https://iextrading.com/developer), see [terms](https://iextrading.com/api-
|
65
|
+
Data provided for free by [IEX](https://iextrading.com/developer), see [terms](https://iextrading.com/api-terms).
|
data/lib/iex-ruby-client.rb
CHANGED
@@ -2,8 +2,8 @@ require 'faraday'
|
|
2
2
|
require 'faraday_middleware'
|
3
3
|
require 'faraday_middleware/response_middleware'
|
4
4
|
require 'hashie'
|
5
|
+
|
5
6
|
require_relative 'iex/version'
|
6
7
|
require_relative 'iex/errors'
|
7
8
|
require_relative 'iex/api'
|
8
|
-
require_relative 'iex/
|
9
|
-
require_relative 'iex/quote'
|
9
|
+
require_relative 'iex/resources'
|
data/lib/iex/api.rb
CHANGED
@@ -1 +1,21 @@
|
|
1
|
+
module IEX
|
2
|
+
module Api
|
3
|
+
ROOT_URI = 'https://api.iextrading.com/1.0/stock'.freeze
|
4
|
+
|
5
|
+
def self.default_connection(path)
|
6
|
+
Faraday.new(
|
7
|
+
url: "#{ROOT_URI}/#{path}",
|
8
|
+
request: {
|
9
|
+
params_encoder: Faraday::FlatParamsEncoder
|
10
|
+
}
|
11
|
+
) do |c|
|
12
|
+
c.use ::FaradayMiddleware::ParseJson
|
13
|
+
c.use Faraday::Response::RaiseError
|
14
|
+
c.use Faraday::Adapter::NetHttp
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
1
20
|
require_relative 'api/quote'
|
21
|
+
require_relative 'api/company'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module IEX
|
2
|
+
module Api
|
3
|
+
module Company
|
4
|
+
def self.get(params)
|
5
|
+
params = params.dup
|
6
|
+
symbol = params.delete(:q)
|
7
|
+
connection(symbol).get do |c|
|
8
|
+
c.params.merge!(params)
|
9
|
+
end.body
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.connection(symbol)
|
13
|
+
IEX::Api.default_connection "#{symbol}/company"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/iex/api/quote.rb
CHANGED
@@ -10,16 +10,7 @@ module IEX
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.connection(symbol)
|
13
|
-
|
14
|
-
url: "https://api.iextrading.com/1.0/stock/#{symbol}/quote",
|
15
|
-
request: {
|
16
|
-
params_encoder: Faraday::FlatParamsEncoder
|
17
|
-
}
|
18
|
-
) do |c|
|
19
|
-
c.use ::FaradayMiddleware::ParseJson
|
20
|
-
c.use Faraday::Response::RaiseError
|
21
|
-
c.use Faraday::Adapter::NetHttp
|
22
|
-
end
|
13
|
+
IEX::Api.default_connection "#{symbol}/quote"
|
23
14
|
end
|
24
15
|
end
|
25
16
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module IEX
|
2
|
+
module Resources
|
3
|
+
class Company < Resource
|
4
|
+
property 'symbol' # stock ticker
|
5
|
+
property 'company_name', from: 'companyName' # company name
|
6
|
+
property 'exchange' # primary listings exchange
|
7
|
+
property 'industry'
|
8
|
+
property 'website'
|
9
|
+
property 'description'
|
10
|
+
property 'ceo', from: 'CEO'
|
11
|
+
property 'issue_type', from: 'issueType' # common issue type of the stock
|
12
|
+
property 'sector'
|
13
|
+
|
14
|
+
def self.get(symbol)
|
15
|
+
new IEX::Api::Company.get(q: symbol)
|
16
|
+
rescue Faraday::ResourceNotFound => e
|
17
|
+
raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module IEX
|
2
|
+
module Resources
|
3
|
+
class Quote < Resource
|
4
|
+
property 'symbol' # stock ticker
|
5
|
+
property 'company_name', from: 'companyName' # company name
|
6
|
+
property 'primary_exchange', from: 'primaryExchange' # primary listings exchange
|
7
|
+
property 'sector' # sector of the stock
|
8
|
+
property 'calculation_price', from: 'calculationPrice' # source of the latest price - tops, sip, previousclose or close
|
9
|
+
property 'open' # official open price
|
10
|
+
property 'open_time', from: 'openTime' # official listing exchange time for the open
|
11
|
+
property 'close' # official close price
|
12
|
+
property 'close_time', from: 'closeTime' # official listing exchange time for the close
|
13
|
+
property 'high' # market-wide highest price from the SIP, 15 minute delayed
|
14
|
+
property 'low' # market-wide lowest price from the SIP, 15 minute delayed
|
15
|
+
property 'latest_price', from: 'latestPrice' # latest price being the IEX real time price, the 15 minute delayed market price, or the previous close price
|
16
|
+
property 'latest_source', from: 'latestSource' # the source of latestPrice - IEX real time price, 15 minute delayed price, Close or Previous close
|
17
|
+
property 'latest_time', from: 'latestTime' # human readable time of the latestPrice
|
18
|
+
property 'latest_update', from: 'latestUpdate' # the update time of latestPrice in milliseconds since midnight Jan 1, 1970
|
19
|
+
property 'latest_update_t', from: 'latestUpdate', with: ->(v) { Time.at(v / 1000) } # the update time of latestPrice
|
20
|
+
property 'latest_volume', from: 'latestVolume' # the total market volume of the stock
|
21
|
+
property 'iex_realtime_price', from: 'iexRealtimePrice' # last sale price of the stock on IEX
|
22
|
+
property 'iex_realtime_size', from: 'iexRealtimeSize' # last sale size of the stock on IEX
|
23
|
+
property 'iex_last_updated', from: 'iexLastUpdated' # last update time of the data in milliseconds since midnight Jan 1, 1970 UTC or -1 or 0; if the value is -1 or 0, IEX has not quoted the symbol in the trading day
|
24
|
+
property 'iex_last_updated_t', from: 'iexLastUpdated', with: ->(v) { v > 0 ? Time.at(v / 1000) : nil } # last update time of the data
|
25
|
+
property 'delayed_price', from: 'delayedPrice' # 15 minute delayed market price
|
26
|
+
property 'delayed_price_time', from: 'delayedPriceTime' # time of the delayed market price
|
27
|
+
property 'previous_close', from: 'previousClose' # adjusted close price of the last trading day of the stock
|
28
|
+
property 'change' # change in value, calculated using calculation_price from previous_close
|
29
|
+
property 'change_percent', from: 'changePercent' # change in percent, calculated using calculation_price from previous_close
|
30
|
+
property 'change_percent_s', from: 'changePercent', with: lambda { |v|
|
31
|
+
[
|
32
|
+
v > 0 ? '+' : '',
|
33
|
+
format('%.2f', v * 100),
|
34
|
+
'%'
|
35
|
+
].join
|
36
|
+
} # change in percent as a String with a leading + or - sign
|
37
|
+
property 'iex_market_percent', from: 'iexMarketPercent' # IEX’s percentage of the market in the stock
|
38
|
+
property 'iex_volume', from: 'iexVolume' # shares traded in the stock on IEX
|
39
|
+
property 'avg_total_volume', from: 'avgTotalVolume' # 30 day average volume on all markets
|
40
|
+
property 'iex_bid_price', from: 'iexBidPrice' # best bid price on IEX
|
41
|
+
property 'iex_bid_size', from: 'iexBidSize' # amount of shares on the bid on IEX
|
42
|
+
property 'iex_ask_price', from: 'iexAskPrice' # the best ask price on IEX
|
43
|
+
property 'iex_ask_size', from: 'iexAskSize' # amount of shares on the ask on IEX
|
44
|
+
property 'market_cap', from: 'marketCap' # market cap, calculated in real time using calculation_price
|
45
|
+
property 'pe_ratio', from: 'peRatio' # PE ratio, calculated in real time using calculation_price
|
46
|
+
property 'week_52_high', from: 'week52High' # adjusted 52 week high
|
47
|
+
property 'week_52_low', from: 'week52Low' # adjusted 52 week low
|
48
|
+
property 'ytd_change', from: 'ytdChange' # price change percentage from start of year to previous close
|
49
|
+
|
50
|
+
def self.get(symbol)
|
51
|
+
new IEX::Api::Quote.get(q: symbol)
|
52
|
+
rescue Faraday::ResourceNotFound => e
|
53
|
+
raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
File without changes
|
data/lib/iex/version.rb
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.iextrading.com/1.0/stock/INVALID/company
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.14.0
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 404
|
19
|
+
message: Not Found
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx
|
23
|
+
Date:
|
24
|
+
- Mon, 26 Mar 2018 20:47:50 GMT
|
25
|
+
Content-Type:
|
26
|
+
- text/html; charset=utf-8
|
27
|
+
Transfer-Encoding:
|
28
|
+
- chunked
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Set-Cookie:
|
32
|
+
- ctoken=0397c9aa99f94e3bb4c858ac83fbdd2b; Domain=.iextrading.com; Path=/; Expires=Tue,
|
33
|
+
27 Mar 2018 08:47:50 GMT; Secure
|
34
|
+
Content-Security-Policy:
|
35
|
+
- default-src 'self'; child-src 'none'; object-src 'none'; style-src 'self'
|
36
|
+
'unsafe-inline'; font-src data:; connect-src 'self' https://auth.iextrading.com
|
37
|
+
wss://iextrading.com wss://tops.iextrading.com; script-src 'self';
|
38
|
+
X-Content-Security-Policy:
|
39
|
+
- default-src 'self'; child-src 'none'; object-src 'none'; style-src 'self'
|
40
|
+
'unsafe-inline'; font-src data:; connect-src 'self' https://auth.iextrading.com
|
41
|
+
wss://iextrading.com wss://tops.iextrading.com; script-src 'self';
|
42
|
+
Frame-Options:
|
43
|
+
- deny
|
44
|
+
X-Frame-Options:
|
45
|
+
- deny
|
46
|
+
Strict-Transport-Security:
|
47
|
+
- max-age=15768000
|
48
|
+
Access-Control-Allow-Origin:
|
49
|
+
- "*"
|
50
|
+
Access-Control-Allow-Credentials:
|
51
|
+
- 'true'
|
52
|
+
Access-Control-Allow-Methods:
|
53
|
+
- GET, OPTIONS
|
54
|
+
Access-Control-Allow-Headers:
|
55
|
+
- Origin, X-Requested-With, Content-Type, Accept
|
56
|
+
body:
|
57
|
+
encoding: ASCII-8BIT
|
58
|
+
string: Unknown symbol
|
59
|
+
http_version:
|
60
|
+
recorded_at: Mon, 26 Mar 2018 20:47:50 GMT
|
61
|
+
recorded_with: VCR 4.0.0
|
@@ -0,0 +1,68 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.iextrading.com/1.0/stock/MSFT/company
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.14.0
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx
|
23
|
+
Date:
|
24
|
+
- Mon, 26 Mar 2018 20:47:50 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json; charset=utf-8
|
27
|
+
Content-Length:
|
28
|
+
- '490'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Set-Cookie:
|
32
|
+
- ctoken=a59dd70ac7f44bb1a19cebd4d5204e8d; Domain=.iextrading.com; Path=/; Expires=Tue,
|
33
|
+
27 Mar 2018 08:47:50 GMT; Secure
|
34
|
+
Content-Security-Policy:
|
35
|
+
- default-src 'self'; child-src 'none'; object-src 'none'; style-src 'self'
|
36
|
+
'unsafe-inline'; font-src data:; connect-src 'self' https://auth.iextrading.com
|
37
|
+
wss://iextrading.com wss://tops.iextrading.com; script-src 'self';
|
38
|
+
X-Content-Security-Policy:
|
39
|
+
- default-src 'self'; child-src 'none'; object-src 'none'; style-src 'self'
|
40
|
+
'unsafe-inline'; font-src data:; connect-src 'self' https://auth.iextrading.com
|
41
|
+
wss://iextrading.com wss://tops.iextrading.com; script-src 'self';
|
42
|
+
Frame-Options:
|
43
|
+
- deny
|
44
|
+
X-Frame-Options:
|
45
|
+
- deny
|
46
|
+
X-Content-Type-Options:
|
47
|
+
- nosniff
|
48
|
+
Strict-Transport-Security:
|
49
|
+
- max-age=15768000
|
50
|
+
Access-Control-Allow-Origin:
|
51
|
+
- "*"
|
52
|
+
Access-Control-Allow-Credentials:
|
53
|
+
- 'true'
|
54
|
+
Access-Control-Allow-Methods:
|
55
|
+
- GET, OPTIONS
|
56
|
+
Access-Control-Allow-Headers:
|
57
|
+
- Origin, X-Requested-With, Content-Type, Accept
|
58
|
+
body:
|
59
|
+
encoding: UTF-8
|
60
|
+
string: '{"symbol":"MSFT","companyName":"Microsoft Corporation","exchange":"Nasdaq
|
61
|
+
Global Select","industry":"Application Software","website":"http://www.microsoft.com","description":"Microsoft
|
62
|
+
Corp is a technology company. It develop, license, and support a wide range
|
63
|
+
of software products and services. Its business is organized into three segments:
|
64
|
+
Productivity and Business Processes, Intelligent Cloud, and More Personal
|
65
|
+
Computing.","CEO":"Satya Nadella","issueType":"cs","sector":"Technology"}'
|
66
|
+
http_version:
|
67
|
+
recorded_at: Mon, 26 Mar 2018 20:47:50 GMT
|
68
|
+
recorded_with: VCR 4.0.0
|
File without changes
|
File without changes
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IEX::Resources::Company do
|
4
|
+
context 'known symbol', vcr: { cassette_name: 'company/msft' } do
|
5
|
+
subject do
|
6
|
+
IEX::Resources::Company.get('MSFT')
|
7
|
+
end
|
8
|
+
it 'retrieves company information' do
|
9
|
+
expect(subject.symbol).to eq 'MSFT'
|
10
|
+
expect(subject.ceo).to eq 'Satya Nadella'
|
11
|
+
expect(subject.company_name).to eq 'Microsoft Corporation'
|
12
|
+
expect(subject.description).to include 'Microsoft Corp is a technology company.'
|
13
|
+
expect(subject.exchange).to eq 'Nasdaq Global Select'
|
14
|
+
expect(subject.industry).to eq 'Application Software'
|
15
|
+
expect(subject.issue_type).to eq 'cs'
|
16
|
+
expect(subject.website).to eq 'http://www.microsoft.com'
|
17
|
+
expect(subject.sector).to eq 'Technology'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
context 'invalid symbol', vcr: { cassette_name: 'company/invalid' } do
|
21
|
+
subject do
|
22
|
+
IEX::Resources::Company.get('INVALID')
|
23
|
+
end
|
24
|
+
it 'fails with SymbolNotFoundError' do
|
25
|
+
expect { subject }.to raise_error IEX::Errors::SymbolNotFoundError, 'Symbol INVALID Not Found'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe IEX::Quote do
|
4
|
-
context 'known symbol', vcr: { cassette_name: 'msft' } do
|
3
|
+
describe IEX::Resources::Quote do
|
4
|
+
context 'known symbol', vcr: { cassette_name: 'quote/msft' } do
|
5
5
|
subject do
|
6
|
-
IEX::Quote.get('MSFT')
|
6
|
+
IEX::Resources::Quote.get('MSFT')
|
7
7
|
end
|
8
8
|
it 'retrieves a quote' do
|
9
9
|
expect(subject.symbol).to eq 'MSFT'
|
@@ -19,10 +19,16 @@ describe IEX::Quote do
|
|
19
19
|
expect(subject.change_percent).to eq 0.00418
|
20
20
|
expect(subject.change_percent_s).to eq '+0.42%'
|
21
21
|
end
|
22
|
+
it 'coerces times' do
|
23
|
+
expect(subject.latest_update).to eq 1_521_818_145_007
|
24
|
+
expect(subject.latest_update_t).to eq Time.at(1_521_818_145)
|
25
|
+
expect(subject.iex_last_updated).to eq 1_521_818_145_007
|
26
|
+
expect(subject.iex_last_updated_t).to eq Time.at(1_521_818_145)
|
27
|
+
end
|
22
28
|
end
|
23
|
-
context 'invalid symbol', vcr: { cassette_name: 'invalid' } do
|
29
|
+
context 'invalid symbol', vcr: { cassette_name: 'quote/invalid' } do
|
24
30
|
subject do
|
25
|
-
IEX::Quote.get('INVALID')
|
31
|
+
IEX::Resources::Quote.get('INVALID')
|
26
32
|
end
|
27
33
|
it 'fails with SymbolNotFoundError' do
|
28
34
|
expect { subject }.to raise_error IEX::Errors::SymbolNotFoundError, 'Symbol INVALID Not Found'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iex-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -143,15 +143,21 @@ files:
|
|
143
143
|
- iex-ruby-client.gemspec
|
144
144
|
- lib/iex-ruby-client.rb
|
145
145
|
- lib/iex/api.rb
|
146
|
+
- lib/iex/api/company.rb
|
146
147
|
- lib/iex/api/quote.rb
|
147
148
|
- lib/iex/errors.rb
|
148
149
|
- lib/iex/errors/symbol_not_found_error.rb
|
149
|
-
- lib/iex/
|
150
|
-
- lib/iex/
|
150
|
+
- lib/iex/resources.rb
|
151
|
+
- lib/iex/resources/company.rb
|
152
|
+
- lib/iex/resources/quote.rb
|
153
|
+
- lib/iex/resources/resource.rb
|
151
154
|
- lib/iex/version.rb
|
152
|
-
- spec/fixtures/iex/invalid.yml
|
153
|
-
- spec/fixtures/iex/msft.yml
|
154
|
-
- spec/iex/
|
155
|
+
- spec/fixtures/iex/company/invalid.yml
|
156
|
+
- spec/fixtures/iex/company/msft.yml
|
157
|
+
- spec/fixtures/iex/quote/invalid.yml
|
158
|
+
- spec/fixtures/iex/quote/msft.yml
|
159
|
+
- spec/iex/resources/company_spec.rb
|
160
|
+
- spec/iex/resources/quote_spec.rb
|
155
161
|
- spec/iex/version_spec.rb
|
156
162
|
- spec/spec_helper.rb
|
157
163
|
- spec/support/vcr.rb
|
@@ -175,14 +181,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
181
|
version: 1.3.6
|
176
182
|
requirements: []
|
177
183
|
rubyforge_project:
|
178
|
-
rubygems_version: 2.6.
|
184
|
+
rubygems_version: 2.6.13
|
179
185
|
signing_key:
|
180
186
|
specification_version: 4
|
181
187
|
summary: IEX Finance API Ruby client with support for retrieving stock quotes.
|
182
188
|
test_files:
|
183
|
-
- spec/fixtures/iex/invalid.yml
|
184
|
-
- spec/fixtures/iex/msft.yml
|
185
|
-
- spec/iex/
|
189
|
+
- spec/fixtures/iex/company/invalid.yml
|
190
|
+
- spec/fixtures/iex/company/msft.yml
|
191
|
+
- spec/fixtures/iex/quote/invalid.yml
|
192
|
+
- spec/fixtures/iex/quote/msft.yml
|
193
|
+
- spec/iex/resources/company_spec.rb
|
194
|
+
- spec/iex/resources/quote_spec.rb
|
186
195
|
- spec/iex/version_spec.rb
|
187
196
|
- spec/spec_helper.rb
|
188
197
|
- spec/support/vcr.rb
|
data/lib/iex/quote.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
module IEX
|
2
|
-
class Quote < Resource
|
3
|
-
property 'symbol'
|
4
|
-
property 'company_name', from: 'companyName'
|
5
|
-
property 'primary_exchange', from: 'primaryExchange'
|
6
|
-
property 'sector'
|
7
|
-
property 'calculation_price', from: 'calculationPrice'
|
8
|
-
property 'open'
|
9
|
-
property 'open_time', from: 'openTime'
|
10
|
-
property 'close'
|
11
|
-
property 'close_time', from: 'closeTime'
|
12
|
-
property 'high'
|
13
|
-
property 'low'
|
14
|
-
property 'latest_price', from: 'latestPrice'
|
15
|
-
property 'latest_source', from: 'latestSource'
|
16
|
-
property 'latest_time', from: 'latestTime'
|
17
|
-
property 'latest_update', from: 'latestUpdate'
|
18
|
-
property 'latest_volume', from: 'latestVolume'
|
19
|
-
property 'iex_realtime_price', from: 'iexRealtimePrice'
|
20
|
-
property 'iex_realtime_size', from: 'iexRealtimeSize'
|
21
|
-
property 'iex_last_updated', from: 'iexLastUpdated'
|
22
|
-
property 'delayed_price', from: 'delayedPrice'
|
23
|
-
property 'delayed_price_time', from: 'delayedPriceTime'
|
24
|
-
property 'previous_close', from: 'previousClose'
|
25
|
-
property 'change'
|
26
|
-
property 'change_percent', from: 'changePercent'
|
27
|
-
property 'iex_market_percent', from: 'iexMarketPercent'
|
28
|
-
property 'iex_volume', from: 'iexVolume'
|
29
|
-
property 'avg_total_volume', from: 'avgTotalVolume'
|
30
|
-
property 'iex_bid_price', from: 'iexBidPrice'
|
31
|
-
property 'iex_bid_size', from: 'iexBidSize'
|
32
|
-
property 'iex_ask_price', from: 'iexAskPrice'
|
33
|
-
property 'iex_ask_size', from: 'iexAskSize'
|
34
|
-
property 'market_cap', from: 'marketCap'
|
35
|
-
property 'pe_ratio', from: 'peRatio'
|
36
|
-
property 'week_52_high', from: 'week52High'
|
37
|
-
property 'week_52_low', from: 'week52Low'
|
38
|
-
property 'ytd_change', from: 'ytdChange'
|
39
|
-
|
40
|
-
def change_percent_s
|
41
|
-
[
|
42
|
-
change_percent > 0 ? '+' : '',
|
43
|
-
format('%.2f', change_percent * 100),
|
44
|
-
'%'
|
45
|
-
].join
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.get(symbol)
|
49
|
-
new IEX::Api::Quote.get(q: symbol)
|
50
|
-
rescue Faraday::ResourceNotFound => e
|
51
|
-
raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|