Skip to content

Commit

Permalink
issue #195: get stock prices from IEX (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
corprew authored and dblock committed Apr 19, 2019
1 parent b615196 commit 25f9384
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
* [#209](https://github.com/slack-ruby/slack-ruby-bot/pull/209): Allow `respond_to_slack_message` and `respond_to_slack_messages` without arguments - [@dblock](https://github.com/dblock).
* [#216](https://github.com/slack-ruby/slack-ruby-bot/pull/216): Added `start_typing` RSpec matcher - [@dblock](https://github.com/dblock).
* [#214](https://github.com/slack-ruby/slack-ruby-bot/pull/214): Add passenger deployment documentation - [@cybercrediators](https://github.com/cybercrediators).
* [#220](https://github.com/slack-ruby/slack-ruby-bot/pull/220): Updated examples/market to pull from IEX instead of defunct yahoo service - [@corprew](https://github.com/corprew).
* Your contribution here.


### 0.12.0 (2019/2/25)

* [#203](https://github.com/slack-ruby/slack-ruby-bot/pull/203): Removing restart logic - [@RodneyU215](https://github.com/RodneyU215).
Expand Down
5 changes: 2 additions & 3 deletions examples/market/Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
source 'http://rubygems.org'

gem 'faye-websocket'
gem 'slack-ruby-bot', path: '../..'
gem 'yahoo-finance'
gem 'iex-ruby-client'
gem 'slack-ruby-bot'
35 changes: 20 additions & 15 deletions examples/market/marketbot.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
require 'iex-ruby-client'
require 'slack-ruby-bot'
require 'yahoo-finance'

SlackRubyBot::Client.logger.level = Logger::WARN

class MarketBot < SlackRubyBot::Bot
scan(/([A-Z]{2,5}+)/) do |client, data, stocks|
YahooFinance::Client.new.quotes(stocks, %i[name symbol last_trade_price change change_in_percent]).each do |quote|
next if quote.symbol == 'N/A'
client.web_client.chat_postMessage(
channel: data.channel,
as_user: true,
attachments: [
{
fallback: "#{quote.name} (#{quote.symbol}): $#{quote.last_trade_price}",
title: "#{quote.name} (#{quote.symbol})",
text: "$#{quote.last_trade_price} (#{quote.change_in_percent})",
color: quote.change.to_f > 0 ? '#00FF00' : '#FF0000'
}
]
)
stocks.each do |stock|
begin
quote = IEX::Resources::Quote.get(stock.first)

client.web_client.chat_postMessage(
channel: data.channel,
as_user: true,
attachments: [
{
fallback: "#{quote.company_name} (#{quote.symbol}): $#{quote.latest_price}",
title: "#{quote.company_name} (#{quote.symbol})",
text: "$#{quote.latest_price} (#{quote.change_percent})",
color: quote.change.to_f > 0 ? '#00FF00' : '#FF0000'
}
]
)
rescue IEX::Errors::SymbolNotFoundError
logger.warn "no stock found for symbol #{stock}"
end
end
end
end
Expand Down

0 comments on commit 25f9384

Please sign in to comment.