Sha256: 82615534bae47cce0f6dc4c3fdd9ccf5311e8c05d6e69db9931778e82b8550aa

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

namespace :iro do

  desc 'watch stocks'
  task watch_stocks: :environment do
    while true

      begin
        Timeout::timeout( 10 ) do
          TDA::Api.get_quotes Iro::Stock.active.map(&:ticker).join(",")
        end
      rescue Exception => e
        puts! e, 'Error in iro:watch_stocks'
        # Wco::Exceptionist.notify(e, 'Error in iro:watch_stocks')
      end

      sleep Iro::Stock::SLEEP_TIME_SECONDS
    end
  end

  desc 'alerts'
  task alerts: :environment do
    print 'iro:alerts'
    while true
      Iro::Alert.active.each do |alert|

        # price = Iro::Stock.latest( alert.ticker ).price
        price = Tda::Api.get_quote( alert.symbol ).last

        if  alert.direction == Iro::Alert::DIRECTION_ABOVE && price >= alert.strike ||
            alert.direction == Iro::Alert::DIRECTION_BELOW && price <= alert.strike

          Iro::AlertMailer.stock_alert( alert ).deliver_later
          alert.update({ status: Iro::Alert::STATUS_INACTIVE })
          print '^'

        end
      end

      print '.'
      sleep Iro::Alert::SLEEP_TIME_SECONDS
    end
  end

end


Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
iron_warbler-2.0.7.8 lib/tasks/iro_tasks.rake
iron_warbler-2.0.7.7 lib/tasks/iro_tasks.rake