iex-ruby-client 0.4.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +8 -36
- data/CHANGELOG.md +5 -0
- data/LICENSE.md +1 -1
- data/README.md +113 -160
- data/UPGRADING.md +55 -3
- data/iex-ruby-client.gemspec +1 -1
- data/lib/iex-ruby-client.rb +2 -0
- data/lib/iex/api.rb +15 -31
- data/lib/iex/api/client.rb +30 -0
- data/lib/iex/api/config.rb +45 -0
- data/lib/iex/cloud.rb +3 -0
- data/lib/iex/cloud/connection.rb +37 -0
- data/lib/iex/cloud/request.rb +38 -0
- data/lib/iex/cloud/response.rb +20 -0
- data/lib/iex/endpoints/chart.rb +39 -0
- data/lib/iex/endpoints/company.rb +11 -0
- data/lib/iex/endpoints/crypto.rb +11 -0
- data/lib/iex/endpoints/dividends.rb +18 -0
- data/lib/iex/endpoints/earnings.rb +13 -0
- data/lib/iex/endpoints/key_stats.rb +11 -0
- data/lib/iex/endpoints/largest_trades.rb +13 -0
- data/lib/iex/endpoints/logo.rb +11 -0
- data/lib/iex/endpoints/news.rb +19 -0
- data/lib/iex/endpoints/ohlc.rb +17 -0
- data/lib/iex/endpoints/price.rb +11 -0
- data/lib/iex/endpoints/quote.rb +11 -0
- data/lib/iex/endpoints/sectors.rb +17 -0
- data/lib/iex/errors.rb +1 -0
- data/lib/iex/errors/client_error.rb +13 -1
- data/lib/iex/errors/permission_denied_error.rb +5 -0
- data/lib/iex/logger.rb +13 -0
- data/lib/iex/resources.rb +0 -1
- data/lib/iex/resources/chart.rb +38 -21
- data/lib/iex/resources/company.rb +2 -8
- data/lib/iex/resources/crypto.rb +10 -18
- data/lib/iex/resources/dividends.rb +5 -15
- data/lib/iex/resources/earnings.rb +1 -15
- data/lib/iex/resources/key_stats.rb +11 -57
- data/lib/iex/resources/largest_trades.rb +0 -10
- data/lib/iex/resources/logo.rb +0 -8
- data/lib/iex/resources/news.rb +1 -11
- data/lib/iex/resources/ohlc.rb +8 -16
- data/lib/iex/resources/quote.rb +0 -8
- data/lib/iex/resources/resource.rb +19 -2
- data/lib/iex/resources/sectors.rb +0 -10
- data/lib/iex/version.rb +1 -1
- data/spec/fixtures/iex/chart/1d.yml +472 -444
- data/spec/fixtures/iex/chart/20190306.yml +475 -0
- data/spec/fixtures/iex/chart/bad_option.yml +80 -62
- data/spec/fixtures/iex/chart/chartInterval.yml +121 -98
- data/spec/fixtures/iex/chart/dynamic/1m.yml +106 -81
- data/spec/fixtures/iex/chart/invalid.yml +80 -58
- data/spec/fixtures/iex/chart/msft.yml +106 -81
- data/spec/fixtures/iex/client/access_denied.yml +49 -0
- data/spec/fixtures/iex/company/invalid.yml +80 -58
- data/spec/fixtures/iex/company/msft.yml +87 -65
- data/spec/fixtures/iex/crypto/btcusdt.yml +87 -0
- data/spec/fixtures/iex/dividends/invalid.yml +80 -62
- data/spec/fixtures/iex/dividends/msft.yml +88 -66
- data/spec/fixtures/iex/dividends/msft_1y.yml +92 -68
- data/spec/fixtures/iex/dividends/msft_default_range.yml +85 -65
- data/spec/fixtures/iex/dividends/msft_invalid_range.yml +82 -64
- data/spec/fixtures/iex/earnings/invalid.yml +80 -62
- data/spec/fixtures/iex/earnings/msft.yml +84 -68
- data/spec/fixtures/iex/key_stats/invalid.yml +80 -62
- data/spec/fixtures/iex/key_stats/msft.yml +84 -65
- data/spec/fixtures/iex/largest-trades/aapl.yml +91 -73
- data/spec/fixtures/iex/largest-trades/invalid.yml +80 -62
- data/spec/fixtures/iex/logo/msft.yml +82 -64
- data/spec/fixtures/iex/news/invalid.yml +80 -58
- data/spec/fixtures/iex/news/msft.yml +83 -61
- data/spec/fixtures/iex/news/msft_7.yml +83 -61
- data/spec/fixtures/iex/ohlc/market.yml +82 -65
- data/spec/fixtures/iex/ohlc/msft.yml +82 -64
- data/spec/fixtures/iex/price/invalid.yml +80 -58
- data/spec/fixtures/iex/price/msft.yml +82 -60
- data/spec/fixtures/iex/quote/invalid.yml +80 -62
- data/spec/fixtures/iex/quote/msft.yml +84 -66
- data/spec/fixtures/iex/sectors/invalid.yml +80 -62
- data/spec/fixtures/iex/sectors/sectors-performance.yml +88 -69
- data/spec/iex/client_spec.rb +138 -0
- data/spec/iex/config_spec.rb +22 -0
- data/spec/iex/{resources → endpoints}/chart_spec.rb +23 -21
- data/spec/iex/{resources → endpoints}/company_spec.rb +11 -7
- data/spec/iex/endpoints/crypto_spec.rb +66 -0
- data/spec/iex/{resources → endpoints}/dividends_spec.rb +17 -14
- data/spec/iex/endpoints/earnings_spec.rb +36 -0
- data/spec/iex/endpoints/key_stats_spec.rb +62 -0
- data/spec/iex/{resources → endpoints}/largest_trades_spec.rb +8 -6
- data/spec/iex/{resources → endpoints}/logo_spec.rb +3 -1
- data/spec/iex/endpoints/news_spec.rb +36 -0
- data/spec/iex/{resources → endpoints}/ohlc_spec.rb +15 -13
- data/spec/iex/{resources → endpoints}/price_spec.rb +6 -4
- data/spec/iex/endpoints/quote_spec.rb +38 -0
- data/spec/iex/{resources → endpoints}/sectors_spec.rb +7 -6
- data/spec/iex/resources/{base_spec.rb → resource_spec.rb} +6 -6
- data/spec/spec_helper.rb +2 -0
- data/spec/support/client.rb +6 -0
- metadata +66 -59
- data/lib/iex/api/chart.rb +0 -24
- data/lib/iex/api/company.rb +0 -13
- data/lib/iex/api/crypto.rb +0 -13
- data/lib/iex/api/dividends.rb +0 -17
- data/lib/iex/api/earnings.rb +0 -13
- data/lib/iex/api/key_stats.rb +0 -13
- data/lib/iex/api/largest_trades.rb +0 -13
- data/lib/iex/api/logo.rb +0 -13
- data/lib/iex/api/news.rb +0 -18
- data/lib/iex/api/ohlc.rb +0 -17
- data/lib/iex/api/price.rb +0 -13
- data/lib/iex/api/quote.rb +0 -13
- data/lib/iex/api/sectors.rb +0 -16
- data/lib/iex/resources/base.rb +0 -27
- data/lib/iex/resources/chart/base.rb +0 -14
- data/lib/iex/resources/chart/default.rb +0 -21
- data/lib/iex/resources/chart/one_day.rb +0 -20
- data/lib/iex/resources/ohlc/base.rb +0 -14
- data/lib/iex/resources/ohlc/timed_price.rb +0 -12
- data/lib/iex/resources/price.rb +0 -13
- data/spec/fixtures/iex/chart/20180227.yml +0 -452
- data/spec/fixtures/iex/crypto.yml +0 -101
- data/spec/fixtures/iex/news/market.yml +0 -64
- data/spec/iex/resources/crypto_spec.rb +0 -65
- data/spec/iex/resources/earnings_spec.rb +0 -38
- data/spec/iex/resources/key_stats_spec.rb +0 -94
- data/spec/iex/resources/news_spec.rb +0 -44
- data/spec/iex/resources/quote_spec.rb +0 -38
@@ -0,0 +1,11 @@
|
|
1
|
+
module IEX
|
2
|
+
module Endpoints
|
3
|
+
module Logo
|
4
|
+
def logo(symbol, options = {})
|
5
|
+
IEX::Resources::Logo.new(get("stock/#{symbol.downcase}/logo", options))
|
6
|
+
rescue Faraday::ResourceNotFound => e
|
7
|
+
raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module IEX
|
2
|
+
module Endpoints
|
3
|
+
module News
|
4
|
+
def news(symbol, range = nil, options = {})
|
5
|
+
get([
|
6
|
+
'stock',
|
7
|
+
symbol,
|
8
|
+
'news',
|
9
|
+
range ? 'last' : nil,
|
10
|
+
range
|
11
|
+
].compact.join('/'), options).map do |data|
|
12
|
+
IEX::Resources::News.new(data)
|
13
|
+
end
|
14
|
+
rescue Faraday::ResourceNotFound => e
|
15
|
+
raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module IEX
|
2
|
+
module Endpoints
|
3
|
+
module Ohlc
|
4
|
+
def ohlc(symbol, options = {})
|
5
|
+
IEX::Resources::OHLC.new(get("stock/#{symbol}/ohlc", options))
|
6
|
+
rescue Faraday::ResourceNotFound => e
|
7
|
+
raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
|
8
|
+
end
|
9
|
+
|
10
|
+
def market(options = {})
|
11
|
+
Hash[get('stock/market/ohlc', options).map do |k, v|
|
12
|
+
[k, IEX::Resources::OHLC.new(v)]
|
13
|
+
end]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module IEX
|
2
|
+
module Endpoints
|
3
|
+
module Quote
|
4
|
+
def quote(symbol, options = {})
|
5
|
+
IEX::Resources::Quote.new(get("stock/#{symbol}/quote", options))
|
6
|
+
rescue Faraday::ResourceNotFound => e
|
7
|
+
raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module IEX
|
2
|
+
module Endpoints
|
3
|
+
module Sectors
|
4
|
+
def sectors(symbol, options = {})
|
5
|
+
get([
|
6
|
+
'stock',
|
7
|
+
symbol,
|
8
|
+
'sector-performance'
|
9
|
+
].compact.join('/'), options).map do |data|
|
10
|
+
IEX::Resources::Sectors.new(data)
|
11
|
+
end
|
12
|
+
rescue Faraday::ResourceNotFound => e
|
13
|
+
raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/iex/errors.rb
CHANGED
@@ -5,7 +5,19 @@ module IEX
|
|
5
5
|
|
6
6
|
def initialize(response)
|
7
7
|
@response = response
|
8
|
-
super
|
8
|
+
super error
|
9
|
+
end
|
10
|
+
|
11
|
+
def error
|
12
|
+
if body.is_a?(Hash) && body.key?('error')
|
13
|
+
body['error']
|
14
|
+
else
|
15
|
+
body
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def body
|
20
|
+
response[:body]
|
9
21
|
end
|
10
22
|
end
|
11
23
|
end
|
data/lib/iex/logger.rb
ADDED
data/lib/iex/resources.rb
CHANGED
@@ -9,7 +9,6 @@ require_relative 'resources/largest_trades'
|
|
9
9
|
require_relative 'resources/logo'
|
10
10
|
require_relative 'resources/news'
|
11
11
|
require_relative 'resources/ohlc'
|
12
|
-
require_relative 'resources/price'
|
13
12
|
require_relative 'resources/quote'
|
14
13
|
require_relative 'resources/sectors'
|
15
14
|
require_relative 'resources/crypto'
|
data/lib/iex/resources/chart.rb
CHANGED
@@ -1,27 +1,44 @@
|
|
1
|
-
require_relative 'base'
|
2
|
-
require_relative 'chart/base'
|
3
|
-
require_relative 'chart/one_day'
|
4
|
-
require_relative 'chart/default'
|
5
|
-
|
6
1
|
module IEX
|
7
2
|
module Resources
|
8
3
|
module Chart
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
4
|
+
class Base < Resource
|
5
|
+
property 'high'
|
6
|
+
property 'low'
|
7
|
+
property 'volume'
|
8
|
+
property 'label'
|
9
|
+
property 'change_over_time', from: 'changeOverTime'
|
10
|
+
property 'date', transform_with: ->(v) { Date.parse(v) }
|
11
|
+
end
|
12
|
+
|
13
|
+
class Default < Base
|
14
|
+
property 'open'
|
15
|
+
property 'close'
|
16
|
+
property 'unadjusted_volume', from: 'unadjustedVolume'
|
17
|
+
property 'change'
|
18
|
+
property 'change_percent', from: 'changePercent'
|
19
|
+
property 'change_percent_s', from: 'changePercent', with: lambda { |v|
|
20
|
+
[
|
21
|
+
v > 0 ? '+' : '',
|
22
|
+
format('%.2f', v),
|
23
|
+
'%'
|
24
|
+
].join
|
25
|
+
} # change in percent as a String with a leading + or - sign
|
26
|
+
property 'vwap'
|
27
|
+
end
|
28
|
+
|
29
|
+
class OneDay < Base
|
30
|
+
property 'minute'
|
31
|
+
property 'market_average', from: 'marketAverage'
|
32
|
+
property 'market_notional', from: 'marketNotional'
|
33
|
+
property 'market_number_of_trades', from: 'marketNumberOfTrades'
|
34
|
+
property 'market_high', from: 'marketHigh'
|
35
|
+
property 'market_low', from: 'marketLow'
|
36
|
+
property 'market_volume', from: 'marketVolume'
|
37
|
+
property 'market_change_over_time', from: 'marketChangeOverTime'
|
38
|
+
property 'average'
|
39
|
+
property 'notional'
|
40
|
+
property 'number_of_trades', from: 'numberOfTrades'
|
41
|
+
property 'simplify_factor', from: 'simplifyFactor'
|
25
42
|
end
|
26
43
|
end
|
27
44
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require_relative 'base'
|
2
|
-
|
3
1
|
module IEX
|
4
2
|
module Resources
|
5
3
|
class Company < Resource
|
@@ -10,14 +8,10 @@ module IEX
|
|
10
8
|
property 'website'
|
11
9
|
property 'description'
|
12
10
|
property 'ceo', from: 'CEO'
|
11
|
+
property 'security_name', from: 'securityName'
|
13
12
|
property 'issue_type', from: 'issueType' # common issue type of the stock
|
14
13
|
property 'sector'
|
15
|
-
|
16
|
-
def self.get(stock_symbol)
|
17
|
-
Base.symbol(stock_symbol) do
|
18
|
-
new IEX::Api::Company.get(stock_symbol)
|
19
|
-
end
|
20
|
-
end
|
14
|
+
property 'employees'
|
21
15
|
end
|
22
16
|
end
|
23
17
|
end
|
data/lib/iex/resources/crypto.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require_relative 'base'
|
2
|
-
|
3
1
|
module IEX
|
4
2
|
module Resources
|
5
3
|
class Crypto < Resource
|
@@ -9,22 +7,22 @@ module IEX
|
|
9
7
|
property 'sector'
|
10
8
|
property 'calculation_price', from: 'calculationPrice'
|
11
9
|
property 'open'
|
12
|
-
property 'open_dollar', from: 'open', with: ->(v) {
|
10
|
+
property 'open_dollar', from: 'open', with: ->(v) { Resource.to_dollar(amount: v) }
|
13
11
|
property 'open_time', from: 'openTime'
|
14
12
|
property 'close'
|
15
|
-
property 'close_dollar', from: 'close', with: ->(v) {
|
13
|
+
property 'close_dollar', from: 'close', with: ->(v) { Resource.to_dollar(amount: v) }
|
16
14
|
property 'close_time', from: 'closeTime'
|
17
15
|
property 'high'
|
18
|
-
property 'high_dollar', from: 'high', with: ->(v) {
|
16
|
+
property 'high_dollar', from: 'high', with: ->(v) { Resource.to_dollar(amount: v) }
|
19
17
|
property 'low'
|
20
|
-
property 'low_dollar', from: 'low', with: ->(v) {
|
18
|
+
property 'low_dollar', from: 'low', with: ->(v) { Resource.to_dollar(amount: v) }
|
21
19
|
property 'latest_price', from: 'latestPrice'
|
22
|
-
property 'latest_price_dollar', from: 'latestPrice', with: ->(v) {
|
20
|
+
property 'latest_price_dollar', from: 'latestPrice', with: ->(v) { Resource.to_dollar(amount: v) }
|
23
21
|
property 'latest_source', from: 'latestSource'
|
24
22
|
property 'latest_time', from: 'latestTime'
|
25
23
|
property 'latest_update', from: 'latestUpdate'
|
26
24
|
property 'latest_volume', from: 'latestVolume'
|
27
|
-
property 'latest_volume_dollar', from: 'latestVolume', with: ->(v) {
|
25
|
+
property 'latest_volume_dollar', from: 'latestVolume', with: ->(v) { Resource.to_dollar(amount: v) }
|
28
26
|
property 'iex_realtime_price', from: 'iexRealtimePrice'
|
29
27
|
property 'iex_realtime_size', from: 'iexRealtimeSize'
|
30
28
|
property 'iex_last_updated', from: 'iexLastUpdated'
|
@@ -35,10 +33,10 @@ module IEX
|
|
35
33
|
property 'extended_change_percent', from: 'extendedChangePercent'
|
36
34
|
property 'extended_price_time', from: 'extendedPriceTime'
|
37
35
|
property 'previous_close', from: 'previousClose'
|
38
|
-
property 'previous_close_dollar', from: 'previousClose', with: ->(v) {
|
36
|
+
property 'previous_close_dollar', from: 'previousClose', with: ->(v) { Resource.to_dollar(amount: v) }
|
39
37
|
property 'change'
|
40
38
|
property 'change_percent', from: 'changePercent'
|
41
|
-
property 'change_percent_s', from: 'changePercent', with: ->(v) {
|
39
|
+
property 'change_percent_s', from: 'changePercent', with: ->(v) { float_to_percentage(v) }
|
42
40
|
property 'iex_market_percent', from: 'iexMarketPercent'
|
43
41
|
property 'iex_volume', from: 'iexVolume'
|
44
42
|
property 'avg_total_volume', from: 'avgTotalVolume'
|
@@ -49,20 +47,14 @@ module IEX
|
|
49
47
|
property 'market_cap', from: 'marketCap'
|
50
48
|
property 'pe_ratio', from: 'peRatio'
|
51
49
|
property 'week52_high', from: 'week52High'
|
52
|
-
property 'week52_high_dollar', from: 'week52High', with: ->(v) {
|
50
|
+
property 'week52_high_dollar', from: 'week52High', with: ->(v) { Resource.to_dollar(amount: v) }
|
53
51
|
property 'week52_low', from: 'week52low'
|
54
|
-
property 'week52_low_dollar', from: 'week52low', with: ->(v) {
|
52
|
+
property 'week52_low_dollar', from: 'week52low', with: ->(v) { Resource.to_dollar(amount: v) }
|
55
53
|
property 'ytd_change', from: 'ytdChange'
|
56
54
|
property 'bid_price', from: 'bidPrice'
|
57
55
|
property 'bid_size', from: 'bidSize'
|
58
56
|
property 'ask_price', from: 'askPrice'
|
59
57
|
property 'ask_size', from: 'askSize'
|
60
|
-
|
61
|
-
def self.get
|
62
|
-
IEX::Api::Crypto.get.map do |data|
|
63
|
-
new data
|
64
|
-
end
|
65
|
-
end
|
66
58
|
end
|
67
59
|
end
|
68
60
|
end
|
@@ -1,30 +1,20 @@
|
|
1
|
-
require_relative 'base'
|
2
|
-
|
3
1
|
module IEX
|
4
2
|
module Resources
|
5
3
|
class Dividends < Resource
|
4
|
+
property 'ex_date', from: 'exDate'
|
6
5
|
property 'payment_date', from: 'paymentDate'
|
7
6
|
property 'record_date', from: 'recordDate'
|
8
7
|
property 'declared_date', from: 'declaredDate'
|
9
8
|
property 'amount'
|
10
9
|
property 'amount_dollar'
|
11
|
-
property '
|
12
|
-
property '
|
13
|
-
property '
|
14
|
-
property 'indicated'
|
10
|
+
property 'currency'
|
11
|
+
property 'description'
|
12
|
+
property 'frequency'
|
15
13
|
|
16
14
|
def initialize(data)
|
17
15
|
super
|
18
16
|
# TODO: require Hashie >= 2.5.8, see https://github.com/intridea/hashie/pull/457
|
19
|
-
self['amount_dollar'] =
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.get(stock_symbol, range = nil)
|
23
|
-
Base.symbol(stock_symbol) do
|
24
|
-
IEX::Api::Dividends.get(stock_symbol, range).map do |data|
|
25
|
-
new data
|
26
|
-
end
|
27
|
-
end
|
17
|
+
self['amount_dollar'] = Resource.to_dollar(amount: amount, ignore_cents: false)
|
28
18
|
end
|
29
19
|
end
|
30
20
|
end
|
@@ -1,11 +1,8 @@
|
|
1
|
-
require_relative 'base'
|
2
|
-
|
3
1
|
module IEX
|
4
2
|
module Resources
|
5
3
|
class Earnings < Resource
|
6
4
|
property 'actual_eps', from: 'actualEPS'
|
7
5
|
property 'consensus_eps', from: 'consensusEPS'
|
8
|
-
property 'estimated_eps', from: 'estimatedEPS'
|
9
6
|
property 'announce_time', from: 'announceTime'
|
10
7
|
property 'number_of_estimates', from: 'numberOfEstimates'
|
11
8
|
property 'eps_surprise_dollar', from: 'EPSSurpriseDollar'
|
@@ -14,18 +11,7 @@ module IEX
|
|
14
11
|
property 'fiscal_end_date', from: 'fiscalEndDate'
|
15
12
|
property 'year_ago', from: 'yearAgo'
|
16
13
|
property 'year_ago_change_percent', from: 'yearAgoChangePercent'
|
17
|
-
property 'year_ago_change_percent_s', from: 'yearAgoChangePercent', with: ->(v) {
|
18
|
-
property 'estimated_change_percent', from: 'estimatedChangePercent'
|
19
|
-
property 'estimated_change_percent_s', from: 'estimatedChangePercent', with: ->(v) { Base.float_to_percentage(v) }
|
20
|
-
property 'symbol_id', from: 'symbolId'
|
21
|
-
|
22
|
-
def self.get(stock_symbol)
|
23
|
-
Base.symbol(stock_symbol) do
|
24
|
-
IEX::Api::Earnings.get(stock_symbol)['earnings'].map do |data|
|
25
|
-
new data
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
14
|
+
property 'year_ago_change_percent_s', from: 'yearAgoChangePercent', with: ->(v) { Resource.float_to_percentage(v) }
|
29
15
|
end
|
30
16
|
end
|
31
17
|
end
|
@@ -3,84 +3,38 @@ module IEX
|
|
3
3
|
class KeyStats < Resource
|
4
4
|
property 'company_name', from: 'companyName'
|
5
5
|
property 'market_cap', from: 'marketcap'
|
6
|
-
property 'market_cap_dollars', from: 'marketcap', with: ->(v) {
|
7
|
-
property 'beta'
|
6
|
+
property 'market_cap_dollars', from: 'marketcap', with: ->(v) { Resource.to_dollar(amount: v) }
|
8
7
|
property 'week_52_high', from: 'week52high'
|
9
|
-
property 'week_52_high_dollar', from: 'week52high', with: ->(v) {
|
8
|
+
property 'week_52_high_dollar', from: 'week52high', with: ->(v) { Resource.to_dollar(amount: v, ignore_cents: false) }
|
10
9
|
property 'week_52_low', from: 'week52low'
|
11
|
-
property 'week_52_low_dollar', from: 'week52low', with: ->(v) {
|
10
|
+
property 'week_52_low_dollar', from: 'week52low', with: ->(v) { Resource.to_dollar(amount: v, ignore_cents: false) }
|
12
11
|
property 'week_52_change'
|
13
|
-
property 'week_52_change_dollar', from: 'week52change', with: ->(v) {
|
14
|
-
property 'short_interest', from: 'shortInterest'
|
15
|
-
property 'short_date', from: 'shortDate'
|
16
|
-
property 'dividend_rate', from: 'dividendRate'
|
12
|
+
property 'week_52_change_dollar', from: 'week52change', with: ->(v) { Resource.to_dollar(amount: v, ignore_cents: false) }
|
17
13
|
property 'dividend_yield', from: 'dividendYield'
|
18
14
|
property 'ex_dividend_date', from: 'exDividendDate'
|
19
|
-
property 'latest_eps', from: 'latestEPS'
|
20
|
-
property 'latest_eps_date', from: 'latestEPSDate'
|
21
15
|
property 'shares_outstanding', from: 'sharesOutstanding'
|
22
16
|
property 'float'
|
23
|
-
property 'return_on_equity', from: 'returnOnEquity'
|
24
|
-
property 'consensus_eps', from: 'consensusEPS'
|
25
|
-
property 'number_of_estimates', from: 'numberOfEstimates'
|
26
|
-
property 'symbol'
|
27
|
-
property 'ebitda', from: 'EBITDA'
|
28
|
-
property 'revenue'
|
29
|
-
property 'revenue_dollar'
|
30
|
-
property 'gross_profit', from: 'grossProfit'
|
31
|
-
property 'gross_profit_dollar', from: 'grossProfit', with: ->(v) { Base.to_dollar(amount: v) }
|
32
|
-
property 'cash'
|
33
|
-
property 'cash_dollar', from: 'cash', with: ->(v) { Base.to_dollar(amount: v) }
|
34
|
-
property 'dept'
|
35
|
-
property 'dept_dollar', from: 'dept', with: ->(v) { Base.to_dollar(amount: v) }
|
36
17
|
property 'ttm_eps', from: 'ttmEPS'
|
37
|
-
property 'revenue_per_share', from: 'revenuePerShare'
|
38
|
-
property 'revenue_per_employee', from: 'revenuePerEmployee'
|
39
|
-
property 'pe_ratio_high', from: 'peRatioHigh'
|
40
|
-
property 'pe_ratio_low', from: 'peRatioLow'
|
41
|
-
property 'eps_surprise_dollar', from: 'EPSSurpriseDollar'
|
42
|
-
property 'eps_surprise_percent', from: 'EPSSurprisePercent'
|
43
|
-
property 'eps_surprise_percent_s', from: 'EPSSurprisePercent', with: ->(v) { Base.float_to_percentage(v) }
|
44
|
-
property 'return_on_assets', from: 'returnOnAssets'
|
45
|
-
property 'return_on_capital', from: 'returnOnCapital'
|
46
|
-
property 'profit_margin', from: 'profitMargin'
|
47
|
-
property 'price_to_sales', from: 'priceToSales'
|
48
|
-
property 'price_to_book', from: 'priceToBook'
|
49
|
-
property 'price_to_sales_dollar', from: 'priceToSales', with: ->(v) { Base.to_dollar(amount: v, ignore_cents: false) }
|
50
|
-
property 'price_to_book_dollar', from: 'priceToBook', with: ->(v) { Base.to_dollar(amount: v, ignore_cents: false) }
|
51
18
|
property 'day_200_moving_avg', from: 'day200MovingAvg'
|
52
19
|
property 'day_50_moving_avg', from: 'day50MovingAvg'
|
53
|
-
property 'institution_percent', from: 'institutionPercent'
|
54
|
-
property 'institution_percent_s', from: 'institutionPercent', with: ->(v) { Base.float_to_percentage(v) }
|
55
|
-
property 'insider_percent', from: 'insiderPercent'
|
56
|
-
property 'insider_percent_s', from: 'insiderPercent', with: ->(v) { Base.float_to_percentage(v) }
|
57
|
-
property 'short_ratio', from: 'shortRatio'
|
58
20
|
property 'year_5_change_percent', from: 'year5ChangePercent'
|
59
|
-
property 'year_5_change_percent_s', from: 'year5ChangePercent', with: ->(v) {
|
21
|
+
property 'year_5_change_percent_s', from: 'year5ChangePercent', with: ->(v) { Resource.float_to_percentage(v) }
|
60
22
|
property 'year_2_change_percent', from: 'year2ChangePercent'
|
61
|
-
property 'year_2_change_percent_s', from: 'year2ChangePercent', with: ->(v) {
|
23
|
+
property 'year_2_change_percent_s', from: 'year2ChangePercent', with: ->(v) { Resource.float_to_percentage(v) }
|
62
24
|
property 'year_1_change_percent', from: 'year1ChangePercent'
|
63
|
-
property 'year_1_change_percent_s', from: 'year1ChangePercent', with: ->(v) {
|
25
|
+
property 'year_1_change_percent_s', from: 'year1ChangePercent', with: ->(v) { Resource.float_to_percentage(v) }
|
64
26
|
property 'ytd_change_percent', from: 'ytdChangePercent'
|
65
27
|
property 'month_6_change_percent', from: 'month6ChangePercent'
|
66
|
-
property 'month_6_change_percent_s', from: 'month6ChangePercent', with: ->(v) {
|
28
|
+
property 'month_6_change_percent_s', from: 'month6ChangePercent', with: ->(v) { Resource.float_to_percentage(v) }
|
67
29
|
property 'month_3_change_percent', from: 'month3ChangePercent'
|
68
|
-
property 'month_3_change_percent_s', from: 'month3ChangePercent', with: ->(v) {
|
30
|
+
property 'month_3_change_percent_s', from: 'month3ChangePercent', with: ->(v) { Resource.float_to_percentage(v) }
|
69
31
|
property 'month_1_change_percent', from: 'month1ChangePercent'
|
70
|
-
property 'month_1_change_percent_s', from: 'month1ChangePercent', with: ->(v) {
|
32
|
+
property 'month_1_change_percent_s', from: 'month1ChangePercent', with: ->(v) { Resource.float_to_percentage(v) }
|
71
33
|
property 'day_5_change_percent', from: 'day5ChangePercent'
|
72
|
-
property 'day_5_change_percent_s', from: 'day5ChangePercent', with: ->(v) {
|
34
|
+
property 'day_5_change_percent_s', from: 'day5ChangePercent', with: ->(v) { Resource.float_to_percentage(v) }
|
73
35
|
|
74
36
|
def initialize(data = {})
|
75
37
|
super
|
76
|
-
# TODO: require Hashie >= 2.5.8, see https://github.com/intridea/hashie/pull/457
|
77
|
-
self['revenue_dollar'] = Base.to_dollar(amount: revenue)
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.get(symbol)
|
81
|
-
new IEX::Api::KeyStats.get(symbol)
|
82
|
-
rescue Faraday::ResourceNotFound => e
|
83
|
-
raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
|
84
38
|
end
|
85
39
|
end
|
86
40
|
end
|