5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/ish/yahoo_stockwatcher.rb', line 5
def watch_once
stocks = Ish::StockWatch.where( :notification_type => :EMAIL )
stocks.each do |stock|
r = HTTParty.get "https://query1.finance.yahoo.com/v7/finance/chart/#{stock.ticker}?interval=1d&indicators=quote", timeout: 10
r = JSON.parse( r.body ).deep_symbolize_keys
r = r[:chart][:result][0][:meta][:regularMarketPrice]
if stock.direction == :ABOVE && r >= stock.price ||
stock.direction == :BELOW && r <= stock.price
IshManager::ApplicationMailer.stock_alert( stock ).deliver
end
end
end
|