iex-ruby-client 1.4.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/danger.yml +20 -0
  3. data/.github/workflows/rubocop.yml +14 -0
  4. data/.github/workflows/test.yml +25 -0
  5. data/.gitignore +2 -0
  6. data/.rubocop.yml +1 -0
  7. data/.rubocop_todo.yml +8 -1
  8. data/CHANGELOG.md +14 -0
  9. data/CONTRIBUTING.md +1 -1
  10. data/Gemfile.danger +6 -0
  11. data/README.md +53 -16
  12. data/RELEASING.md +1 -1
  13. data/UPGRADING.md +23 -0
  14. data/iex-ruby-client.gemspec +3 -3
  15. data/lib/iex/api/client.rb +2 -0
  16. data/lib/iex/api/config/client.rb +2 -2
  17. data/lib/iex/api.rb +2 -0
  18. data/lib/iex/endpoints/fx.rb +13 -0
  19. data/lib/iex/endpoints/historial_prices.rb +2 -2
  20. data/lib/iex/endpoints/key_stat.rb +14 -0
  21. data/lib/iex/endpoints/ref_data.rb +5 -0
  22. data/lib/iex/errors/invalid_symbols_list.rb +14 -0
  23. data/lib/iex/errors/stat_not_found_error.rb +13 -0
  24. data/lib/iex/errors.rb +3 -1
  25. data/lib/iex/resources/currency_rate.rb +9 -0
  26. data/lib/iex/resources/resource.rb +5 -1
  27. data/lib/iex/resources/symbols.rb +5 -0
  28. data/lib/iex/resources.rb +1 -0
  29. data/lib/iex/version.rb +1 -1
  30. data/lib/iex-ruby-client.rb +1 -1
  31. data/script/console +9 -0
  32. data/spec/fixtures/iex/fx/invalid.yml +83 -0
  33. data/spec/fixtures/iex/fx/latest.yml +85 -0
  34. data/spec/fixtures/iex/fx/latest_one_symbol.yml +85 -0
  35. data/spec/fixtures/iex/key_stat/individual.yml +60 -0
  36. data/spec/fixtures/iex/key_stat/invalid_stat.yml +60 -0
  37. data/spec/fixtures/iex/key_stat/invalid_symbol.yml +50 -0
  38. data/spec/fixtures/iex/ref-data/exchange_symbols.yml +1 -1869
  39. data/spec/fixtures/iex/ref-data/region_symbols.yml +58 -0
  40. data/spec/iex/config/client_spec.rb +9 -3
  41. data/spec/iex/endpoints/fx_spec.rb +48 -0
  42. data/spec/iex/endpoints/key_stat_spec.rb +43 -0
  43. data/spec/iex/endpoints/ref_data_spec.rb +38 -8
  44. data/spec/support/client.rb +2 -0
  45. metadata +43 -16
  46. data/.travis.yml +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd85bc6a798e1c37eb803200aed631db1d1ff3fb6090714cceb01bb5d12c6c9f
4
- data.tar.gz: 0e483fa9cf10d511714de9563034309c463278931628d077c580a33bbdbf32d0
3
+ metadata.gz: a15ce3455468f791bbe21989defd92328cb979d2f803ee94de76069c798e9354
4
+ data.tar.gz: eceab7355f2c4e291004a138f9a39fb5001b4b6e95bea5fb5ceb45babee65ed0
5
5
  SHA512:
6
- metadata.gz: fe22b477b65f4ade43d1c0f9b44c07dc99664744f4d8fc0081aec8b29053e54c06d3c290e47a27a37c8452c81557f5d2c371d39e936ecd19d5ac0dbd68cd2124
7
- data.tar.gz: 14b3664d77a34096534dc9c46fadfa8f7056c7d8bfe82bd5264ee390817363619ccc7de809e1bd8c80e9d7d5cce04e8e5d33b1f8ab8d88f86cf81d1f40e59027
6
+ metadata.gz: 967562f47076ba6c8f3a4a4f8c9ac5c414570c3c9b90cf661d13e2eb8ab970913efb810268ecdd379ad6f2f1101ac9b7d00acb81a2b4dd5ec03ba469f1b84886
7
+ data.tar.gz: a889e0b0504c02a9d2a21b12555ae496c7a402606d129848faed9139ba225b4e88a242eed80d0ab6fe92d65975562c100187cf476152079d04c1bd7616d1b03e
@@ -0,0 +1,20 @@
1
+ name: PR Linter
2
+ on: [pull_request]
3
+ jobs:
4
+ danger:
5
+ runs-on: ubuntu-latest
6
+ env:
7
+ BUNDLE_GEMFILE: ${{ github.workspace }}/Gemfile.danger
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ with:
11
+ fetch-depth: 0
12
+ - name: Set up Ruby
13
+ uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.7
16
+ bundler-cache: true
17
+ - run: |
18
+ # the personal token is public, this is ok, base64 encode to avoid tripping Github
19
+ TOKEN=$(echo -n NWY1ZmM5MzEyMzNlYWY4OTZiOGU3MmI3MWQ3Mzk0MzgxMWE4OGVmYwo= | base64 --decode)
20
+ DANGER_GITHUB_API_TOKEN=$TOKEN bundle exec danger --verbose
@@ -0,0 +1,14 @@
1
+ name: Rubocop
2
+ on: [push, pull_request]
3
+ jobs:
4
+ lint:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - uses: actions/checkout@v2
8
+ - name: Set up Ruby
9
+ uses: ruby/setup-ruby@v1
10
+ with:
11
+ ruby-version: 2.7
12
+ bundler-cache: true
13
+ - name: Run Rubocop
14
+ run: bundle exec rubocop
@@ -0,0 +1,25 @@
1
+ name: Tests
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ strategy:
7
+ matrix:
8
+ entry:
9
+ - { ruby: "2.7" }
10
+ - { ruby: "3.0" }
11
+ - { ruby: "3.1" }
12
+ - { ruby: ruby-head, ignore: true }
13
+ - { ruby: jruby-head, ignore: true }
14
+ name: test (ruby=${{ matrix.entry.ruby }})
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Install Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.entry.ruby }}
21
+ - name: Run Tests
22
+ continue-on-error: ${{ matrix.entry.ignore || false }}
23
+ run: |
24
+ bundle install
25
+ bundle exec rspec
data/.gitignore CHANGED
@@ -4,3 +4,5 @@ Gemfile.lock
4
4
  .DS_Store
5
5
  .bundle
6
6
  .idea
7
+ .irbrc
8
+ .tool-versions
data/.rubocop.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  AllCops:
2
2
  Exclude:
3
3
  - vendor/**/*
4
+ TargetRubyVersion: 2.4
4
5
 
5
6
  Style/FrozenStringLiteralComment:
6
7
  Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-04-19 14:36:19 -0400 using RuboCop version 0.67.2.
3
+ # on 2022-07-21 13:04:05 -0500 using RuboCop version 0.75.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
@@ -11,3 +11,10 @@
11
11
  Style/AsciiComments:
12
12
  Exclude:
13
13
  - 'lib/iex/resources/quote.rb'
14
+
15
+ # Offense count: 2
16
+ # Configuration parameters: EnforcedStyle.
17
+ # SupportedStyles: annotated, template, unannotated
18
+ Style/FormatStringToken:
19
+ Exclude:
20
+ - 'lib/iex/resources/resource.rb'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ### 2.0.0 (2022/07/24)
2
+ * [#111](https://github.com/dblock/iex-ruby-client/pull/111): Added support for fetching symbols for a region - [@mathu97](https://github.com/mathu97).
3
+ * [#111](https://github.com/dblock/iex-ruby-client/pull/111): Added `Symbols#exchange_suffix`, `exchange_name`, `exchange_segment`, `exchange_segment_name`, and `lei` - [@mathu97](https://github.com/mathu97).
4
+ * [#113](https://github.com/dblock/iex-ruby-client/pull/113): Explicitly require Ruby >= 2.4 - [@agrberg](https://github.com/agrberg).
5
+ * [#113](https://github.com/dblock/iex-ruby-client/pull/113): Remove default SSL options for `ca_file` and `ca_path` - [@agrberg](https://github.com/agrberg).
6
+
7
+ ### 1.6.0 (2021/10/17)
8
+ * [#110](https://github.com/dblock/iex-ruby-client/pull/110): Drop `money_helper` dependency and utilize `money` gem directly - [@agrberg](https://github.com/agrberg).
9
+
10
+ ### 1.5.0 (2021/08/15)
11
+ * [#105](https://github.com/dblock/iex-ruby-client/pull/105): Added support for fetching latest foreign exchange rates - [@mathu97](https://github.com/mathu97).
12
+ * [#106](https://github.com/dblock/iex-ruby-client/pull/106): Added support for fetching a single key stat with `key_stat(symbol, stat)` endpoint - [@agrberg](https://github.com/agrberg).
13
+ * [#107](https://github.com/dblock/iex-ruby-client/pull/107): Added `./script/console` for ease of local development - [@agrberg](https://github.com/agrberg).
14
+
1
15
  ### 1.4.1 (2021/05/15)
2
16
  * [#103](https://github.com/dblock/iex-ruby-client/pull/103): Added support for fetching symbols for an exchange - [@mathu97](https://github.com/mathu97).
3
17
  * [#99](https://github.com/dblock/iex-ruby-client/pull/99): Added `image` and `paywalled` to news - [@reddavis](https://github.com/reddavis).
data/CONTRIBUTING.md CHANGED
@@ -114,7 +114,7 @@ git push origin my-feature-branch -f
114
114
 
115
115
  ### Check on Your Pull Request
116
116
 
117
- Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
117
+ Go back to your pull request after a few minutes and see whether it passed muster with GitHub Actions. Everything should look green, otherwise fix issues and amend your commit as described above.
118
118
 
119
119
  ### Be Patient
120
120
 
data/Gemfile.danger ADDED
@@ -0,0 +1,6 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'danger-changelog', '~> 0.6.0', require: false
5
+ gem 'danger-toc', '~> 0.2.0', require: false
6
+ end
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # IEX Finance API
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/iex-ruby-client.svg)](https://badge.fury.io/rb/iex-ruby-client)
4
- [![Build Status](https://travis-ci.org/dblock/iex-ruby-client.svg?branch=master)](https://travis-ci.org/dblock/iex-ruby-client)
4
+ [![Build Status](https://github.com/dblock/iex-ruby-client/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/dblock/iex-ruby-client/actions/workflows/test.yml)
5
5
 
6
6
  A Ruby client for the [The IEX Cloud API](https://iexcloud.io/docs/api/).
7
7
 
@@ -33,6 +33,8 @@ A Ruby client for the [The IEX Cloud API](https://iexcloud.io/docs/api/).
33
33
  - [ISIN Mapping](#isin-mapping)
34
34
  - [Get Symbols](#get-symbols)
35
35
  - [Get Symbols for an Exchange](#get-symbols-for-an-exchange)
36
+ - [Get Symbols for a Region](#get-symbols-for-a-region)
37
+ - [Get Latest Foreign Exchange Rates](#get-latest-foreign-exchange-rates)
36
38
  - [Get List](#get-list)
37
39
  - [Other Requests](#other-requests)
38
40
  - [Configuration](#configuration)
@@ -157,23 +159,23 @@ NOTE: If you use the `date` value for the `range` parameter:
157
159
  This is a complicated endpoint as there is a lot of granularity over the time period of data returned. See below for a variety of ways to request data, NOTE: this is _NOT_ as exhaustive list.
158
160
 
159
161
  ```ruby
160
- historial_prices = client.historical_prices('MSFT') # One month of data
161
- historial_prices = client.historical_prices('MSFT', {range: 'max'}) # All data up to 15 years
162
- historial_prices = client.historical_prices('MSFT', {range: 'ytd'}) # Year to date data
163
- historial_prices = client.historical_prices('MSFT', {range: '5y'}) # 5 years of data
164
- historial_prices = client.historical_prices('MSFT', {range: '6m'}) # 6 months of data
165
- historial_prices = client.historical_prices('MSFT', {range: '5d'}) # 5 days of data
166
- historial_prices = client.historical_prices('MSFT', {range: 'date', date: '20200930', chartByDay: 'true'}) # One day of data
167
- historial_prices = client.historical_prices('MSFT', {range: 'date', date: Date.parse('2020-09-30'), chartByDay: 'true'}) # One day of data
162
+ historical_prices = client.historical_prices('MSFT') # One month of data
163
+ historical_prices = client.historical_prices('MSFT', {range: 'max'}) # All data up to 15 years
164
+ historical_prices = client.historical_prices('MSFT', {range: 'ytd'}) # Year to date data
165
+ historical_prices = client.historical_prices('MSFT', {range: '5y'}) # 5 years of data
166
+ historical_prices = client.historical_prices('MSFT', {range: '6m'}) # 6 months of data
167
+ historical_prices = client.historical_prices('MSFT', {range: '5d'}) # 5 days of data
168
+ historical_prices = client.historical_prices('MSFT', {range: 'date', date: '20200930', chartByDay: 'true'}) # One day of data
169
+ historical_prices = client.historical_prices('MSFT', {range: 'date', date: Date.parse('2020-09-30'), chartByDay: 'true'}) # One day of data
168
170
  ...
169
171
  ```
170
172
 
171
173
  Once you have the data over the preferred time period, you can access the following fields
172
174
 
173
175
  ```ruby
174
- historial_prices = client.historical_prices('MSFT') # One month of data
176
+ historical_prices = client.historical_prices('MSFT') # One month of data
175
177
 
176
- historial_price = historial_prices.first
178
+ historical_price = historical_prices.first
177
179
  historical_price.date # 2020-10-07
178
180
  historical_price.open #207.06
179
181
  historical_price.open_dollar # '$207.06'
@@ -322,6 +324,12 @@ key_stats.pe_ratio # 29.47
322
324
  key_stats.beta # 1.4135449089973444
323
325
  ```
324
326
 
327
+ You can also fetch a single stat for a symbol. **Note** that IEX uses `lowerCamelCase` for the names of the stats.
328
+
329
+ ```ruby
330
+ client.key_stat('VTI', 'dividendYield') # 0.01271760965303361
331
+ ```
332
+
325
333
  See [#key-stats](https://iexcloud.io/docs/api/#key-stats) for detailed documentation or [key_stats.rb](lib/iex/resources/key_stats.rb) for returned fields.
326
334
 
327
335
  ### Get Advanced Stats
@@ -555,7 +563,7 @@ See [#ISIN Mapping](https://iexcloud.io/docs/api/#isin-mapping) for detailed doc
555
563
 
556
564
  ### Get Symbols
557
565
 
558
- Returns an array of symbols
566
+ Returns an array of symbols.
559
567
 
560
568
  ```ruby
561
569
  symbols = client.ref_data_symbols()
@@ -571,19 +579,48 @@ See [#symbols](https://iexcloud.io/docs/api/#symbols) for detailed documentation
571
579
 
572
580
  ### Get Symbols for an Exchange
573
581
 
574
- Returns an array of symbols for a given exchange
582
+ Returns an array of symbols for an exchange identified by a market identifier code.
575
583
 
576
584
  ```ruby
577
- symbols = client.ref_data_symbols_for_exchange('TSX')
585
+ symbols = client.ref_data_symbols_for_exchange('XTSE')
578
586
 
579
587
  symbol = symbols.first
580
- symbol.exchange # TSX
588
+ symbol.exchange # XTSE
581
589
  symbol.iex_id # IEX_4656374258322D52
582
590
  symbol.region # CA
583
591
  symbol.symbol # A-CV
584
592
  ```
585
593
 
586
- See [#international-symbols](https://iexcloud.io/docs/api/#international-symbols).
594
+ See [#international-symbols](https://iexcloud.io/docs/api/#international-symbols) for returned fields.
595
+
596
+ ### Get Symbols for a Region
597
+
598
+ Returns an array of symbols for a region.
599
+
600
+ ```ruby
601
+ symbols = client.ref_data_symbols_for_region('ca')
602
+
603
+ symbol = symbols.first
604
+ symbol.exchange # XTSE
605
+ symbol.iex_id # IEX_4656374258322D53
606
+ symbol.region # CA
607
+ symbol.symbol # A-CT
608
+ ```
609
+
610
+ ### Get Latest Foreign Exchange Rates
611
+
612
+ Returns an array of foreign exchange rates for a given list of symbols.
613
+
614
+ ```ruby
615
+ rates = client.fx_latest(['USDCAD', 'USDGBP', 'USDJPY'])
616
+
617
+ rate = rates.first
618
+ rate.symbol # USDCAD
619
+ rate.rate # 1.25674
620
+ rate.timestamp # <Date: 2021-07-23 ((2459419j,0s,0n),+0s,2299161j)>
621
+ ```
622
+
623
+ See [#latest-currency-rates](https://iexcloud.io/docs/api/#latest-currency-rates) for returned fields.
587
624
 
588
625
  ### Get List
589
626
 
data/RELEASING.md CHANGED
@@ -11,7 +11,7 @@ bundle install
11
11
  rake
12
12
  ```
13
13
 
14
- Check that the last build succeeded in [Travis CI](https://travis-ci.org/dblock/iex-ruby-client) for all supported platforms.
14
+ Check that the last build succeeded in [GitHub Actions](https://github.com/dblock/iex-ruby-client/actions/workflows/test.yml) for all supported platforms.
15
15
 
16
16
  Change "Next" in [CHANGELOG.md](CHANGELOG.md) to the current date.
17
17
 
data/UPGRADING.md CHANGED
@@ -1,6 +1,29 @@
1
1
  Upgrading iex-ruby-client
2
2
  =========================
3
3
 
4
+ ### Upgrading to >= 2.0.0
5
+
6
+ [#113](https://github.com/dblock/iex-ruby-client/pull/113) Minimum Ruby version is 2.4
7
+
8
+ [#113](https://github.com/dblock/iex-ruby-client/pull/113) Removes default values for Faraday's SSL settings `ca_file` and `ca_path`.
9
+
10
+ If you previously relied on `OpenSSL::X509::DEFAULT_CERT_FILE` or `OpenSSL::X509::DEFAULT_CERT_DIR` to set these values you must now do so explicitly. E.g.:
11
+
12
+ ```ruby
13
+ IEX::Api.configure do |config|
14
+ config.ca_file = OpenSSL::X509::DEFAULT_CERT_FILE
15
+ config.ca_path = OpenSSL::X509::DEFAULT_CERT_DIR
16
+ end
17
+ ```
18
+
19
+ ### Upgrading to >= 1.6.0
20
+
21
+ [#110](https://github.com/dblock/iex-ruby-client/pull/110) drops the dependency on `money_helper` in favor of using the `money` library directly.
22
+
23
+ Previously the `money_helper` library set `Money.locale_backend = :currency` globally. The default is `I18n` which looks up the thousands separator and decimal marker. Depending on your project you may need to set this value if you use `Money#format` without the `thousands_separator` or `decimal_mark` options. You are less likely to require this in a Rails project.
24
+
25
+ This represents a change in the `money` library's method of handling defaults and is similar to the deprecation warning the library provides until you set `Money.rounding_mode=`.
26
+
4
27
  ### Upgrading to >= 1.0.0
5
28
 
6
29
  On June 1, 2019, IEX API has been sunset for all non-IEX data. IEX Cloud, a non-Exchange platform, continues to provide access to third-party data sources and requires a token. When upgrading to 1.0.0, create an account and get a `publishable token` from [IEX Cloud Console](https://iexcloud.io).
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.email = 'dblock@dblock.org'
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.required_rubygems_version = '>= 1.3.6'
12
- s.required_ruby_version = '>= 2.3.0'
12
+ s.required_ruby_version = '>= 2.4.0'
13
13
  s.files = `git ls-files`.split("\n")
14
14
  s.test_files = `git ls-files -- spec/*`.split("\n")
15
15
  s.require_paths = ['lib']
@@ -19,10 +19,10 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency 'faraday', '>= 0.17'
20
20
  s.add_dependency 'faraday_middleware'
21
21
  s.add_dependency 'hashie'
22
- s.add_dependency 'money_helper'
22
+ s.add_dependency 'money', '~> 6.0'
23
23
  s.add_development_dependency 'rake', '~> 10'
24
24
  s.add_development_dependency 'rspec'
25
- s.add_development_dependency 'rubocop', '0.72.0'
25
+ s.add_development_dependency 'rubocop', '0.75.0'
26
26
  s.add_development_dependency 'vcr'
27
27
  s.add_development_dependency 'webmock'
28
28
  end
@@ -12,8 +12,10 @@ module IEX
12
12
  include Endpoints::Crypto
13
13
  include Endpoints::Dividends
14
14
  include Endpoints::Earnings
15
+ include Endpoints::FX
15
16
  include Endpoints::HistoricalPrices
16
17
  include Endpoints::Income
18
+ include Endpoints::KeyStat
17
19
  include Endpoints::KeyStats
18
20
  include Endpoints::LargestTrades
19
21
  include Endpoints::Logo
@@ -21,13 +21,13 @@ module IEX
21
21
  attr_accessor(*ATTRIBUTES)
22
22
 
23
23
  def reset!
24
- self.ca_file = defined?(OpenSSL) ? OpenSSL::X509::DEFAULT_CERT_FILE : nil
25
- self.ca_path = defined?(OpenSSL) ? OpenSSL::X509::DEFAULT_CERT_DIR : nil
26
24
  self.endpoint = 'https://cloud.iexapis.com/v1'
27
25
  self.publishable_token = ENV['IEX_API_PUBLISHABLE_TOKEN']
28
26
  self.secret_token = ENV['IEX_API_SECRET_TOKEN']
29
27
  self.user_agent = "IEX Ruby Client/#{IEX::VERSION}"
30
28
 
29
+ self.ca_file = nil
30
+ self.ca_path = nil
31
31
  self.open_timeout = nil
32
32
  self.proxy = nil
33
33
  self.referer = nil
data/lib/iex/api.rb CHANGED
@@ -5,10 +5,12 @@ require_relative 'endpoints/chart'
5
5
  require_relative 'endpoints/company'
6
6
  require_relative 'endpoints/dividends'
7
7
  require_relative 'endpoints/earnings'
8
+ require_relative 'endpoints/fx'
8
9
  require_relative 'endpoints/historial_prices'
9
10
  require_relative 'endpoints/income'
10
11
  require_relative 'endpoints/largest_trades'
11
12
  require_relative 'endpoints/logo'
13
+ require_relative 'endpoints/key_stat'
12
14
  require_relative 'endpoints/key_stats'
13
15
  require_relative 'endpoints/news'
14
16
  require_relative 'endpoints/ohlc'
@@ -0,0 +1,13 @@
1
+ module IEX
2
+ module Endpoints
3
+ module FX
4
+ def fx_latest(symbols, options = {})
5
+ symbols = Array(symbols)
6
+ response = get('fx/latest', { token: publishable_token, symbols: symbols.join(',') }.merge(options))
7
+ response.map { |row| IEX::Resources::CurrencyRate.new(row) }
8
+ rescue Faraday::ResourceNotFound => e
9
+ raise IEX::Errors::InvalidSymbolsList.new(symbols, e.response[:body])
10
+ end
11
+ end
12
+ end
13
+ end
@@ -3,8 +3,8 @@ module IEX
3
3
  module HistoricalPrices
4
4
  def historical_prices(symbol, options = {})
5
5
  if options[:range] == 'date'
6
- raise ArgumentError unless options[:date].present?
7
- raise ArgumentError unless options[:chartByDay].present?
6
+ raise ArgumentError unless options[:date]
7
+ raise ArgumentError unless options[:chartByDay]
8
8
  end
9
9
 
10
10
  options = options.dup
@@ -0,0 +1,14 @@
1
+ module IEX
2
+ module Endpoints
3
+ module KeyStat
4
+ def key_stat(symbol, stat, options = {})
5
+ result = get("stock/#{symbol}/stats/#{stat}", { token: publishable_token }.merge(options))
6
+ raise IEX::Errors::StatNotFoundError.new(stat, result) if result.is_a?(Hash)
7
+
8
+ result
9
+ rescue Faraday::ResourceNotFound => e
10
+ raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
11
+ end
12
+ end
13
+ end
14
+ end
@@ -22,6 +22,11 @@ module IEX
22
22
  response = get("ref-data/exchange/#{exchange}/symbols", { token: publishable_token }.merge(options))
23
23
  response.map { |row| IEX::Resources::Symbols.new(row) }
24
24
  end
25
+
26
+ def ref_data_symbols_for_region(region, options = {})
27
+ response = get("ref-data/region/#{region}/symbols", { token: publishable_token }.merge(options))
28
+ response.map { |row| IEX::Resources::Symbols.new(row) }
29
+ end
25
30
  end
26
31
  end
27
32
  end
@@ -0,0 +1,14 @@
1
+ module IEX
2
+ module Errors
3
+ class InvalidSymbolsList < StandardError
4
+ attr_reader :symbols
5
+ attr_reader :response
6
+
7
+ def initialize(symbols, response)
8
+ @response = response
9
+ @symbols = symbols
10
+ super "Invalid symbol list: #{symbols.join(',')}"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module IEX
2
+ module Errors
3
+ class StatNotFoundError < StandardError
4
+ attr_reader :response, :stat
5
+
6
+ def initialize(stat, response)
7
+ @response = response
8
+ @stat = stat
9
+ super "Stat #{stat} Not Found"
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/iex/errors.rb CHANGED
@@ -1,3 +1,5 @@
1
- require_relative 'errors/symbol_not_found_error'
2
1
  require_relative 'errors/client_error'
2
+ require_relative 'errors/invalid_symbols_list'
3
3
  require_relative 'errors/permission_denied_error'
4
+ require_relative 'errors/stat_not_found_error'
5
+ require_relative 'errors/symbol_not_found_error'
@@ -0,0 +1,9 @@
1
+ module IEX
2
+ module Resources
3
+ class CurrencyRate < Resource
4
+ property 'symbol'
5
+ property 'rate'
6
+ property 'timestamp', transform_with: ->(v) { Date.strptime((v.to_f / 1000).to_s, '%s') }
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module IEX
2
4
  module Resources
3
5
  class Resource < Hashie::Trash
@@ -27,7 +29,9 @@ module IEX
27
29
  end
28
30
 
29
31
  def self.to_dollar(amount:, ignore_cents: true)
30
- MoneyHelper.money_to_text(amount, 'USD', nil, no_cents: ignore_cents)
32
+ return nil unless amount
33
+
34
+ Money.new(amount * 100, 'USD').format(decimal_mark: '.', no_cents: ignore_cents, thousands_separator: ',')
31
35
  end
32
36
  end
33
37
  end
@@ -3,6 +3,10 @@ module IEX
3
3
  class Symbols < Resource
4
4
  property 'symbol'
5
5
  property 'exchange'
6
+ property 'exchange_suffix', from: 'exchangeSuffix'
7
+ property 'exchange_name', from: 'exchangeName'
8
+ property 'exchange_segment', from: 'exchangeSegment'
9
+ property 'exchange_segment_name', from: 'exchangeSegmentName'
6
10
  property 'name'
7
11
  property 'date', transform_with: ->(v) { Date.parse(v) }
8
12
  property 'enabled', from: 'isEnabled'
@@ -12,6 +16,7 @@ module IEX
12
16
  property 'iex_id', from: 'iexId'
13
17
  property 'figi'
14
18
  property 'cik'
19
+ property 'lei'
15
20
 
16
21
  alias :enabled? enabled
17
22
  end
data/lib/iex/resources.rb CHANGED
@@ -4,6 +4,7 @@ require_relative 'resources/advanced_stats'
4
4
  require_relative 'resources/balance_sheet'
5
5
  require_relative 'resources/cash_flow'
6
6
  require_relative 'resources/chart'
7
+ require_relative 'resources/currency_rate'
7
8
  require_relative 'resources/company'
8
9
  require_relative 'resources/dividends'
9
10
  require_relative 'resources/earnings'
data/lib/iex/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module IEX
2
- VERSION = '1.4.1'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
@@ -2,7 +2,7 @@ require 'faraday'
2
2
  require 'faraday_middleware'
3
3
  require 'faraday_middleware/response_middleware'
4
4
  require 'hashie'
5
- require 'money_helper'
5
+ require 'money'
6
6
  require 'date'
7
7
 
8
8
  require_relative 'iex/version'
data/script/console ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << './lib'
4
+
5
+ require 'dotenv/load'
6
+ require 'iex-ruby-client'
7
+ require 'irb'
8
+
9
+ IRB.start
@@ -0,0 +1,83 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://cloud.iexapis.com/v1/fx/latest?symbols=INVALID&token=test-iex-api-publishable-token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ""
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.15.4
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
+ - Fri, 05 Apr 2019 02:59:49 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=333d7c703c954832b14c34cb8cca7b3a; Max-Age=43200; Path=/; Expires=Fri,
33
+ 05 Apr 2019 14:59:49 GMT
34
+ Content-Security-Policy:
35
+ - "default-src 'self'; child-src 'none'; object-src 'self'; style-src
36
+ 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self'
37
+ https://js.intercomcdn.com/fonts/ https://fonts.gstatic.com; frame-src 'self'
38
+ https://portal.productboard.com/ https://js.stripe.com/; img-src 'self'
39
+ data: https://*.intercomcdn.com/ https://static.intercomassets.com/ https://www.google-analytics.com
40
+ https://downloads.intercomcdn.com/; connect-src 'self' https://auth.iexcloud.io
41
+ https://api.iexcloud.io https://api.iexcloud.io https://cloud.iexapis.com
42
+ wss://iexcloud.io wss://tops.iexcloud.io wss://api.iexcloud.io wss://iexcloud.io
43
+ https://api-iam.intercom.io/messenger/ https://nexus-websocket-a.intercom.io/
44
+ https://nexus-websocket-b.intercom.io/ wss://nexus-websocket-a.intercom.io/
45
+ wss://nexus-websocket-b.intercom.io/ https://www.google-analytics.com; script-src
46
+ 'self' 'unsafe-inline' 'unsafe-eval' https://www.google.com/recaptcha/api.js
47
+ https://www.google-analytics.com https://js.stripe.com/v3/ https://widget.intercom.io/widget/lhos563b
48
+ https://js.intercomcdn.com/ https://www.googletagmanager.com;"
49
+ X-Content-Security-Policy:
50
+ - "default-src 'self'; child-src 'none'; object-src 'self'; style-src
51
+ 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self'
52
+ https://js.intercomcdn.com/fonts/ https://fonts.gstatic.com; frame-src 'self'
53
+ https://portal.productboard.com/ https://js.stripe.com/; img-src 'self'
54
+ data: https://*.intercomcdn.com/ https://static.intercomassets.com/ https://www.google-analytics.com
55
+ https://downloads.intercomcdn.com/; connect-src 'self' https://auth.iexcloud.io
56
+ https://api.iexcloud.io https://api.iexcloud.io https://cloud.iexapis.com
57
+ wss://iexcloud.io wss://tops.iexcloud.io wss://api.iexcloud.io wss://iexcloud.io
58
+ https://api-iam.intercom.io/messenger/ https://nexus-websocket-a.intercom.io/
59
+ https://nexus-websocket-b.intercom.io/ wss://nexus-websocket-a.intercom.io/
60
+ wss://nexus-websocket-b.intercom.io/ https://www.google-analytics.com; script-src
61
+ 'self' 'unsafe-inline' 'unsafe-eval' https://www.google.com/recaptcha/api.js
62
+ https://www.google-analytics.com https://js.stripe.com/v3/ https://widget.intercom.io/widget/lhos563b
63
+ https://js.intercomcdn.com/ https://www.googletagmanager.com;"
64
+ Frame-Options:
65
+ - SAMEORIGIN
66
+ X-Frame-Options:
67
+ - SAMEORIGIN
68
+ Strict-Transport-Security:
69
+ - max-age=15768000
70
+ Access-Control-Allow-Origin:
71
+ - "*"
72
+ Access-Control-Allow-Credentials:
73
+ - "true"
74
+ Access-Control-Allow-Methods:
75
+ - GET, OPTIONS
76
+ Access-Control-Allow-Headers:
77
+ - Origin, X-Requested-With, Content-Type, Accept
78
+ body:
79
+ encoding: ASCII-8BIT
80
+ string: Unknown symbol
81
+ http_version:
82
+ recorded_at: Fri, 05 Apr 2019 02:59:49 GMT
83
+ recorded_with: VCR 4.0.0