Sha256: 117282c31a11528d67ae3b504d48ff8a024b6377d3406b2ace0b7501012598c2

Contents?: true

Size: 963 Bytes

Versions: 46

Compression:

Stored size: 963 Bytes

Contents

class ::YahooStockwatcher

  # For: https://query1.finance.yahoo.com/v7/finance/chart/qqq?interval=1d&indicators=quote
  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

end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
ish_models-0.0.33.153 lib/warbler/yahoo_stockwatcher.rb
ish_models-0.0.33.152 lib/warbler/yahoo_stockwatcher.rb
ish_models-0.0.33.151 lib/warbler/yahoo_stockwatcher.rb
ish_models-0.0.33.150 lib/warbler/yahoo_stockwatcher.rb
ish_models-0.0.33.149 lib/warbler/yahoo_stockwatcher.rb
ish_models-0.0.33.148 lib/warbler/yahoo_stockwatcher.rb
ish_models-0.0.33.147 lib/warbler/yahoo_stockwatcher.rb
ish_models-0.0.33.146 lib/warbler/yahoo_stockwatcher.rb
ish_models-0.0.33.145 lib/warbler/yahoo_stockwatcher.rb
ish_models-0.0.33.144 lib/warbler/yahoo_stockwatcher.rb
ish_models-0.0.33.143 lib/warbler/yahoo_stockwatcher.rb
ish_models-0.0.33.142 lib/warbler/yahoo_stockwatcher.rb
ish_models-0.0.33.141 lib/warbler/yahoo_stockwatcher.rb
ish_models-0.0.33.140 lib/ish/yahoo_stockwatcher.rb
ish_models-0.0.33.139 lib/ish/yahoo_stockwatcher.rb
ish_models-0.0.33.138 lib/ish/yahoo_stockwatcher.rb
ish_models-0.0.33.137 lib/ish/yahoo_stockwatcher.rb
ish_models-0.0.33.136 lib/ish/yahoo_stockwatcher.rb
ish_models-0.0.33.135 lib/ish/yahoo_stockwatcher.rb
ish_models-0.0.33.134 lib/ish/yahoo_stockwatcher.rb