Skip to content

Commit

Permalink
Merge pull request #50 from dblock/add-missing-properties-for-key-sta…
Browse files Browse the repository at this point in the history
…ts-api

Add missing properties for key stats API
  • Loading branch information
dblock authored May 6, 2019
2 parents 382a62e + 11dd235 commit b245638
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 143 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 1.0.1 (Next)

* Your contribution here.
* [#50](https://github.com/dblock/iex-ruby-client/pull/50): Add missing properties for key stats API - [@bingxie](https://github.com/bingxie).

### 1.0.0 (2019/04/23)

Expand Down
73 changes: 43 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ client = IEX::Api::Client.new(publishable_token: 'token')
Fetches a single number, being the IEX real time price, the 15 minute delayed market price, or the previous close price.

```ruby
client.get('MSFT') # 93.78
client.price('MSFT') # 93.78
```

See [#price](https://iexcloud.io/docs/api/#price) for detailed documentation.
Expand Down Expand Up @@ -193,35 +193,48 @@ Fetches company's key stats for a symbol.
```ruby
key_stats = client.key_stats('MSFT')

key_stats.market_cap # 825814890000
key_stats.market_cap_dollars # '$825,814,890,000'
key_stats.week_52_high # 111.15
key_stats.week_52_high_dollar # '$111.15'
key_stats.week_52_low # 71.28
key_stats.week_52_low_dollar # '$71.28'
key_stats.week_52_change_dollar # '$51.77'
key_stats.dividend_yield # 1.5617738
key_stats.ex_dividend_date # '2018-08-15 00:00:00.0'
key_stats.shares_outstanding # 7677000000
key_stats.float # 7217387757
key_stats.ttm_eps # 3.51
key_stats.day_200_moving_avg # 91.99065
key_stats.day_50_moving_avg # 102.2528
key_stats.year_5_change_percent # 2.85141424991049
key_stats.year_5_change_percent_s # '+285.14%'
key_stats.year_2_change_percent # 0.9732002824884664
key_stats.year_2_change_percent_s # '+97.32%'
key_stats.year_1_change_percent # 0.5200287133805482
key_stats.year_1_change_percent_s # '+52.00%'
key_stats.ytd_change_percent # 0.2628699562098638
key_stats.month_6_change_percent # 0.23345097958275707
key_stats.month_6_change_percent_s # '+23.35%'
key_stats.month_3_change_percent # 0.14846686026648437
key_stats.month_3_change_percent_s # '+14.85%'
key_stats.month_1_change_percent # 0.08601716304896513
key_stats.month_1_change_percent_s # '+8.60%'
key_stats.day_5_change_percent # -0.0010215453194652084
key_stats.day_5_change_percent_s # '-0.10%'
key_stats.week_52_change_dollar # "$0.37"
key_stats.week_52_high # 136.04
key_stats.week_52_high_dollar # "$136.04"
key_stats.week_52_low # 95.92,
key_stats.week_52_low_dollar # "$95.92"
key_stats.market_cap # 990869169557
key_stats.market_cap_dollars # "$990,869,169,557"
key_stats.employees # 133074
key_stats.day_200_moving_avg # 112.43
key_stats.day_50_moving_avg # 121
key_stats.float # 7694414092
key_stats.avg_10_volume # 25160156.2
key_stats.avg_30_volume # 23123700.13
key_stats.ttm_eps # 4.66
key_stats.ttm_dividend_rate # 1.8
key_stats.company_name # "Microsoft Corp."
key_stats.shares_outstanding # 7849945172
key_stats.max_change_percent # 4.355607
key_stats.year_5_change_percent # 2.32987
key_stats.year_5_change_percent_s # "+232.99%"
key_stats.year_2_change_percent # 0.84983
key_stats.year_2_change_percent_s # "+84.98%"
key_stats.year_1_change_percent # 0.383503
key_stats.year_1_change_percent_s # "+38.35%"
key_stats.ytd_change_percent # 0.270151
key_stats.ytd_change_percent_s # "+27.02%"
key_stats.month_6_change_percent # 0.208977
key_stats.month_6_change_percent_s # "+20.90%"
key_stats.month_3_change_percent # 0.212188
key_stats.month_3_change_percent_s # "+21.22%"
key_stats.month_1_change_percent # 0.076335
key_stats.month_1_change_percent_s # "+7.63%"
key_stats.day_30_change_percent # 0.089589
key_stats.day_30_change_percent_s # "+8.96%"
key_stats.day_5_change_percent # -0.010013
key_stats.day_5_change_percent_s # "-1.00%"
key_stats.next_dividend_date # "2019-05-21"
key_stats.dividend_yield # 0.014087248841960684
key_stats.next_earnings_date # "2019-07-29"
key_stats.ex_dividend_date # "2019-05-24"
key_stats.pe_ratio # 29.47
key_stats.beta # 1.4135449089973444
```

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.
Expand Down
12 changes: 12 additions & 0 deletions lib/iex/resources/key_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class KeyStats < Resource
property 'year_1_change_percent', from: 'year1ChangePercent'
property 'year_1_change_percent_s', from: 'year1ChangePercent', with: ->(v) { Resource.float_to_percentage(v) }
property 'ytd_change_percent', from: 'ytdChangePercent'
property 'ytd_change_percent_s', from: 'ytdChangePercent', with: ->(v) { Resource.float_to_percentage(v) }
property 'month_6_change_percent', from: 'month6ChangePercent'
property 'month_6_change_percent_s', from: 'month6ChangePercent', with: ->(v) { Resource.float_to_percentage(v) }
property 'month_3_change_percent', from: 'month3ChangePercent'
Expand All @@ -32,6 +33,17 @@ class KeyStats < Resource
property 'month_1_change_percent_s', from: 'month1ChangePercent', with: ->(v) { Resource.float_to_percentage(v) }
property 'day_5_change_percent', from: 'day5ChangePercent'
property 'day_5_change_percent_s', from: 'day5ChangePercent', with: ->(v) { Resource.float_to_percentage(v) }
property 'employees'
property 'avg_10_volume', from: 'avg10Volume'
property 'avg_30_volume', from: 'avg30Volume'
property 'ttm_dividend_rate', from: 'ttmDividendRate'
property 'max_change_percent', from: 'maxChangePercent'
property 'day_30_change_percent', from: 'day30ChangePercent'
property 'day_30_change_percent_s', from: 'day30ChangePercent', with: ->(v) { Resource.float_to_percentage(v) }
property 'next_dividend_date', from: 'nextDividendDate'
property 'next_earnings_date', from: 'nextEarningsDate'
property 'pe_ratio', from: 'peRatio'
property 'beta'

def initialize(data = {})
super
Expand Down
48 changes: 7 additions & 41 deletions spec/fixtures/iex/key_stats/invalid.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 11 additions & 43 deletions spec/fixtures/iex/key_stats/msft.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 41 additions & 29 deletions spec/iex/endpoints/key_stats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,56 @@
end
it 'retrieves a keyStats' do
expect(subject.company_name).to eq 'Microsoft Corp.'
expect(subject.market_cap).to eq 915_754_985_600
expect(subject.market_cap_dollars).to eq '$915,754,985,600'
expect(subject.market_cap).to eq 990_869_169_557
expect(subject.market_cap_dollars).to eq '$990,869,169,557'
expect(subject.employees).to eq 133_074
end

it 'weekly stats' do
expect(subject.week_52_high).to eq 120.82
expect(subject.week_52_high_dollar).to eq '$120.82'
expect(subject.week_52_low).to eq 89.48
expect(subject.week_52_low_dollar).to eq '$89.48'
expect(subject.week_52_change_dollar).to eq '$0.29'
expect(subject.week_52_high).to eq 136.04
expect(subject.week_52_high_dollar).to eq '$136.04'
expect(subject.week_52_low).to eq 95.92
expect(subject.week_52_low_dollar).to eq '$95.92'
expect(subject.week_52_change_dollar).to eq '$0.37'
end

it 'general stats' do
expect(subject.dividend_yield).to eq 0.014745308310991957
expect(subject.ex_dividend_date).to eq '2019-05-15'
expect(subject.shares_outstanding).to eq 7_672_210_000
expect(subject.float).to eq 7_541_169_096
expect(subject.ttm_eps).to eq 4.35
expect(subject.day_200_moving_avg).to eq 108.04
expect(subject.day_50_moving_avg).to eq 111.56
expect(subject.ttm_dividend_rate).to eq 1.8
expect(subject.dividend_yield).to eq 0.014087248841960684
expect(subject.ex_dividend_date).to eq '2019-05-24'
expect(subject.shares_outstanding).to eq 7_849_945_172
expect(subject.float).to eq 7_694_414_092
expect(subject.ttm_eps).to eq 4.66
expect(subject.next_dividend_date).to eq '2019-05-21'
expect(subject.next_earnings_date).to eq '2019-07-29'
expect(subject.pe_ratio).to eq 29.47
expect(subject.beta).to eq 1.4135449089973444
expect(subject.day_200_moving_avg).to eq 112.43
expect(subject.day_50_moving_avg).to eq 121
end

it 'changes stats' do
expect(subject.year_5_change_percent).to be 1.998995
expect(subject.year_5_change_percent_s).to eq '+199.90%'
expect(subject.year_2_change_percent).to eq 0.820622
expect(subject.year_2_change_percent_s).to eq '+82.06%'
expect(subject.year_1_change_percent).to eq 0.292055
expect(subject.year_1_change_percent_s).to eq '+29.21%'
expect(subject.ytd_change_percent).to eq 0.18038
expect(subject.month_6_change_percent).to eq 0.064479
expect(subject.month_6_change_percent_s).to eq '+6.45%'
expect(subject.month_3_change_percent).to eq 0.169508
expect(subject.month_3_change_percent_s).to eq '+16.95%'
expect(subject.month_1_change_percent).to eq 0.068577
expect(subject.month_1_change_percent_s).to eq '+6.86%'
expect(subject.day_5_change_percent).to eq 0.01204
expect(subject.day_5_change_percent_s).to eq '+1.20%'
expect(subject.avg_10_volume).to be 25_160_156.2
expect(subject.avg_30_volume).to be 23_123_700.13
expect(subject.max_change_percent).to eq 4.355607
expect(subject.year_5_change_percent).to be 2.32987
expect(subject.year_5_change_percent_s).to eq '+232.99%'
expect(subject.year_2_change_percent).to eq 0.84983
expect(subject.year_2_change_percent_s).to eq '+84.98%'
expect(subject.year_1_change_percent).to eq 0.383503
expect(subject.year_1_change_percent_s).to eq '+38.35%'
expect(subject.ytd_change_percent).to eq 0.270151
expect(subject.ytd_change_percent_s).to eq '+27.02%'
expect(subject.month_6_change_percent).to eq 0.208977
expect(subject.month_6_change_percent_s).to eq '+20.90%'
expect(subject.month_3_change_percent).to eq 0.212188
expect(subject.month_3_change_percent_s).to eq '+21.22%'
expect(subject.month_1_change_percent).to eq 0.076335
expect(subject.month_1_change_percent_s).to eq '+7.63%'
expect(subject.day_5_change_percent).to eq(-0.010013)
expect(subject.day_5_change_percent_s).to eq '-1.00%'
expect(subject.day_30_change_percent).to eq 0.089589
expect(subject.day_30_change_percent_s).to eq '+8.96%'
end
end

Expand Down

0 comments on commit b245638

Please sign in to comment.