iex-ruby-client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +34 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +3 -0
- data/CONTRIBUTING.md +125 -0
- data/Gemfile +3 -0
- data/LICENSE.md +22 -0
- data/README.md +48 -0
- data/RELEASING.md +61 -0
- data/Rakefile +17 -0
- data/iex-ruby-client.gemspec +26 -0
- data/lib/iex-ruby-client.rb +9 -0
- data/lib/iex/api.rb +1 -0
- data/lib/iex/api/quote.rb +26 -0
- data/lib/iex/errors.rb +1 -0
- data/lib/iex/errors/symbol_not_found_error.rb +14 -0
- data/lib/iex/quote.rb +54 -0
- data/lib/iex/resource.rb +4 -0
- data/lib/iex/version.rb +3 -0
- data/spec/fixtures/iex/invalid.yml +61 -0
- data/spec/fixtures/iex/msft.yml +65 -0
- data/spec/iex/quote_spec.rb +31 -0
- data/spec/iex/version_spec.rb +7 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/vcr.rb +9 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: efe580506738cb0051bdf88c9394e1648b0266a7
|
4
|
+
data.tar.gz: 3e24aa4081f8d58ddf429b7c88405fe82184e6b7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '0708198339a430a907ba930429c84cb8ac6c0af610fc4610a12d86b8811fcfdfff4103a26f568f3e611e558f88c78f4bfd1b878d9b7d1d95061e71577e338ff2'
|
7
|
+
data.tar.gz: 407fd1c3d226efad5bd9b63599dd555c2ffff97bfe092b826ef2aff0571c556c9212ce1bfdef27dfbe2a4949d1384aca0a7d120440b065b955e0ec21824f17ec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2018-03-23 11:25:55 -0400 using RuboCop version 0.51.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
11
|
+
Metrics/BlockLength:
|
12
|
+
Max: 27
|
13
|
+
|
14
|
+
# Offense count: 2
|
15
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
16
|
+
# URISchemes: http, https
|
17
|
+
Metrics/LineLength:
|
18
|
+
Max: 107
|
19
|
+
|
20
|
+
# Offense count: 1
|
21
|
+
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
22
|
+
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
|
23
|
+
Naming/FileName:
|
24
|
+
Exclude:
|
25
|
+
- 'lib/iex-ruby-client.rb'
|
26
|
+
|
27
|
+
# Offense count: 3
|
28
|
+
Style/Documentation:
|
29
|
+
Exclude:
|
30
|
+
- 'spec/**/*'
|
31
|
+
- 'test/**/*'
|
32
|
+
- 'lib/iex/api/quote.rb'
|
33
|
+
- 'lib/iex/errors/symbol_not_found_error.rb'
|
34
|
+
- 'lib/iex/quote.rb'
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# Contributing to IEX-Ruby-Client
|
2
|
+
|
3
|
+
This project is work of [many contributors](https://github.com/dblock/iex-ruby-client/graphs/contributors).
|
4
|
+
|
5
|
+
You're encouraged to submit [pull requests](https://github.com/dblock/iex-ruby-client/pulls), [propose features and discuss issues](https://github.com/dblock/iex-ruby-client/issues).
|
6
|
+
|
7
|
+
In the examples below, substitute your Github username for `contributor` in URLs.
|
8
|
+
|
9
|
+
### Fork the Project
|
10
|
+
|
11
|
+
Fork the [project on Github](https://github.com/dblock/iex-ruby-client) and check out your copy.
|
12
|
+
|
13
|
+
```
|
14
|
+
git clone https://github.com/contributor/iex-ruby-client.git
|
15
|
+
cd iex-ruby-client
|
16
|
+
git remote add upstream https://github.com/dblock/iex-ruby-client.git
|
17
|
+
```
|
18
|
+
|
19
|
+
### Bundle Install and Test
|
20
|
+
|
21
|
+
Ensure that you can build the project and run tests.
|
22
|
+
|
23
|
+
```
|
24
|
+
bundle install
|
25
|
+
bundle exec rake
|
26
|
+
```
|
27
|
+
|
28
|
+
## Contribute Code
|
29
|
+
|
30
|
+
### Create a Topic Branch
|
31
|
+
|
32
|
+
Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
|
33
|
+
|
34
|
+
```
|
35
|
+
git checkout master
|
36
|
+
git pull upstream master
|
37
|
+
git checkout -b my-feature-branch
|
38
|
+
```
|
39
|
+
|
40
|
+
### Write Tests
|
41
|
+
|
42
|
+
Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add tests to [spec](spec).
|
43
|
+
|
44
|
+
We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
|
45
|
+
|
46
|
+
### Write Code
|
47
|
+
|
48
|
+
Implement your feature or bug fix.
|
49
|
+
|
50
|
+
Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop). Run `bundle exec rubocop` and fix any style issues highlighted, auto-correct issues when possible with `bundle exec rubocop -a`. To silence generally ingored issues, including line lengths or code complexity metrics, run `bundle exec rubocop --auto-gen-config`.
|
51
|
+
|
52
|
+
Make sure that `bundle exec rake` completes without errors.
|
53
|
+
|
54
|
+
### Write Documentation
|
55
|
+
|
56
|
+
Document any external behavior in the [README](README.md).
|
57
|
+
|
58
|
+
### Update Changelog
|
59
|
+
|
60
|
+
Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Don't remove *Your contribution here*.
|
61
|
+
|
62
|
+
Make it look like every other line, including a link to the issue being fixed, your name and link to your Github account.
|
63
|
+
|
64
|
+
### Commit Changes
|
65
|
+
|
66
|
+
Make sure git knows your name and email address:
|
67
|
+
|
68
|
+
```
|
69
|
+
git config --global user.name "Your Name"
|
70
|
+
git config --global user.email "contributor@example.com"
|
71
|
+
```
|
72
|
+
|
73
|
+
Writing good commit logs is important. A commit log should describe what changed and why.
|
74
|
+
|
75
|
+
```
|
76
|
+
git add ...
|
77
|
+
git commit
|
78
|
+
```
|
79
|
+
|
80
|
+
### Push
|
81
|
+
|
82
|
+
```
|
83
|
+
git push origin my-feature-branch
|
84
|
+
```
|
85
|
+
|
86
|
+
### Make a Pull Request
|
87
|
+
|
88
|
+
Go to https://github.com/contributor/iex-ruby-client and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
|
89
|
+
|
90
|
+
### Update CHANGELOG Again
|
91
|
+
|
92
|
+
Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
|
93
|
+
|
94
|
+
```
|
95
|
+
* [#123](https://github.com/dblock/iex-ruby-client/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
|
96
|
+
```
|
97
|
+
|
98
|
+
Amend your previous commit and force push the changes.
|
99
|
+
|
100
|
+
```
|
101
|
+
git commit --amend
|
102
|
+
git push origin my-feature-branch -f
|
103
|
+
```
|
104
|
+
|
105
|
+
### Rebase
|
106
|
+
|
107
|
+
If you've been working on a change for a while, rebase with upstream/master.
|
108
|
+
|
109
|
+
```
|
110
|
+
git fetch upstream
|
111
|
+
git rebase upstream/master
|
112
|
+
git push origin my-feature-branch -f
|
113
|
+
```
|
114
|
+
|
115
|
+
### Check on Your Pull Request
|
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.
|
118
|
+
|
119
|
+
### Be Patient
|
120
|
+
|
121
|
+
It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
|
122
|
+
|
123
|
+
## Thank You
|
124
|
+
|
125
|
+
Please do know that we really appreciate and value your time and work. We love you, really.
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Daniel Doubrovkine and Contributors
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
IEX Finance API
|
2
|
+
===============
|
3
|
+
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/iex-ruby-client.svg)](https://badge.fury.io/rb/iex-ruby-client)
|
5
|
+
[![Build Status](https://travis-ci.org/dblock/iex-ruby-client.svg?branch=master)](https://travis-ci.org/dblock/iex-ruby-client)
|
6
|
+
|
7
|
+
A Ruby client for the [IEX Finance API](https://iextrading.com/developer).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add to Gemfile.
|
12
|
+
|
13
|
+
```
|
14
|
+
gem 'iex-ruby-client'
|
15
|
+
```
|
16
|
+
|
17
|
+
Run `bundle install`.
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Get a Quote
|
22
|
+
|
23
|
+
Fetches a single stock quote.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
quote = IEX::Quote.get('MSFT')
|
27
|
+
|
28
|
+
quote.latest_price # 90.165
|
29
|
+
quote.change # 0.375
|
30
|
+
quote.change_percent # 0.00418
|
31
|
+
quote.change_percent_s # '+0.42%'
|
32
|
+
```
|
33
|
+
|
34
|
+
See [#quote](https://iextrading.com/developer/docs/#quote) for detailed documentation or [quote.rb](lib/iex/quote.rb) for returned fields.
|
35
|
+
|
36
|
+
If a symbol cannot be found an [IEX::Errors::SymbolNotFound](lib/iex/errors/symbol_not_found_error.rb) exception is raised.
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
See [CONTRIBUTING](CONTRIBUTING.md).
|
41
|
+
|
42
|
+
## Copyright and License
|
43
|
+
|
44
|
+
Copyright (c) 2018, [Daniel Doubrovkine](https://twitter.com/dblockdotorg) and [Contributors](CHANGELOG.md).
|
45
|
+
|
46
|
+
This project is licensed under the [MIT License](LICENSE.md).
|
47
|
+
|
48
|
+
Data provided for free by [IEX](https://iextrading.com/developer), see [terms](https://iextrading.com/api-exhibit-a).
|
data/RELEASING.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Releasing IEX-Ruby-Client
|
2
|
+
|
3
|
+
There're no hard rules about when to release iex-ruby-client. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
|
4
|
+
|
5
|
+
### Release
|
6
|
+
|
7
|
+
Run tests, check that all tests succeed locally.
|
8
|
+
|
9
|
+
```
|
10
|
+
bundle install
|
11
|
+
rake
|
12
|
+
```
|
13
|
+
|
14
|
+
Check that the last build succeeded in [Travis CI](https://travis-ci.org/dblock/iex-ruby-client) for all supported platforms.
|
15
|
+
|
16
|
+
Change "Next" in [CHANGELOG.md](CHANGELOG.md) to the current date.
|
17
|
+
|
18
|
+
```
|
19
|
+
### 0.2.2 (7/10/2015)
|
20
|
+
```
|
21
|
+
|
22
|
+
Remove the line with "Your contribution here.", since there will be no more contributions to this release.
|
23
|
+
|
24
|
+
Commit your changes.
|
25
|
+
|
26
|
+
```
|
27
|
+
git add CHANGELOG.md
|
28
|
+
git commit -m "Preparing for release, 0.2.2."
|
29
|
+
git push origin master
|
30
|
+
```
|
31
|
+
|
32
|
+
Release.
|
33
|
+
|
34
|
+
```
|
35
|
+
$ rake release
|
36
|
+
|
37
|
+
iex-ruby-client 0.2.2 built to pkg/iex-ruby-client-0.2.2.gem.
|
38
|
+
Tagged v0.2.2.
|
39
|
+
Pushed git commits and tags.
|
40
|
+
Pushed iex-ruby-client 0.2.2 to rubygems.org.
|
41
|
+
```
|
42
|
+
|
43
|
+
### Prepare for the Next Version
|
44
|
+
|
45
|
+
Add the next release to [CHANGELOG.md](CHANGELOG.md).
|
46
|
+
|
47
|
+
```
|
48
|
+
### 0.2.3 (Next)
|
49
|
+
|
50
|
+
* Your contribution here.
|
51
|
+
```
|
52
|
+
|
53
|
+
Increment the third version number in [lib/iex/version.rb](lib/iex/version.rb).
|
54
|
+
|
55
|
+
Commit your changes.
|
56
|
+
|
57
|
+
```
|
58
|
+
git add CHANGELOG.md lib/iex/version.rb
|
59
|
+
git commit -m "Preparing for next development iteration, 0.2.3."
|
60
|
+
git push origin master
|
61
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
Bundler.setup :default, :development
|
6
|
+
|
7
|
+
require 'rspec/core'
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
11
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rubocop/rake_task'
|
15
|
+
RuboCop::RakeTask.new
|
16
|
+
|
17
|
+
task default: %i[rubocop spec]
|
@@ -0,0 +1,26 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'iex/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'iex-ruby-client'
|
6
|
+
s.bindir = 'bin'
|
7
|
+
s.version = IEX::VERSION
|
8
|
+
s.authors = ['Daniel Doubrovkine']
|
9
|
+
s.email = 'dblock@dblock.org'
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.required_rubygems_version = '>= 1.3.6'
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
14
|
+
s.require_paths = ['lib']
|
15
|
+
s.homepage = 'http://github.com/dblock/iex-ruby-client'
|
16
|
+
s.licenses = ['MIT']
|
17
|
+
s.summary = 'IEX Finance API Ruby client with support for retrieving stock quotes.'
|
18
|
+
s.add_dependency 'faraday', '>= 0.9'
|
19
|
+
s.add_dependency 'faraday_middleware'
|
20
|
+
s.add_dependency 'hashie'
|
21
|
+
s.add_development_dependency 'rake', '~> 10'
|
22
|
+
s.add_development_dependency 'rspec'
|
23
|
+
s.add_development_dependency 'rubocop', '0.51.0'
|
24
|
+
s.add_development_dependency 'vcr'
|
25
|
+
s.add_development_dependency 'webmock'
|
26
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'faraday_middleware/response_middleware'
|
4
|
+
require 'hashie'
|
5
|
+
require_relative 'iex/version'
|
6
|
+
require_relative 'iex/errors'
|
7
|
+
require_relative 'iex/api'
|
8
|
+
require_relative 'iex/resource'
|
9
|
+
require_relative 'iex/quote'
|
data/lib/iex/api.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'api/quote'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module IEX
|
2
|
+
module Api
|
3
|
+
module Quote
|
4
|
+
def self.get(params)
|
5
|
+
params = params.dup
|
6
|
+
symbol = params.delete(:q)
|
7
|
+
connection(symbol).get do |c|
|
8
|
+
c.params.merge!(params)
|
9
|
+
end.body
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.connection(symbol)
|
13
|
+
Faraday.new(
|
14
|
+
url: "https://api.iextrading.com/1.0/stock/#{symbol}/quote",
|
15
|
+
request: {
|
16
|
+
params_encoder: Faraday::FlatParamsEncoder
|
17
|
+
}
|
18
|
+
) do |c|
|
19
|
+
c.use ::FaradayMiddleware::ParseJson
|
20
|
+
c.use Faraday::Response::RaiseError
|
21
|
+
c.use Faraday::Adapter::NetHttp
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/iex/errors.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'errors/symbol_not_found_error'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module IEX
|
2
|
+
module Errors
|
3
|
+
class SymbolNotFoundError < StandardError
|
4
|
+
attr_reader :symbol
|
5
|
+
attr_reader :response
|
6
|
+
|
7
|
+
def initialize(symbol, response)
|
8
|
+
@response = response
|
9
|
+
@symbol = symbol
|
10
|
+
super "Symbol #{symbol} Not Found"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/iex/quote.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module IEX
|
2
|
+
class Quote < Resource
|
3
|
+
property 'symbol'
|
4
|
+
property 'company_name', from: 'companyName'
|
5
|
+
property 'primary_exchange', from: 'primaryExchange'
|
6
|
+
property 'sector'
|
7
|
+
property 'calculation_price', from: 'calculationPrice'
|
8
|
+
property 'open'
|
9
|
+
property 'open_time', from: 'openTime'
|
10
|
+
property 'close'
|
11
|
+
property 'close_time', from: 'closeTime'
|
12
|
+
property 'high'
|
13
|
+
property 'low'
|
14
|
+
property 'latest_price', from: 'latestPrice'
|
15
|
+
property 'latest_source', from: 'latestSource'
|
16
|
+
property 'latest_time', from: 'latestTime'
|
17
|
+
property 'latest_update', from: 'latestUpdate'
|
18
|
+
property 'latest_volume', from: 'latestVolume'
|
19
|
+
property 'iex_realtime_price', from: 'iexRealtimePrice'
|
20
|
+
property 'iex_realtime_size', from: 'iexRealtimeSize'
|
21
|
+
property 'iex_last_updated', from: 'iexLastUpdated'
|
22
|
+
property 'delayed_price', from: 'delayedPrice'
|
23
|
+
property 'delayed_price_time', from: 'delayedPriceTime'
|
24
|
+
property 'previous_close', from: 'previousClose'
|
25
|
+
property 'change'
|
26
|
+
property 'change_percent', from: 'changePercent'
|
27
|
+
property 'iex_market_percent', from: 'iexMarketPercent'
|
28
|
+
property 'iex_volume', from: 'iexVolume'
|
29
|
+
property 'avg_total_volume', from: 'avgTotalVolume'
|
30
|
+
property 'iex_bid_price', from: 'iexBidPrice'
|
31
|
+
property 'iex_bid_size', from: 'iexBidSize'
|
32
|
+
property 'iex_ask_price', from: 'iexAskPrice'
|
33
|
+
property 'iex_ask_size', from: 'iexAskSize'
|
34
|
+
property 'market_cap', from: 'marketCap'
|
35
|
+
property 'pe_ratio', from: 'peRatio'
|
36
|
+
property 'week_52_high', from: 'week52High'
|
37
|
+
property 'week_52_low', from: 'week52Low'
|
38
|
+
property 'ytd_change', from: 'ytdChange'
|
39
|
+
|
40
|
+
def change_percent_s
|
41
|
+
[
|
42
|
+
change_percent > 0 ? '+' : '',
|
43
|
+
format('%.2f', change_percent * 100),
|
44
|
+
'%'
|
45
|
+
].join
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.get(symbol)
|
49
|
+
new IEX::Api::Quote.get(q: symbol)
|
50
|
+
rescue Faraday::ResourceNotFound => e
|
51
|
+
raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/iex/resource.rb
ADDED
data/lib/iex/version.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.iextrading.com/1.0/stock/INVALID/quote
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.14.0
|
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, 23 Mar 2018 15:15:57 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=8fdab40cfa8542669c3411d154319317; Domain=.iextrading.com; Path=/; Expires=Sat,
|
33
|
+
24 Mar 2018 03:15:57 GMT; Secure
|
34
|
+
Content-Security-Policy:
|
35
|
+
- default-src 'self'; child-src 'none'; object-src 'none'; style-src 'self'
|
36
|
+
'unsafe-inline'; font-src data:; connect-src 'self' https://auth.iextrading.com
|
37
|
+
wss://iextrading.com wss://tops.iextrading.com; script-src 'self';
|
38
|
+
X-Content-Security-Policy:
|
39
|
+
- default-src 'self'; child-src 'none'; object-src 'none'; style-src 'self'
|
40
|
+
'unsafe-inline'; font-src data:; connect-src 'self' https://auth.iextrading.com
|
41
|
+
wss://iextrading.com wss://tops.iextrading.com; script-src 'self';
|
42
|
+
Frame-Options:
|
43
|
+
- deny
|
44
|
+
X-Frame-Options:
|
45
|
+
- deny
|
46
|
+
Strict-Transport-Security:
|
47
|
+
- max-age=15768000
|
48
|
+
Access-Control-Allow-Origin:
|
49
|
+
- "*"
|
50
|
+
Access-Control-Allow-Credentials:
|
51
|
+
- 'true'
|
52
|
+
Access-Control-Allow-Methods:
|
53
|
+
- GET, OPTIONS
|
54
|
+
Access-Control-Allow-Headers:
|
55
|
+
- Origin, X-Requested-With, Content-Type, Accept
|
56
|
+
body:
|
57
|
+
encoding: ASCII-8BIT
|
58
|
+
string: Unknown symbol
|
59
|
+
http_version:
|
60
|
+
recorded_at: Fri, 23 Mar 2018 15:15:57 GMT
|
61
|
+
recorded_with: VCR 4.0.0
|
@@ -0,0 +1,65 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.iextrading.com/1.0/stock/MSFT/quote
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.14.0
|
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: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx
|
23
|
+
Date:
|
24
|
+
- Fri, 23 Mar 2018 15:15:57 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json; charset=utf-8
|
27
|
+
Content-Length:
|
28
|
+
- '836'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Set-Cookie:
|
32
|
+
- ctoken=d3f239a37b4141acbf609e8663f3302a; Domain=.iextrading.com; Path=/; Expires=Sat,
|
33
|
+
24 Mar 2018 03:15:57 GMT; Secure
|
34
|
+
Content-Security-Policy:
|
35
|
+
- default-src 'self'; child-src 'none'; object-src 'none'; style-src 'self'
|
36
|
+
'unsafe-inline'; font-src data:; connect-src 'self' https://auth.iextrading.com
|
37
|
+
wss://iextrading.com wss://tops.iextrading.com; script-src 'self';
|
38
|
+
X-Content-Security-Policy:
|
39
|
+
- default-src 'self'; child-src 'none'; object-src 'none'; style-src 'self'
|
40
|
+
'unsafe-inline'; font-src data:; connect-src 'self' https://auth.iextrading.com
|
41
|
+
wss://iextrading.com wss://tops.iextrading.com; script-src 'self';
|
42
|
+
Frame-Options:
|
43
|
+
- deny
|
44
|
+
X-Frame-Options:
|
45
|
+
- deny
|
46
|
+
X-Content-Type-Options:
|
47
|
+
- nosniff
|
48
|
+
Strict-Transport-Security:
|
49
|
+
- max-age=15768000
|
50
|
+
Access-Control-Allow-Origin:
|
51
|
+
- "*"
|
52
|
+
Access-Control-Allow-Credentials:
|
53
|
+
- 'true'
|
54
|
+
Access-Control-Allow-Methods:
|
55
|
+
- GET, OPTIONS
|
56
|
+
Access-Control-Allow-Headers:
|
57
|
+
- Origin, X-Requested-With, Content-Type, Accept
|
58
|
+
body:
|
59
|
+
encoding: UTF-8
|
60
|
+
string: '{"symbol":"MSFT","companyName":"Microsoft Corporation","primaryExchange":"Nasdaq
|
61
|
+
Global Select","sector":"Technology","calculationPrice":"tops","open":89.45,"openTime":1521811800352,"close":89.79,"closeTime":1521748800315,"high":90.46,"low":89.161,"latestPrice":90.165,"latestSource":"IEX
|
62
|
+
real time price","latestTime":"11:15:45 AM","latestUpdate":1521818145007,"latestVolume":10015072,"iexRealtimePrice":90.165,"iexRealtimeSize":200,"iexLastUpdated":1521818145007,"delayedPrice":90.34,"delayedPriceTime":1521817252749,"previousClose":89.79,"change":0.375,"changePercent":0.00418,"iexMarketPercent":0.03178,"iexVolume":318279,"avgTotalVolume":32176892,"iexBidPrice":89.8,"iexBidSize":100,"iexAskPrice":92.31,"iexAskSize":100,"marketCap":694251822501,"peRatio":27.32,"week52High":97.24,"week52Low":64.35,"ytdChange":0.049583743433526506}'
|
63
|
+
http_version:
|
64
|
+
recorded_at: Fri, 23 Mar 2018 15:15:57 GMT
|
65
|
+
recorded_with: VCR 4.0.0
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IEX::Quote do
|
4
|
+
context 'known symbol', vcr: { cassette_name: 'msft' } do
|
5
|
+
subject do
|
6
|
+
IEX::Quote.get('MSFT')
|
7
|
+
end
|
8
|
+
it 'retrieves a quote' do
|
9
|
+
expect(subject.symbol).to eq 'MSFT'
|
10
|
+
expect(subject.primary_exchange).to eq 'Nasdaq Global Select'
|
11
|
+
expect(subject.company_name).to eq 'Microsoft Corporation'
|
12
|
+
expect(subject.market_cap).to eq 694_251_822_501
|
13
|
+
end
|
14
|
+
it 'coerces numbers' do
|
15
|
+
expect(subject.latest_price).to eq 90.165
|
16
|
+
expect(subject.change).to eq 0.375
|
17
|
+
expect(subject.week_52_high).to eq 97.24
|
18
|
+
expect(subject.week_52_low).to eq 64.35
|
19
|
+
expect(subject.change_percent).to eq 0.00418
|
20
|
+
expect(subject.change_percent_s).to eq '+0.42%'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
context 'invalid symbol', vcr: { cassette_name: 'invalid' } do
|
24
|
+
subject do
|
25
|
+
IEX::Quote.get('INVALID')
|
26
|
+
end
|
27
|
+
it 'fails with SymbolNotFoundError' do
|
28
|
+
expect { subject }.to raise_error IEX::Errors::SymbolNotFoundError, 'Symbol INVALID Not Found'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/support/vcr.rb
ADDED
metadata
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iex-ruby-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Doubrovkine
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: hashie
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.51.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.51.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: vcr
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description:
|
126
|
+
email: dblock@dblock.org
|
127
|
+
executables: []
|
128
|
+
extensions: []
|
129
|
+
extra_rdoc_files: []
|
130
|
+
files:
|
131
|
+
- ".gitignore"
|
132
|
+
- ".rspec"
|
133
|
+
- ".rubocop.yml"
|
134
|
+
- ".rubocop_todo.yml"
|
135
|
+
- ".travis.yml"
|
136
|
+
- CHANGELOG.md
|
137
|
+
- CONTRIBUTING.md
|
138
|
+
- Gemfile
|
139
|
+
- LICENSE.md
|
140
|
+
- README.md
|
141
|
+
- RELEASING.md
|
142
|
+
- Rakefile
|
143
|
+
- iex-ruby-client.gemspec
|
144
|
+
- lib/iex-ruby-client.rb
|
145
|
+
- lib/iex/api.rb
|
146
|
+
- lib/iex/api/quote.rb
|
147
|
+
- lib/iex/errors.rb
|
148
|
+
- lib/iex/errors/symbol_not_found_error.rb
|
149
|
+
- lib/iex/quote.rb
|
150
|
+
- lib/iex/resource.rb
|
151
|
+
- lib/iex/version.rb
|
152
|
+
- spec/fixtures/iex/invalid.yml
|
153
|
+
- spec/fixtures/iex/msft.yml
|
154
|
+
- spec/iex/quote_spec.rb
|
155
|
+
- spec/iex/version_spec.rb
|
156
|
+
- spec/spec_helper.rb
|
157
|
+
- spec/support/vcr.rb
|
158
|
+
homepage: http://github.com/dblock/iex-ruby-client
|
159
|
+
licenses:
|
160
|
+
- MIT
|
161
|
+
metadata: {}
|
162
|
+
post_install_message:
|
163
|
+
rdoc_options: []
|
164
|
+
require_paths:
|
165
|
+
- lib
|
166
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: 1.3.6
|
176
|
+
requirements: []
|
177
|
+
rubyforge_project:
|
178
|
+
rubygems_version: 2.6.12
|
179
|
+
signing_key:
|
180
|
+
specification_version: 4
|
181
|
+
summary: IEX Finance API Ruby client with support for retrieving stock quotes.
|
182
|
+
test_files:
|
183
|
+
- spec/fixtures/iex/invalid.yml
|
184
|
+
- spec/fixtures/iex/msft.yml
|
185
|
+
- spec/iex/quote_spec.rb
|
186
|
+
- spec/iex/version_spec.rb
|
187
|
+
- spec/spec_helper.rb
|
188
|
+
- spec/support/vcr.rb
|