Skip to content

Commit

Permalink
Add Symbols Resource (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryosuke-endo committed May 3, 2020
1 parent 85f8002 commit 153b364
Show file tree
Hide file tree
Showing 9 changed files with 9,073 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
### 1.1.3 (Next)

* Your contribution here.
* [#71](https://github.com/dblock/iex-ruby-client/pull/71): Add symbols resource - [@ryosuke-endo](https://github.com/ryosuke-endo).
* [#69](https://github.com/dblock/iex-ruby-client/pull/69): Fixed ref_data_isin request - [@bguban](https://github.com/bguban).

### 1.1.2 (2020/03/25)
Expand Down
17 changes: 17 additions & 0 deletions README.md
Expand Up @@ -27,6 +27,7 @@ A Ruby client for the [The IEX Cloud API](https://iexcloud.io/docs/api/).
- [Get Largest Trades](#get-largest-trades)
- [Get a Quote for Crypto Currencies](#get-a-quote-for-crypto-currencies)
- [ISIN Mapping](#isin-mapping)
- [Get Symbols](#get-symbols)
- [Get List](#get-list)
- [Other Requests](#other-requests)
- [Configuration](#configuration)
Expand Down Expand Up @@ -395,6 +396,22 @@ client.ref_data_isin(['US0378331005', 'US5949181045'], mapped: true) # {'US03783

See [#ISIN Mapping](https://iexcloud.io/docs/api/#isin-mapping) for detailed documentation or [isin_mapping.rb](lib/iex/resources/isin_mapping.rb) for returned fields.

### Get Symbols

Returns an array of symbols

```ruby
symbols = client.ref_data_symbols()

symbol = symbols.first
symbol.exchange # NAS
symbol.iex_id # IEX_46574843354B2D52
symbol.region # US
symbol.symbol # A
```

See [#symbols](https://iexcloud.io/docs/api/#symbols) for detailed documentation or [symbols.rb](lib/iex/resources/symbols.rb) for returned fields.

### Get List

Returns an array of quotes for the top 10 symbols in a specified list.
Expand Down
2 changes: 1 addition & 1 deletion iex-ruby-client.gemspec
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |s|
s.homepage = 'http://github.com/dblock/iex-ruby-client'
s.licenses = ['MIT']
s.summary = 'IEX Finance API Ruby client with support for retrieving stock quotes.'
s.add_dependency 'faraday', '>= 0.9'
s.add_dependency 'faraday', '>= 0.17'
s.add_dependency 'faraday_middleware'
s.add_dependency 'hashie'
s.add_dependency 'money_helper'
Expand Down
2 changes: 1 addition & 1 deletion lib/iex/cloud/response.rb
Expand Up @@ -5,7 +5,7 @@ class RaiseError < ::Faraday::Response::RaiseError
def on_complete(env)
case env[:status]
when 404
raise Faraday::Error::ResourceNotFound, response_values(env)
raise Faraday::ResourceNotFound, response_values(env)
when 403
raise IEX::Errors::PermissionDeniedError, response_values(env)
when ClientErrorStatuses
Expand Down
5 changes: 5 additions & 0 deletions lib/iex/endpoints/ref_data.rb
Expand Up @@ -12,6 +12,11 @@ def ref_data_isin(isins, options = {})
response.map { |row| IEX::Resources::Symbol.new(row) }
end
end

def ref_data_symbols(options = {})
response = get('ref-data/symbols', { token: publishable_token }.merge(options))
response.map { |row| IEX::Resources::Symbols.new(row) }
end
end
end
end
1 change: 1 addition & 0 deletions lib/iex/resources.rb
Expand Up @@ -14,3 +14,4 @@
require_relative 'resources/sectors'
require_relative 'resources/crypto'
require_relative 'resources/symbol'
require_relative 'resources/symbols'
19 changes: 19 additions & 0 deletions lib/iex/resources/symbols.rb
@@ -0,0 +1,19 @@
module IEX
module Resources
class Symbols < Resource
property 'symbol'
property 'exchange'
property 'name'
property 'date', transform_with: ->(v) { Date.parse(v) }
property 'enabled', from: 'isEnabled'
property 'type'
property 'region'
property 'currency'
property 'iex_id', from: 'iexId'
property 'figi'
property 'cik'

alias :enabled? enabled
end
end
end
9,002 changes: 9,002 additions & 0 deletions spec/fixtures/iex/ref-data/symbols.yml

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions spec/iex/endpoints/ref_data_spec.rb
Expand Up @@ -37,4 +37,30 @@
end
end
end

describe '#ref_data_symbols', vcr: { cassette_name: 'ref-data/symbols' } do
subject { client.ref_data_symbols }

it 'retrieves all symbols' do
expect(subject.count).to eq 8808
end

context 'first symbol' do
subject { client.ref_data_symbols.first }
it 'retrieves a symbol data' do
expect(subject.symbol).to eq 'A'
expect(subject.exchange).to eq 'NYS'
expect(subject.name).to eq 'Agilent Technologies Inc.'
expect(subject.date).to eq Date.parse('2020-04-30')
expect(subject.enabled).to eq true
expect(subject.enabled?).to eq true
expect(subject.type).to eq 'cs'
expect(subject.region).to eq 'US'
expect(subject.currency).to eq 'USD'
expect(subject.iex_id).to eq 'IEX_46574843354B2D52'
expect(subject.figi).to eq 'BBG000C2V3D6'
expect(subject.cik).to eq '1090872'
end
end
end
end

0 comments on commit 153b364

Please sign in to comment.