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,138 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IEX::Api::Client do
|
4
|
+
before do
|
5
|
+
IEX::Api.config.reset!
|
6
|
+
end
|
7
|
+
context 'with defaults' do
|
8
|
+
let(:client) { described_class.new }
|
9
|
+
context '#initialize' do
|
10
|
+
it 'implements endpoint' do
|
11
|
+
expect(client.endpoint).to_not be nil
|
12
|
+
end
|
13
|
+
it 'includes default http configuration' do
|
14
|
+
expect(client.user_agent).to eq "IEX Ruby Client/#{IEX::VERSION}"
|
15
|
+
end
|
16
|
+
it 'sets user-agent' do
|
17
|
+
expect(client.user_agent).to eq IEX::Api::Config.user_agent
|
18
|
+
expect(client.user_agent).to include IEX::VERSION
|
19
|
+
end
|
20
|
+
(IEX::Api::Config::ATTRIBUTES - [:logger]).each do |key|
|
21
|
+
it "sets #{key}" do
|
22
|
+
expect(client.send(key)).to eq IEX::Api::Config.send(key)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
context 'with custom settings' do
|
28
|
+
context '#initialize' do
|
29
|
+
IEX::Api::Config::ATTRIBUTES.each do |key|
|
30
|
+
context key.to_s do
|
31
|
+
let(:client) { described_class.new(key => 'custom') }
|
32
|
+
it "sets #{key}" do
|
33
|
+
expect(client.send(key)).to_not eq IEX::Api::Config.send(key)
|
34
|
+
expect(client.send(key)).to eq 'custom'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
context 'global config' do
|
41
|
+
let(:client) { described_class.new }
|
42
|
+
context 'user-agent' do
|
43
|
+
before do
|
44
|
+
IEX::Api.configure do |config|
|
45
|
+
config.user_agent = 'custom/user-agent'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
context '#initialize' do
|
49
|
+
it 'sets user-agent' do
|
50
|
+
expect(client.user_agent).to eq 'custom/user-agent'
|
51
|
+
end
|
52
|
+
it 'creates a connection with the custom user-agent' do
|
53
|
+
expect(client.send(:connection).headers).to include(
|
54
|
+
'Accept' => 'application/json; charset=utf-8',
|
55
|
+
'User-Agent' => 'custom/user-agent'
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
context 'proxy' do
|
61
|
+
before do
|
62
|
+
IEX::Api.configure do |config|
|
63
|
+
config.proxy = 'http://localhost:8080'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
context '#initialize' do
|
67
|
+
it 'sets proxy' do
|
68
|
+
expect(client.proxy).to eq 'http://localhost:8080'
|
69
|
+
end
|
70
|
+
it 'creates a connection with the proxy' do
|
71
|
+
expect(client.send(:connection).proxy.uri.to_s).to eq 'http://localhost:8080'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
context 'SSL options' do
|
76
|
+
before do
|
77
|
+
IEX::Api.configure do |config|
|
78
|
+
config.ca_path = '/ca_path'
|
79
|
+
config.ca_file = '/ca_file'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
context '#initialize' do
|
83
|
+
it 'sets ca_path and ca_file' do
|
84
|
+
expect(client.ca_path).to eq '/ca_path'
|
85
|
+
expect(client.ca_file).to eq '/ca_file'
|
86
|
+
end
|
87
|
+
it 'creates a connection with ssl options' do
|
88
|
+
ssl = client.send(:connection).ssl
|
89
|
+
expect(ssl.ca_path).to eq '/ca_path'
|
90
|
+
expect(ssl.ca_file).to eq '/ca_file'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
context 'logger option' do
|
95
|
+
let(:logger) { Logger.new(STDOUT) }
|
96
|
+
before do
|
97
|
+
IEX::Api.configure do |config|
|
98
|
+
config.logger = logger
|
99
|
+
end
|
100
|
+
end
|
101
|
+
context '#initialize' do
|
102
|
+
it 'sets logger' do
|
103
|
+
expect(client.logger).to eq logger
|
104
|
+
end
|
105
|
+
it 'creates a connection with a logger' do
|
106
|
+
expect(client.send(:connection).builder.handlers).to include ::Faraday::Response::Logger
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
context 'timeout options' do
|
111
|
+
before do
|
112
|
+
IEX::Api.configure do |config|
|
113
|
+
config.timeout = 10
|
114
|
+
config.open_timeout = 15
|
115
|
+
end
|
116
|
+
end
|
117
|
+
context '#initialize' do
|
118
|
+
it 'sets timeout and open_timeout' do
|
119
|
+
expect(client.timeout).to eq 10
|
120
|
+
expect(client.open_timeout).to eq 15
|
121
|
+
end
|
122
|
+
it 'creates a connection with timeout options' do
|
123
|
+
conn = client.send(:connection)
|
124
|
+
expect(conn.options.timeout).to eq 10
|
125
|
+
expect(conn.options.open_timeout).to eq 15
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
context 'without a token' do
|
130
|
+
let(:client) { described_class.new }
|
131
|
+
it 'results in an API key error', vcr: { cassette_name: 'client/access_denied' } do
|
132
|
+
expect do
|
133
|
+
client.get '/stock/msft/quote'
|
134
|
+
end.to raise_error IEX::Errors::PermissionDeniedError, /The API key provided is not valid./
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IEX::Api::Config do
|
4
|
+
before do
|
5
|
+
IEX::Api.config.reset!
|
6
|
+
end
|
7
|
+
describe '#defaults' do
|
8
|
+
it 'sets endpoint' do
|
9
|
+
expect(IEX::Api.config.endpoint).to eq 'https://cloud.iexapis.com/v1'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
describe '#configure' do
|
13
|
+
before do
|
14
|
+
IEX::Api.configure do |config|
|
15
|
+
config.endpoint = 'updated'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
it 'sets endpoint' do
|
19
|
+
expect(IEX::Api.config.endpoint).to eq 'updated'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,42 +1,44 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe IEX::Resources::Chart do
|
4
|
+
include_context 'client'
|
5
|
+
|
4
6
|
context 'known symbol', vcr: { cassette_name: 'chart/msft' } do
|
5
7
|
subject do
|
6
|
-
|
8
|
+
client.chart('MSFT')
|
7
9
|
end
|
8
10
|
let(:first) { subject.first }
|
9
11
|
let(:last) { subject.last }
|
10
12
|
it 'retrieves a default chart' do
|
11
|
-
expect(subject.count).to eq
|
13
|
+
expect(subject.count).to eq 23
|
12
14
|
expect(first).to be_a IEX::Resources::Chart::Default
|
13
|
-
expect(first.label).to eq '
|
14
|
-
expect(first.change_percent_s).to eq '
|
15
|
-
expect(first.close).to eq
|
16
|
-
expect(first.date).to eq Date.new(
|
17
|
-
expect(last.label).to eq '
|
15
|
+
expect(first.label).to eq 'Mar 6'
|
16
|
+
expect(first.change_percent_s).to eq '0.00%'
|
17
|
+
expect(first.close).to eq 111.75
|
18
|
+
expect(first.date).to eq Date.new(2019, 3, 6)
|
19
|
+
expect(last.label).to eq 'Apr 5'
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
23
|
context '1d', vcr: { cassette_name: 'chart/1d' } do
|
22
24
|
subject do
|
23
|
-
|
25
|
+
client.chart('MSFT', '1d')
|
24
26
|
end
|
25
27
|
let(:first) { subject.first }
|
26
28
|
let(:last) { subject.last }
|
27
29
|
it 'retrieves a 1 day chart' do
|
28
|
-
expect(subject.count).to eq
|
30
|
+
expect(subject.count).to eq 390
|
29
31
|
expect(first).to be_a IEX::Resources::Chart::OneDay
|
30
32
|
expect(first.label).to eq '09:30 AM'
|
31
|
-
expect(first.high).to eq
|
32
|
-
expect(first.low).to eq
|
33
|
+
expect(first.high).to eq 119.67
|
34
|
+
expect(first.low).to eq 119.43
|
33
35
|
expect(first.minute).to eq '09:30'
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
37
39
|
context 'with options', vcr: { cassette_name: 'chart/chartInterval' } do
|
38
40
|
subject do
|
39
|
-
|
41
|
+
client.chart('MSFT', '1d', chart_interval: 10)
|
40
42
|
end
|
41
43
|
let(:first) { subject.first }
|
42
44
|
it 'retrieves a 1 day chart with chartInterval applied' do
|
@@ -45,33 +47,33 @@ describe IEX::Resources::Chart do
|
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
|
-
context 'date', vcr: { cassette_name: 'chart/
|
50
|
+
context 'date', vcr: { cassette_name: 'chart/20190306' } do
|
49
51
|
subject do
|
50
|
-
|
52
|
+
client.chart('MSFT', Date.new(2019, 3, 6))
|
51
53
|
end
|
52
54
|
let(:first) { subject.first }
|
53
|
-
it 'retrieves a 1 day chart from
|
55
|
+
it 'retrieves a 1 day chart from 2019/3/6' do
|
54
56
|
expect(subject.count).to eq 390
|
55
57
|
expect(first).to be_a IEX::Resources::Chart::OneDay
|
56
|
-
expect(first.date).to eq Date.new(
|
58
|
+
expect(first.date).to eq Date.new(2019, 3, 6)
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
60
62
|
context 'dynamic 1m', vcr: { cassette_name: 'chart/dynamic/1m' } do
|
61
63
|
subject do
|
62
|
-
|
64
|
+
client.chart('MSFT', :dynamic)
|
63
65
|
end
|
64
66
|
let(:first) { subject.first }
|
65
67
|
it 'retrieves a 1m chart from' do
|
66
|
-
expect(subject.count).to eq
|
68
|
+
expect(subject.count).to eq 23
|
67
69
|
expect(first).to be_a IEX::Resources::Chart::Default
|
68
|
-
expect(first.date).to eq Date.new(
|
70
|
+
expect(first.date).to eq Date.new(2019, 3, 6)
|
69
71
|
end
|
70
72
|
end
|
71
73
|
|
72
74
|
context 'invalid symbol', vcr: { cassette_name: 'chart/invalid' } do
|
73
75
|
subject do
|
74
|
-
|
76
|
+
client.chart('INVALID')
|
75
77
|
end
|
76
78
|
it 'fails with SymbolNotFoundError' do
|
77
79
|
expect { subject }.to raise_error IEX::Errors::SymbolNotFoundError, 'Symbol INVALID Not Found'
|
@@ -80,7 +82,7 @@ describe IEX::Resources::Chart do
|
|
80
82
|
|
81
83
|
context 'with client error', vcr: { cassette_name: 'chart/bad_option' } do
|
82
84
|
subject do
|
83
|
-
|
85
|
+
client.chart('MSFT', '1d', chart_interval: 10, bad_option: 'option')
|
84
86
|
end
|
85
87
|
|
86
88
|
it 'fails with ClientError' do
|
@@ -1,25 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe IEX::Resources::Company do
|
4
|
+
include_context 'client'
|
5
|
+
|
4
6
|
context 'known symbol', vcr: { cassette_name: 'company/msft' } do
|
5
7
|
subject do
|
6
|
-
|
8
|
+
client.company('MSFT')
|
7
9
|
end
|
8
10
|
it 'retrieves company information' do
|
9
11
|
expect(subject.symbol).to eq 'MSFT'
|
10
12
|
expect(subject.ceo).to eq 'Satya Nadella'
|
11
|
-
expect(subject.company_name).to eq 'Microsoft
|
12
|
-
expect(subject.description).to include '
|
13
|
-
expect(subject.exchange).to eq '
|
14
|
-
expect(subject.industry).to eq '
|
13
|
+
expect(subject.company_name).to eq 'Microsoft Corp.'
|
14
|
+
expect(subject.description).to include 'Develops, manufactures and distributes software products'
|
15
|
+
expect(subject.exchange).to eq 'NASDAQ'
|
16
|
+
expect(subject.industry).to eq 'Packaged Software'
|
15
17
|
expect(subject.issue_type).to eq 'cs'
|
16
18
|
expect(subject.website).to eq 'http://www.microsoft.com'
|
17
|
-
expect(subject.sector).to eq 'Technology'
|
19
|
+
expect(subject.sector).to eq 'Technology Services'
|
20
|
+
expect(subject.employees).to eq 131_000
|
21
|
+
expect(subject.security_name).to eq 'Microsoft Corporation'
|
18
22
|
end
|
19
23
|
end
|
20
24
|
context 'invalid symbol', vcr: { cassette_name: 'company/invalid' } do
|
21
25
|
subject do
|
22
|
-
|
26
|
+
client.company('INVALID')
|
23
27
|
end
|
24
28
|
it 'fails with SymbolNotFoundError' do
|
25
29
|
expect { subject }.to raise_error IEX::Errors::SymbolNotFoundError, 'Symbol INVALID Not Found'
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IEX::Resources::Crypto do
|
4
|
+
include_context 'client'
|
5
|
+
|
6
|
+
context 'gets crypto information', vcr: { cassette_name: 'crypto/btcusdt' } do
|
7
|
+
subject do
|
8
|
+
client.crypto('BTCUSDT')
|
9
|
+
end
|
10
|
+
it 'retrieves real-time information' do
|
11
|
+
expect(subject.symbol).to eq 'BTCUSDT'
|
12
|
+
expect(subject.company_name).to eq 'Bitcoin USD'
|
13
|
+
expect(subject.primary_exchange).to eq 'crypto'
|
14
|
+
expect(subject.sector).to eq 'cryptocurrency'
|
15
|
+
expect(subject.calculation_price).to eq 'realtime'
|
16
|
+
expect(subject.open).to eq 3527.79
|
17
|
+
expect(subject.open_dollar).to eq '$3,527'
|
18
|
+
expect(subject.open_time).to eq 1_548_082_840_296
|
19
|
+
expect(subject.close).to eq 3522.05522498
|
20
|
+
expect(subject.close_dollar).to eq '$3,522'
|
21
|
+
expect(subject.close_time).to eq 1_548_169_240_296
|
22
|
+
expect(subject.high).to eq 3590.51
|
23
|
+
expect(subject.high_dollar).to eq '$3,590'
|
24
|
+
expect(subject.low).to eq 3434.85
|
25
|
+
expect(subject.low_dollar).to eq '$3,434'
|
26
|
+
expect(subject.latest_price).to eq 3563.22
|
27
|
+
expect(subject.latest_price_dollar).to eq '$3,563'
|
28
|
+
expect(subject.latest_source).to eq 'Real time price'
|
29
|
+
expect(subject.latest_time).to eq '10:00:40 AM'
|
30
|
+
expect(subject.latest_update).to eq 1_548_169_240_296
|
31
|
+
expect(subject.latest_volume).to eq 28_053.196533
|
32
|
+
expect(subject.latest_volume_dollar).to eq '$28,053'
|
33
|
+
expect(subject.iex_realtime_price).to eq nil
|
34
|
+
expect(subject.iex_realtime_size).to eq nil
|
35
|
+
expect(subject.iex_last_updated).to eq nil
|
36
|
+
expect(subject.delayed_price).to eq nil
|
37
|
+
expect(subject.delayed_price_time).to eq nil
|
38
|
+
expect(subject.extended_change).to eq nil
|
39
|
+
expect(subject.extended_change_percent).to eq nil
|
40
|
+
expect(subject.extended_price_time).to eq nil
|
41
|
+
expect(subject.previous_close).to eq 3527.79
|
42
|
+
expect(subject.previous_close_dollar).to eq '$3,527'
|
43
|
+
expect(subject.change).to eq 35.43
|
44
|
+
expect(subject.change_percent).to eq 0.01004
|
45
|
+
expect(subject.change_percent_s).to eq '+1.00%'
|
46
|
+
expect(subject.iex_market_percent).to eq nil
|
47
|
+
expect(subject.iex_volume).to eq nil
|
48
|
+
expect(subject.avg_total_volume).to eq nil
|
49
|
+
expect(subject.iex_bid_price).to eq nil
|
50
|
+
expect(subject.iex_bid_size).to eq nil
|
51
|
+
expect(subject.iex_ask_price).to eq nil
|
52
|
+
expect(subject.iex_ask_size).to eq nil
|
53
|
+
expect(subject.market_cap).to eq nil
|
54
|
+
expect(subject.pe_ratio).to eq nil
|
55
|
+
expect(subject.week52_high).to eq nil
|
56
|
+
expect(subject.week52_high_dollar).to eq nil
|
57
|
+
expect(subject.week52_low).to eq nil
|
58
|
+
expect(subject.week52_low_dollar).to eq nil
|
59
|
+
expect(subject.ytd_change).to eq nil
|
60
|
+
expect(subject.bid_price).to eq 3562.94
|
61
|
+
expect(subject.bid_size).to eq 0.061728
|
62
|
+
expect(subject.ask_price).to eq 3563.22
|
63
|
+
expect(subject.ask_size).to eq 0.134326
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -1,26 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe IEX::Resources::Dividends do
|
4
|
+
include_context 'client'
|
5
|
+
|
4
6
|
context 'known symbol' do
|
5
7
|
context 'with defaults', vcr: { cassette_name: 'dividends/msft' } do
|
6
8
|
subject do
|
7
|
-
|
9
|
+
client.dividends('MSFT', '6m')
|
8
10
|
end
|
9
11
|
let(:dividends) { subject.first }
|
10
12
|
it 'retrieves dividends' do
|
11
|
-
expect(dividends.
|
12
|
-
expect(dividends.
|
13
|
-
expect(dividends.
|
14
|
-
expect(dividends.
|
15
|
-
expect(dividends.
|
16
|
-
expect(dividends.
|
17
|
-
expect(dividends.
|
18
|
-
expect(dividends.
|
13
|
+
expect(dividends.ex_date).to eq '2019-05-15'
|
14
|
+
expect(dividends.payment_date).to eq '2019-06-13'
|
15
|
+
expect(dividends.record_date).to eq '2019-05-16'
|
16
|
+
expect(dividends.declared_date).to eq '2019-03-11'
|
17
|
+
expect(dividends.amount).to eq 0.46
|
18
|
+
expect(dividends.amount_dollar).to eq '$0.46'
|
19
|
+
expect(dividends.currency).to eq 'USD'
|
20
|
+
expect(dividends.description).to eq 'Microsoft Corp. Declares Quarterly Dividend of $0.46 Per Share'
|
21
|
+
expect(dividends.frequency).to eq 'Quarterly'
|
19
22
|
end
|
20
23
|
end
|
21
24
|
context 'without range', vcr: { cassette_name: 'dividends/msft_default_range' } do
|
22
25
|
subject do
|
23
|
-
|
26
|
+
client.dividends('MSFT')
|
24
27
|
end
|
25
28
|
it 'retrieves dividends when no range is passed' do
|
26
29
|
expect(subject.size).to eq 1
|
@@ -28,7 +31,7 @@ describe IEX::Resources::Dividends do
|
|
28
31
|
end
|
29
32
|
context 'invalid range', vcr: { cassette_name: 'dividends/msft_invalid_range' } do
|
30
33
|
subject do
|
31
|
-
|
34
|
+
client.dividends('MSFT', 'INVALID')
|
32
35
|
end
|
33
36
|
let(:dividends) { subject.first }
|
34
37
|
it 'retrieves dividends when invalid range is passed' do
|
@@ -37,16 +40,16 @@ describe IEX::Resources::Dividends do
|
|
37
40
|
end
|
38
41
|
context 'with range', vcr: { cassette_name: 'dividends/msft_1y' } do
|
39
42
|
subject do
|
40
|
-
|
43
|
+
client.dividends('MSFT', '1y')
|
41
44
|
end
|
42
45
|
it 'retrieves dividends with range of 1 year' do
|
43
|
-
expect(subject.size).to eq
|
46
|
+
expect(subject.size).to eq 5
|
44
47
|
end
|
45
48
|
end
|
46
49
|
end
|
47
50
|
context 'invalid symbol', vcr: { cassette_name: 'dividends/invalid' } do
|
48
51
|
subject do
|
49
|
-
|
52
|
+
client.dividends('INVALID', 'INVALID')
|
50
53
|
end
|
51
54
|
it 'fails with SymbolNotFoundError' do
|
52
55
|
expect { subject }.to raise_error IEX::Errors::SymbolNotFoundError, 'Symbol INVALID Not Found'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IEX::Resources::Earnings do
|
4
|
+
include_context 'client'
|
5
|
+
|
6
|
+
context 'known symbol' do
|
7
|
+
context 'with defaults', vcr: { cassette_name: 'earnings/msft' } do
|
8
|
+
subject do
|
9
|
+
client.earnings('MSFT')
|
10
|
+
end
|
11
|
+
let(:earnings) { subject.first }
|
12
|
+
it 'retrieves earnings' do
|
13
|
+
expect(subject.size).to eq 1
|
14
|
+
expect(earnings.actual_eps).to eq 1.1
|
15
|
+
expect(earnings.consensus_eps).to eq 1.09
|
16
|
+
expect(earnings.announce_time).to eq 'AMC'
|
17
|
+
expect(earnings.number_of_estimates).to eq 29
|
18
|
+
expect(earnings.eps_surprise_dollar).to eq 0.01
|
19
|
+
expect(earnings.eps_report_date).to eq '2019-01-30'
|
20
|
+
expect(earnings.fiscal_period).to eq 'Q4 2018'
|
21
|
+
expect(earnings.fiscal_end_date).to eq '2018-12-31'
|
22
|
+
expect(earnings.year_ago).to eq 0.96
|
23
|
+
expect(earnings.year_ago_change_percent).to eq 0.1458
|
24
|
+
expect(earnings.year_ago_change_percent_s).to eq '+14.58%'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
context 'invalid symbol', vcr: { cassette_name: 'earnings/invalid' } do
|
29
|
+
subject do
|
30
|
+
client.earnings('INVALID')
|
31
|
+
end
|
32
|
+
it 'fails with SymbolNotFoundError' do
|
33
|
+
expect { subject }.to raise_error IEX::Errors::SymbolNotFoundError, 'Symbol INVALID Not Found'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|