iex-ruby-client 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +1 -0
  3. data/.rubocop.yml +4 -1
  4. data/CHANGELOG.md +37 -7
  5. data/Dangerfile +2 -2
  6. data/Gemfile +2 -2
  7. data/README.md +159 -37
  8. data/iex-ruby-client.gemspec +3 -2
  9. data/lib/iex-ruby-client.rb +1 -0
  10. data/lib/iex/api.rb +3 -0
  11. data/lib/iex/api/client.rb +3 -0
  12. data/lib/iex/api/config.rb +2 -0
  13. data/lib/iex/cloud/connection.rb +21 -19
  14. data/lib/iex/cloud/request.rb +1 -1
  15. data/lib/iex/cloud/response.rb +1 -1
  16. data/lib/iex/endpoints/chart.rb +5 -6
  17. data/lib/iex/endpoints/company.rb +1 -1
  18. data/lib/iex/endpoints/crypto.rb +1 -1
  19. data/lib/iex/endpoints/dividends.rb +1 -1
  20. data/lib/iex/endpoints/earnings.rb +1 -1
  21. data/lib/iex/endpoints/income.rb +13 -0
  22. data/lib/iex/endpoints/key_stats.rb +1 -1
  23. data/lib/iex/endpoints/largest_trades.rb +1 -1
  24. data/lib/iex/endpoints/logo.rb +1 -1
  25. data/lib/iex/endpoints/news.rb +1 -1
  26. data/lib/iex/endpoints/ohlc.rb +2 -2
  27. data/lib/iex/endpoints/price.rb +1 -1
  28. data/lib/iex/endpoints/quote.rb +1 -1
  29. data/lib/iex/endpoints/ref_data.rb +22 -0
  30. data/lib/iex/endpoints/sectors.rb +1 -1
  31. data/lib/iex/endpoints/stock_market.rb +11 -0
  32. data/lib/iex/resources.rb +3 -0
  33. data/lib/iex/resources/chart.rb +9 -14
  34. data/lib/iex/resources/company.rb +1 -0
  35. data/lib/iex/resources/income.rb +36 -0
  36. data/lib/iex/resources/key_stats.rb +14 -2
  37. data/lib/iex/resources/quote.rb +15 -5
  38. data/lib/iex/resources/resource.rb +1 -1
  39. data/lib/iex/resources/symbol.rb +10 -0
  40. data/lib/iex/resources/symbols.rb +19 -0
  41. data/lib/iex/version.rb +1 -1
  42. data/spec/fixtures/iex/chart/1d.yml +440 -473
  43. data/spec/fixtures/iex/chart/20190306.yml +440 -473
  44. data/spec/fixtures/iex/chart/bad_option.yml +47 -81
  45. data/spec/fixtures/iex/chart/chartInterval.yml +89 -122
  46. data/spec/fixtures/iex/chart/dynamic/1m.yml +73 -107
  47. data/spec/fixtures/iex/chart/invalid.yml +47 -81
  48. data/spec/fixtures/iex/chart/msft.yml +74 -107
  49. data/spec/fixtures/iex/income/invalid.yml +49 -0
  50. data/spec/fixtures/iex/income/msft.yml +53 -0
  51. data/spec/fixtures/iex/income/nsrgy.yml +55 -0
  52. data/spec/fixtures/iex/key_stats/invalid.yml +7 -41
  53. data/spec/fixtures/iex/key_stats/msft.yml +11 -43
  54. data/spec/fixtures/iex/ref-data/isin.yml +57 -0
  55. data/spec/fixtures/iex/ref-data/isin_mapped.yml +57 -0
  56. data/spec/fixtures/iex/ref-data/symbols.yml +9002 -0
  57. data/spec/fixtures/iex/ref-data/wrong_isin_mapped.yml +57 -0
  58. data/spec/fixtures/iex/stock_market/list_mostactive.yml +76 -0
  59. data/spec/iex/client_spec.rb +6 -1
  60. data/spec/iex/endpoints/chart_spec.rb +7 -7
  61. data/spec/iex/endpoints/company_spec.rb +1 -0
  62. data/spec/iex/endpoints/income_spec.rb +68 -0
  63. data/spec/iex/endpoints/key_stats_spec.rb +42 -29
  64. data/spec/iex/endpoints/quote_spec.rb +2 -0
  65. data/spec/iex/endpoints/ref_data_spec.rb +66 -0
  66. data/spec/iex/endpoints/stock_market_spec.rb +14 -0
  67. data/spec/spec_helper.rb +1 -0
  68. data/spec/support/vcr.rb +3 -0
  69. metadata +41 -13
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://cloud.iexapis.com/v1/ref-data/isin?isin=WRONG12345&mapped=true&token=test-iex-api-publishable-token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json; charset=utf-8
12
+ Content-Type:
13
+ - application/json; charset=utf-8
14
+ User-Agent:
15
+ - IEX Ruby Client/1.1.3
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Fri, 10 Apr 2020 15:17:34 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Content-Length:
30
+ - '19'
31
+ Connection:
32
+ - keep-alive
33
+ Set-Cookie:
34
+ - ctoken=84910330e5ea4058969d0af364c32947; Max-Age=43200; Path=/; Expires=Sat,
35
+ 11 Apr 2020 03:17:34 GMT
36
+ Iexcloud-Messages-Used:
37
+ - '100'
38
+ Iexcloud-Premium-Messages-Used:
39
+ - '0'
40
+ X-Content-Type-Options:
41
+ - nosniff
42
+ Strict-Transport-Security:
43
+ - max-age=15768000
44
+ Access-Control-Allow-Origin:
45
+ - "*"
46
+ Access-Control-Allow-Credentials:
47
+ - 'true'
48
+ Access-Control-Allow-Methods:
49
+ - GET, OPTIONS
50
+ Access-Control-Allow-Headers:
51
+ - Origin, X-Requested-With, Content-Type, Accept
52
+ body:
53
+ encoding: UTF-8
54
+ string: '{"WRONG12345":null}'
55
+ http_version: null
56
+ recorded_at: Fri, 10 Apr 2020 15:17:34 GMT
57
+ recorded_with: VCR 5.1.0
@@ -0,0 +1,76 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://cloud.iexapis.com/v1/stock/market/list/mostactive?token=test-iex-api-publishable-token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json; charset=utf-8
12
+ Content-Type:
13
+ - application/json; charset=utf-8
14
+ User-Agent:
15
+ - IEX Ruby Client/1.1.2
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Wed, 04 Mar 2020 13:00:24 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Set-Cookie:
34
+ - ctoken=82c15565434a4dada8483b258390943b; Max-Age=43200; Path=/; Expires=Thu,
35
+ 05 Mar 2020 01:00:24 GMT
36
+ Iexcloud-Messages-Used:
37
+ - '20'
38
+ Iexcloud-Premium-Messages-Used:
39
+ - '0'
40
+ X-Content-Type-Options:
41
+ - nosniff
42
+ Strict-Transport-Security:
43
+ - max-age=15768000
44
+ Access-Control-Allow-Origin:
45
+ - "*"
46
+ Access-Control-Allow-Credentials:
47
+ - 'true'
48
+ Access-Control-Allow-Methods:
49
+ - GET, OPTIONS
50
+ Access-Control-Allow-Headers:
51
+ - Origin, X-Requested-With, Content-Type, Accept
52
+ body:
53
+ encoding: ASCII-8BIT
54
+ string: '[{"symbol":"AMD","companyName":"Advanced Micro Devices, Inc.","primaryExchange":"NASDAQ","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":46.75,"latestSource":"Close","latestTime":"March
55
+ 3, 2020","latestUpdate":1583269200736,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":47.46,"previousVolume":102324726,"change":-0.71,"changePercent":-0.01496,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":69781992,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":54681605000,"peRatio":152.73,"week52High":59.27,"week52Low":21.04,"ytdChange":-0.062822,"lastTradeTime":1583269200603,"isUSMarketOpen":false},{"symbol":"BAC","companyName":"Bank
56
+ of America Corp.","primaryExchange":"New York Stock Exchange","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":27.75,"latestSource":"Close","latestTime":"March
57
+ 3, 2020","latestUpdate":1583269208334,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":29.37,"previousVolume":147776301,"change":-1.62,"changePercent":-0.05516,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":59385616,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":242216707500,"peRatio":10.03,"week52High":35.72,"week52Low":26.21,"ytdChange":-0.27654,"lastTradeTime":1583269208300,"isUSMarketOpen":false},{"symbol":"INO","companyName":"Inovio
58
+ Pharmaceuticals, Inc.","primaryExchange":"NASDAQ","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":7.45,"latestSource":"Close","latestTime":"March
59
+ 3, 2020","latestUpdate":1583269200743,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":4.39,"previousVolume":16179954,"change":3.06,"changePercent":0.69704,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":18795754,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":755139450,"peRatio":-6.32,"week52High":7.48,"week52Low":1.92,"ytdChange":2.017912,"lastTradeTime":1583269200378,"isUSMarketOpen":false},{"symbol":"GE","companyName":"General
60
+ Electric Co.","primaryExchange":"New York Stock Exchange","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":10.88,"latestSource":"Close","latestTime":"March
61
+ 3, 2020","latestUpdate":1583269204858,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":11.21,"previousVolume":124802207,"change":-0.33,"changePercent":-0.02944,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":71758664,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":95093702400,"peRatio":143.16,"week52High":13.26,"week52Low":7.65,"ytdChange":-0.117453,"lastTradeTime":1583269204815,"isUSMarketOpen":false},{"symbol":"F","companyName":"Ford
62
+ Motor Co.","primaryExchange":"New York Stock Exchange","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":6.97,"latestSource":"Close","latestTime":"March
63
+ 3, 2020","latestUpdate":1583269470045,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":7.2,"previousVolume":96766032,"change":-0.23,"changePercent":-0.03194,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":79183546,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":27636398500,"peRatio":237.88,"week52High":10.56,"week52Low":6.67,"ytdChange":-0.29202500000000003,"lastTradeTime":1583269200123,"isUSMarketOpen":false},{"symbol":"AAPL","companyName":"Apple,
64
+ Inc.","primaryExchange":"NASDAQ","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":289.32,"latestSource":"Close","latestTime":"March
65
+ 3, 2020","latestUpdate":1583269200249,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":298.81,"previousVolume":85349339,"change":-9.49,"changePercent":-0.03176,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":41771302,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":1265913873600,"peRatio":22.68,"week52High":327.85,"week52Low":169.5,"ytdChange":-0.06848399999999999,"lastTradeTime":1583269200389,"isUSMarketOpen":false},{"symbol":"MSFT","companyName":"Microsoft
66
+ Corp.","primaryExchange":"NASDAQ","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":164.51,"latestSource":"Close","latestTime":"March
67
+ 3, 2020","latestUpdate":1583269200720,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":172.79,"previousVolume":71030810,"change":-8.28,"changePercent":-0.04792,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":43623452,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":1251271285500,"peRatio":28.37,"week52High":190.7,"week52Low":108.8,"ytdChange":-0.023700999999999996,"lastTradeTime":1583269200282,"isUSMarketOpen":false},{"symbol":"T","companyName":"AT&T,
68
+ Inc.","primaryExchange":"New York Stock Exchange","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":36.3,"latestSource":"Close","latestTime":"March
69
+ 3, 2020","latestUpdate":1583269431180,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":37.18,"previousVolume":68432790,"change":-0.88,"changePercent":-0.02367,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":39604055,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":260375544000,"peRatio":19.09,"week52High":39.7,"week52Low":29.67,"ytdChange":-0.089548,"lastTradeTime":1583269199998,"isUSMarketOpen":false},{"symbol":"XOM","companyName":"Exxon
70
+ Mobil Corp.","primaryExchange":"New York Stock Exchange","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":51.3,"latestSource":"Close","latestTime":"March
71
+ 3, 2020","latestUpdate":1583269428549,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":53.88,"previousVolume":38127634,"change":-2.58,"changePercent":-0.04788,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":24981447,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":217111347000,"peRatio":15.29,"week52High":83.49,"week52Low":48.01,"ytdChange":-0.324326,"lastTradeTime":1583269199431,"isUSMarketOpen":false},{"symbol":"INTC","companyName":"Intel
72
+ Corp.","primaryExchange":"NASDAQ","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":55.97,"latestSource":"Close","latestTime":"March
73
+ 3, 2020","latestUpdate":1583269200750,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":58.18,"previousVolume":43140304,"change":-2.21,"changePercent":-0.03799,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":28110407,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":239383690000,"peRatio":11.7,"week52High":69.29,"week52Low":42.86,"ytdChange":-0.118036,"lastTradeTime":1583269200602,"isUSMarketOpen":false}]'
74
+ http_version: null
75
+ recorded_at: Wed, 04 Mar 2020 13:00:24 GMT
76
+ recorded_with: VCR 5.1.0
@@ -17,6 +17,11 @@ describe IEX::Api::Client do
17
17
  expect(client.user_agent).to eq IEX::Api::Config.user_agent
18
18
  expect(client.user_agent).to include IEX::VERSION
19
19
  end
20
+ it 'caches the Faraday connection to allow persistent adapters' do
21
+ first = client.send(:connection)
22
+ second = client.send(:connection)
23
+ expect(first).to equal second
24
+ end
20
25
  (IEX::Api::Config::ATTRIBUTES - [:logger]).each do |key|
21
26
  it "sets #{key}" do
22
27
  expect(client.send(key)).to eq IEX::Api::Config.send(key)
@@ -130,7 +135,7 @@ describe IEX::Api::Client do
130
135
  let(:client) { described_class.new }
131
136
  it 'results in an API key error', vcr: { cassette_name: 'client/access_denied' } do
132
137
  expect do
133
- client.get '/stock/msft/quote'
138
+ client.get '/stock/msft/quote', token: client.publishable_token
134
139
  end.to raise_error IEX::Errors::PermissionDeniedError, /The API key provided is not valid./
135
140
  end
136
141
  end
@@ -12,11 +12,11 @@ describe IEX::Resources::Chart do
12
12
  it 'retrieves a default chart' do
13
13
  expect(subject.count).to eq 23
14
14
  expect(first).to be_a IEX::Resources::Chart::Default
15
- expect(first.label).to eq 'Mar 6'
15
+ expect(first.label).to eq 'Jul 10'
16
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'
17
+ expect(first.close).to eq 137.85
18
+ expect(first.date).to eq Date.new(2019, 7, 10)
19
+ expect(last.label).to eq 'Aug 9'
20
20
  end
21
21
  end
22
22
 
@@ -30,8 +30,8 @@ describe IEX::Resources::Chart do
30
30
  expect(subject.count).to eq 390
31
31
  expect(first).to be_a IEX::Resources::Chart::OneDay
32
32
  expect(first.label).to eq '09:30 AM'
33
- expect(first.high).to eq 119.67
34
- expect(first.low).to eq 119.43
33
+ expect(first.high).to eq 138.72
34
+ expect(first.low).to eq 138.5
35
35
  expect(first.minute).to eq '09:30'
36
36
  end
37
37
  end
@@ -67,7 +67,7 @@ describe IEX::Resources::Chart do
67
67
  it 'retrieves a 1m chart from' do
68
68
  expect(subject.count).to eq 23
69
69
  expect(first).to be_a IEX::Resources::Chart::Default
70
- expect(first.date).to eq Date.new(2019, 3, 6)
70
+ expect(first.date).to eq Date.new(2019, 7, 10)
71
71
  end
72
72
  end
73
73
 
@@ -19,6 +19,7 @@ describe IEX::Resources::Company do
19
19
  expect(subject.sector).to eq 'Technology Services'
20
20
  expect(subject.employees).to eq 131_000
21
21
  expect(subject.security_name).to eq 'Microsoft Corporation'
22
+ expect(subject.tags).to eq ['Technology Services', 'Packaged Software']
22
23
  end
23
24
  end
24
25
  context 'invalid symbol', vcr: { cassette_name: 'company/invalid' } do
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe IEX::Resources::Income do
6
+ include_context 'client'
7
+
8
+ context 'known symbol' do
9
+ context 'with defaults', vcr: { cassette_name: 'income/msft' } do
10
+ subject do
11
+ client.income('MSFT')
12
+ end
13
+ let(:income) { subject.first }
14
+
15
+ it 'retrieves income statement' do
16
+ expect(subject.size).to eq 1
17
+ expect(income.report_date).to eq '2019-03-31'
18
+ expect(income.total_revenue).to eq 30_505_000_000
19
+ expect(income.total_revenue_dollar).to eq '$30,505,000,000'
20
+ expect(income.cost_of_revenue).to eq 10_170_000_000
21
+ expect(income.cost_of_revenue_dollar).to eq '$10,170,000,000'
22
+ expect(income.gross_profit).to eq 20_335_000_000
23
+ expect(income.gross_profit_dollar).to eq '$20,335,000,000'
24
+ expect(income.research_and_development).to eq 4_316_000_000
25
+ expect(income.research_and_development_dollar).to eq '$4,316,000,000'
26
+ expect(income.selling_general_and_admin).to eq 5_744_000_000
27
+ expect(income.selling_general_and_admin_dollar).to eq '$5,744,000,000'
28
+ expect(income.operating_expense).to eq 20_230_000_000
29
+ expect(income.operating_expense_dollar).to eq '$20,230,000,000'
30
+ expect(income.operating_income).to eq 10_275_000_000
31
+ expect(income.operating_income_dollar).to eq '$10,275,000,000'
32
+ expect(income.other_income_expense_net).to eq 211_000_000
33
+ expect(income.other_income_expense_net_dollar).to eq '$211,000,000'
34
+ expect(income.ebit_dollar).to eq '$10,275,000,000'
35
+ expect(income.ebit).to eq 10_275_000_000
36
+ expect(income.interest_income).to eq 671_000_000
37
+ expect(income.interest_income_dollar).to eq '$671,000,000'
38
+ expect(income.pretax_income).to eq 10_486_000_000
39
+ expect(income.pretax_income_dollar).to eq '$10,486,000,000'
40
+ expect(income.income_tax).to eq 1_677_000_000
41
+ expect(income.income_tax_dollar).to eq '$1,677,000,000'
42
+ expect(income.minority_interest).to eq 0
43
+ expect(income.net_income).to eq 8_809_000_000
44
+ expect(income.net_income_dollar).to eq '$8,809,000,000'
45
+ expect(income.net_income_basic).to eq 8_809_000_000
46
+ expect(income.net_income_basic_dollar).to eq '$8,809,000,000'
47
+ end
48
+ end
49
+ end
50
+
51
+ context 'no result', vcr: { cassette_name: 'income/nsrgy' } do
52
+ subject do
53
+ client.income('nsrgy')
54
+ end
55
+ it 'returns empty array' do
56
+ expect(subject).to eq []
57
+ end
58
+ end
59
+
60
+ context 'invalid symbol', vcr: { cassette_name: 'income/invalid' } do
61
+ subject do
62
+ client.income('INVALID')
63
+ end
64
+ it 'fails with SymbolNotFoundError' do
65
+ expect { subject }.to raise_error IEX::Errors::SymbolNotFoundError, 'Symbol INVALID Not Found'
66
+ end
67
+ end
68
+ end
@@ -9,44 +9,57 @@ describe IEX::Resources::KeyStats do
9
9
  end
10
10
  it 'retrieves a keyStats' do
11
11
  expect(subject.company_name).to eq 'Microsoft Corp.'
12
- expect(subject.market_cap).to eq 915_754_985_600
13
- expect(subject.market_cap_dollars).to eq '$915,754,985,600'
12
+ expect(subject.market_cap).to eq 990_869_169_557
13
+ expect(subject.market_cap_dollar).to eq '$990,869,169,557'
14
+ expect(subject.employees).to eq 133_074
14
15
  end
15
16
 
16
17
  it 'weekly stats' do
17
- expect(subject.week_52_high).to eq 120.82
18
- expect(subject.week_52_high_dollar).to eq '$120.82'
19
- expect(subject.week_52_low).to eq 89.48
20
- expect(subject.week_52_low_dollar).to eq '$89.48'
21
- expect(subject.week_52_change_dollar).to eq '$0.29'
18
+ expect(subject.week_52_high).to eq 136.04
19
+ expect(subject.week_52_high_dollar).to eq '$136.04'
20
+ expect(subject.week_52_low).to eq 95.92
21
+ expect(subject.week_52_low_dollar).to eq '$95.92'
22
+ expect(subject.week_52_change).to eq 0.371641
23
+ expect(subject.week_52_change_dollar).to eq '$0.37'
22
24
  end
23
25
 
24
26
  it 'general stats' do
25
- expect(subject.dividend_yield).to eq 0.014745308310991957
26
- expect(subject.ex_dividend_date).to eq '2019-05-15'
27
- expect(subject.shares_outstanding).to eq 7_672_210_000
28
- expect(subject.float).to eq 7_541_169_096
29
- expect(subject.ttm_eps).to eq 4.35
30
- expect(subject.day_200_moving_avg).to eq 108.04
31
- expect(subject.day_50_moving_avg).to eq 111.56
27
+ expect(subject.ttm_dividend_rate).to eq 1.8
28
+ expect(subject.dividend_yield).to eq 0.014087248841960684
29
+ expect(subject.ex_dividend_date).to eq '2019-05-24'
30
+ expect(subject.shares_outstanding).to eq 7_849_945_172
31
+ expect(subject.float).to eq 7_694_414_092
32
+ expect(subject.ttm_eps).to eq 4.66
33
+ expect(subject.next_dividend_date).to eq '2019-05-21'
34
+ expect(subject.next_earnings_date).to eq '2019-07-29'
35
+ expect(subject.pe_ratio).to eq 29.47
36
+ expect(subject.beta).to eq 1.4135449089973444
37
+ expect(subject.day_200_moving_avg).to eq 112.43
38
+ expect(subject.day_50_moving_avg).to eq 121
32
39
  end
33
40
 
34
41
  it 'changes stats' do
35
- expect(subject.year_5_change_percent).to be 1.998995
36
- expect(subject.year_5_change_percent_s).to eq '+199.90%'
37
- expect(subject.year_2_change_percent).to eq 0.820622
38
- expect(subject.year_2_change_percent_s).to eq '+82.06%'
39
- expect(subject.year_1_change_percent).to eq 0.292055
40
- expect(subject.year_1_change_percent_s).to eq '+29.21%'
41
- expect(subject.ytd_change_percent).to eq 0.18038
42
- expect(subject.month_6_change_percent).to eq 0.064479
43
- expect(subject.month_6_change_percent_s).to eq '+6.45%'
44
- expect(subject.month_3_change_percent).to eq 0.169508
45
- expect(subject.month_3_change_percent_s).to eq '+16.95%'
46
- expect(subject.month_1_change_percent).to eq 0.068577
47
- expect(subject.month_1_change_percent_s).to eq '+6.86%'
48
- expect(subject.day_5_change_percent).to eq 0.01204
49
- expect(subject.day_5_change_percent_s).to eq '+1.20%'
42
+ expect(subject.avg_10_volume).to be 25_160_156.2
43
+ expect(subject.avg_30_volume).to be 23_123_700.13
44
+ expect(subject.max_change_percent).to eq 4.355607
45
+ expect(subject.year_5_change_percent).to be 2.32987
46
+ expect(subject.year_5_change_percent_s).to eq '+232.99%'
47
+ expect(subject.year_2_change_percent).to eq 0.84983
48
+ expect(subject.year_2_change_percent_s).to eq '+84.98%'
49
+ expect(subject.year_1_change_percent).to eq 0.383503
50
+ expect(subject.year_1_change_percent_s).to eq '+38.35%'
51
+ expect(subject.ytd_change_percent).to eq 0.270151
52
+ expect(subject.ytd_change_percent_s).to eq '+27.02%'
53
+ expect(subject.month_6_change_percent).to eq 0.208977
54
+ expect(subject.month_6_change_percent_s).to eq '+20.90%'
55
+ expect(subject.month_3_change_percent).to eq 0.212188
56
+ expect(subject.month_3_change_percent_s).to eq '+21.22%'
57
+ expect(subject.month_1_change_percent).to eq 0.076335
58
+ expect(subject.month_1_change_percent_s).to eq '+7.63%'
59
+ expect(subject.day_5_change_percent).to eq(-0.010013)
60
+ expect(subject.day_5_change_percent_s).to eq '-1.00%'
61
+ expect(subject.day_30_change_percent).to eq 0.089589
62
+ expect(subject.day_30_change_percent_s).to eq '+8.96%'
50
63
  end
51
64
  end
52
65
 
@@ -18,6 +18,8 @@ describe IEX::Resources::Quote do
18
18
  expect(subject.week_52_low).to eq 87.73
19
19
  expect(subject.change_percent).to eq(-0.00508)
20
20
  expect(subject.change_percent_s).to eq '-0.51%'
21
+ expect(subject.extended_change_percent).to eq(-0.00008)
22
+ expect(subject.extended_change_percent_s).to eq '-0.01%'
21
23
  end
22
24
  it 'coerces times' do
23
25
  expect(subject.latest_update).to eq 1_554_408_000_193
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe IEX::Api::Client do
4
+ include_context 'client'
5
+
6
+ describe '#ref_data_isin', vcr: { cassette_name: 'ref-data/isin' } do
7
+ context 'without options' do
8
+ subject { client.ref_data_isin(['US0378331005']) }
9
+
10
+ it 'converts ISIN to IEX Cloud symbols' do
11
+ expect(subject.count).to eq(2)
12
+ expect(subject.first).to eq('exchange' => 'NAS', 'iex_id' => 'IEX_4D48333344362D52', 'region' => 'US', 'symbol' => 'AAPL')
13
+ expect(subject.last).to eq('exchange' => 'ETR', 'iex_id' => 'IEX_464D46474C312D52', 'region' => 'DE', 'symbol' => 'APC-GY')
14
+ end
15
+ end
16
+
17
+ context 'with mapped option', vcr: { cassette_name: 'ref-data/isin_mapped' } do
18
+ subject { client.ref_data_isin(%w[US0378331005 US5949181045], mapped: true) }
19
+
20
+ it 'converts ISINs to IEX Cloud symbols mapped by ISIN' do
21
+ expect(subject.keys).to contain_exactly('US0378331005', 'US5949181045')
22
+
23
+ expect(subject['US0378331005'].first).to eq('exchange' => 'NAS', 'iex_id' => 'IEX_4D48333344362D52', 'region' => 'US', 'symbol' => 'AAPL')
24
+ expect(subject['US0378331005'].last).to eq('exchange' => 'ETR', 'iex_id' => 'IEX_464D46474C312D52', 'region' => 'DE', 'symbol' => 'APC-GY')
25
+
26
+ expect(subject['US5949181045'][0]).to eq('exchange' => 'NAS', 'iex_id' => 'IEX_5038523343322D52', 'region' => 'US', 'symbol' => 'MSFT')
27
+ expect(subject['US5949181045'][1]).to eq('exchange' => 'ETR', 'iex_id' => 'IEX_4C42583859482D52', 'region' => 'DE', 'symbol' => 'MSF-GY')
28
+ expect(subject['US5949181045'][2]).to eq('exchange' => 'BRU', 'iex_id' => 'IEX_5833345950432D52', 'region' => 'BE', 'symbol' => 'MSF-BB')
29
+ end
30
+
31
+ context 'with wrong ISIN', vcr: { cassette_name: 'ref-data/wrong_isin_mapped' } do
32
+ subject { client.ref_data_isin(%w[WRONG12345], mapped: true) }
33
+
34
+ it 'returns nil value for given ISIN' do
35
+ expect(subject).to eq('WRONG12345' => nil)
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ describe '#ref_data_symbols', vcr: { cassette_name: 'ref-data/symbols' } do
42
+ subject { client.ref_data_symbols }
43
+
44
+ it 'retrieves all symbols' do
45
+ expect(subject.count).to eq 8808
46
+ end
47
+
48
+ context 'first symbol' do
49
+ subject { client.ref_data_symbols.first }
50
+ it 'retrieves a symbol data' do
51
+ expect(subject.symbol).to eq 'A'
52
+ expect(subject.exchange).to eq 'NYS'
53
+ expect(subject.name).to eq 'Agilent Technologies Inc.'
54
+ expect(subject.date).to eq Date.parse('2020-04-30')
55
+ expect(subject.enabled).to eq true
56
+ expect(subject.enabled?).to eq true
57
+ expect(subject.type).to eq 'cs'
58
+ expect(subject.region).to eq 'US'
59
+ expect(subject.currency).to eq 'USD'
60
+ expect(subject.iex_id).to eq 'IEX_46574843354B2D52'
61
+ expect(subject.figi).to eq 'BBG000C2V3D6'
62
+ expect(subject.cik).to eq '1090872'
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe IEX::Endpoints::StockMarket do
4
+ include_context 'client'
5
+
6
+ describe '#stock_market_list', vcr: { cassette_name: 'stock_market/list_mostactive' } do
7
+ subject { client.stock_market_list(:mostactive) }
8
+
9
+ it 'retrieves a list of quotes' do
10
+ expect(subject).to all(be_a(IEX::Resources::Quote))
11
+ expect(subject.map(&:symbol)).to match_array(%w[AAPL AMD BAC F GE INO INTC MSFT T XOM])
12
+ end
13
+ end
14
+ end