Class: YahooStockwatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ish/yahoo_stockwatcher.rb

Instance Method Summary collapse

Instance Method Details

#watch_onceObject



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 )
  # puts! stocks.map(&:ticker), "Watching these stocks"
  stocks.each do |stock|
    # puts! stock.ticker, 'ticker'
    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

      ## actions
      ## exit the position
      # stock.stock_actions.where( :is_active => true ).each do |action|
      #   # @TODO: actions
      # end
      
    end
  end
    
end